Skip to content

Commit

Permalink
updated previewer
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiMisiukevich committed Jul 16, 2019
1 parent 60c6082 commit d9a0fd0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
22 changes: 18 additions & 4 deletions Reloader/Xamarin.Forms.HotReload.Reloader/HotReloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public sealed partial class HotReloader
private readonly Type _xamlFilePathAttributeType = typeof(XamlFilePathAttribute);
private readonly object _requestLocker = new object();
private Application _app;
private Action<object, string, bool> _loadXaml;
private Action<object, string, bool?> _loadXaml;

private HashSet<string> _cellViewReloadProps = new HashSet<string> { "Orientation", "Spacing", "IsClippedToBounds", "Padding", "HorizontalOptions", "Margin", "VerticalOptions", "Visual", "FlowDirection", "AnchorX", "AnchorY", "BackgroundColor", "HeightRequest", "InputTransparent", "IsEnabled", "IsVisible", "MinimumHeightRequest", "MinimumWidthRequest", "Opacity", "Rotation", "RotationX", "RotationY", "Scale", "ScaleX", "ScaleY", "Style", "TabIndex", "IsTabStop", "StyleClass", "TranslationX", "TranslationY", "WidthRequest", "DisableLayout", "Resources", "AutomationId", "ClassId", "StyleId" };

Expand Down Expand Up @@ -127,7 +127,13 @@ public ReloaderStartupInfo Run(Application app, Configuration config = null)

_loadXaml = (obj, xaml, isPreviewer) =>
{
loadXaml.Invoke(null, new object[] { obj, xaml, isPreviewer });
var isPreview = isPreviewer ?? config.PreviewerDefaultMode == PreviewerMode.On;
if (loadXaml != null && isPreview)
{
loadXaml.Invoke(null, new object[] { obj, xaml, true });
return;
}
obj.LoadFromXaml(xaml);
};

Task.Run(async () =>
Expand Down Expand Up @@ -611,8 +617,16 @@ private ReloadItem GetItemForReloadingSourceRes(Uri source, object belongObj)
return null;
}

private void LoadFromXaml(object obj, XmlDocument xamlDoc) => _loadXaml.Invoke(obj, xamlDoc.InnerXml, xamlDoc.ChildNodes.Cast<XmlNode>()
.Any(x => (x.Name?.Equals("hotReload", StringComparison.InvariantCultureIgnoreCase) ?? false) && (x.Value?.Equals("preview.on", StringComparison.InvariantCultureIgnoreCase) ?? false)));
private void LoadFromXaml(object obj, XmlDocument xamlDoc)
{
var previewElement = xamlDoc.ChildNodes.Cast<XmlNode>()
.FirstOrDefault(x => (x.Name?.Equals("hotReload", StringComparison.InvariantCultureIgnoreCase) ?? false) &&
(x.Value?.Equals("preview.on", StringComparison.InvariantCultureIgnoreCase) ?? false) || (x.Value?.Equals("preview.off", StringComparison.InvariantCultureIgnoreCase) ?? false));

var isPreview = previewElement != null ? previewElement.Value.Equals("preview.on", StringComparison.InvariantCultureIgnoreCase) : default(bool?);
_loadXaml.Invoke(obj, xamlDoc.InnerXml, isPreview);

}

private string GetResId(Uri source, object belongObj)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,23 @@ public sealed class Configuration
/// </summary>
public IPAddress ExtensionIpAddress { internal get; set; } = IPAddress.Broadcast;

/// <summary>
/// [SHOULD BE THE SAME WITH EXTENSION'S ALERT VALUE] Setup EXTENSION's autodiscovery port. Extension shows it in alert after enabling. Default value is 15000
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("NO NEED TO SET THIS PROPERTY ANYMORE. RELOADER DETECTS THIS PORT AUTOMATICALLY")]
public int ExtensionAutoDiscoveryPort { internal get; set; }

public PreviewerMode PreviewerDefaultMode { get; set; }
}

public sealed class ReloaderStartupInfo
{
public int SelectedDevicePort { get; internal set; }
public IReadOnlyList<IPAddress> IPAddresses { get; internal set; }
}

public enum PreviewerMode
{
Off,
On
}
}
}

0 comments on commit d9a0fd0

Please sign in to comment.