diff --git a/Reloader/Xamarin.Forms.HotReload.Reloader/HotReloader.cs b/Reloader/Xamarin.Forms.HotReload.Reloader/HotReloader.cs index 18dbcd0..14fd78c 100644 --- a/Reloader/Xamarin.Forms.HotReload.Reloader/HotReloader.cs +++ b/Reloader/Xamarin.Forms.HotReload.Reloader/HotReloader.cs @@ -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 _loadXaml; + private Action _loadXaml; private HashSet _cellViewReloadProps = new HashSet { "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" }; @@ -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 () => @@ -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() - .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() + .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) { diff --git a/Reloader/Xamarin.Forms.HotReload.Reloader/ReloaderPublic/ReloaderConfiguration.cs b/Reloader/Xamarin.Forms.HotReload.Reloader/ReloaderPublic/ReloaderConfiguration.cs index bcec237..478f97b 100644 --- a/Reloader/Xamarin.Forms.HotReload.Reloader/ReloaderPublic/ReloaderConfiguration.cs +++ b/Reloader/Xamarin.Forms.HotReload.Reloader/ReloaderPublic/ReloaderConfiguration.cs @@ -19,12 +19,11 @@ public sealed class Configuration /// public IPAddress ExtensionIpAddress { internal get; set; } = IPAddress.Broadcast; - /// - /// [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 - /// [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 @@ -32,5 +31,11 @@ public sealed class ReloaderStartupInfo public int SelectedDevicePort { get; internal set; } public IReadOnlyList IPAddresses { get; internal set; } } + + public enum PreviewerMode + { + Off, + On + } } }