From 0cdc5d966f5c97b203ac19fbf1d424cdbc4f967f Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B6=80=EC=A0=95=EA=B7=A0/Common=20Platform=20Lab=28SR=29?= =?utf8?q?/Staff=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Fri, 27 Dec 2019 17:04:14 +0900 Subject: [PATCH] Add Optional feature in InitializeOption (#120) * Add Optional feature in InitializeOption - add Optional feature of Shell/Style/Visual in InitializeOption class. - add more static constructor type - add OptionalFeatureValues class in TizenSpeciffic * Fix CustomRenderer not applied issue --- Xamarin.Forms.Core/BindableObject.cs | 16 +- .../Internals/PropertyPropagationExtensions.cs | 23 ++- Xamarin.Forms.Core/Page.cs | 8 +- .../TizenSpecific/OptionalFeatureValues.cs | 16 ++ Xamarin.Forms.Core/Shell/NavigableElement.cs | 17 ++- Xamarin.Forms.Platform.Tizen/Forms.cs | 163 +++++++++++++-------- 6 files changed, 163 insertions(+), 80 deletions(-) create mode 100644 Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/OptionalFeatureValues.cs diff --git a/Xamarin.Forms.Core/BindableObject.cs b/Xamarin.Forms.Core/BindableObject.cs index 50c28f3..13b3cf9 100644 --- a/Xamarin.Forms.Core/BindableObject.cs +++ b/Xamarin.Forms.Core/BindableObject.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using Xamarin.Forms.Internals; +using Xamarin.Forms.PlatformConfiguration.TizenSpecific; namespace Xamarin.Forms { @@ -215,14 +216,17 @@ namespace Xamarin.Forms protected virtual void OnBindingContextChanged() { BindingContextChanged?.Invoke(this, EventArgs.Empty); - if (Shell.GetBackButtonBehavior(this) is BackButtonBehavior buttonBehavior) - SetInheritedBindingContext(buttonBehavior, BindingContext); + if (OptionalFeatureValues.UseShell) + { + if (Shell.GetBackButtonBehavior(this) is BackButtonBehavior buttonBehavior) + SetInheritedBindingContext(buttonBehavior, BindingContext); - if (Shell.GetSearchHandler(this) is SearchHandler searchHandler) - SetInheritedBindingContext(searchHandler, BindingContext); + if (Shell.GetSearchHandler(this) is SearchHandler searchHandler) + SetInheritedBindingContext(searchHandler, BindingContext); - if (Shell.GetTitleView(this) is View titleView) - SetInheritedBindingContext(titleView, BindingContext); + if (Shell.GetTitleView(this) is View titleView) + SetInheritedBindingContext(titleView, BindingContext); + } } protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) diff --git a/Xamarin.Forms.Core/Internals/PropertyPropagationExtensions.cs b/Xamarin.Forms.Core/Internals/PropertyPropagationExtensions.cs index 5a7abec..e2c16ba 100644 --- a/Xamarin.Forms.Core/Internals/PropertyPropagationExtensions.cs +++ b/Xamarin.Forms.Core/Internals/PropertyPropagationExtensions.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Text; +using Xamarin.Forms.PlatformConfiguration.TizenSpecific; namespace Xamarin.Forms.Internals { @@ -12,17 +13,23 @@ namespace Xamarin.Forms.Internals if (propertyName == null || propertyName == VisualElement.FlowDirectionProperty.PropertyName) Element.SetFlowDirectionFromParent(element); - if (propertyName == null || propertyName == VisualElement.VisualProperty.PropertyName) - Element.SetVisualfromParent(element); + if (OptionalFeatureValues.UseVisual) + { + if (propertyName == null || propertyName == VisualElement.VisualProperty.PropertyName) + Element.SetVisualfromParent(element); + } - if (propertyName == null || propertyName == Shell.NavBarIsVisibleProperty.PropertyName) - BaseShellItem.PropagateFromParent(Shell.NavBarIsVisibleProperty, element); + if (OptionalFeatureValues.UseShell) + { + if (propertyName == null || propertyName == Shell.NavBarIsVisibleProperty.PropertyName) + BaseShellItem.PropagateFromParent(Shell.NavBarIsVisibleProperty, element); - if (propertyName == null || propertyName == Shell.NavBarHasShadowProperty.PropertyName) - BaseShellItem.PropagateFromParent(Shell.NavBarHasShadowProperty, element); + if (propertyName == null || propertyName == Shell.NavBarHasShadowProperty.PropertyName) + BaseShellItem.PropagateFromParent(Shell.NavBarHasShadowProperty, element); - if (propertyName == null || propertyName == Shell.TabBarIsVisibleProperty.PropertyName) - BaseShellItem.PropagateFromParent(Shell.TabBarIsVisibleProperty, element); + if (propertyName == null || propertyName == Shell.TabBarIsVisibleProperty.PropertyName) + BaseShellItem.PropagateFromParent(Shell.TabBarIsVisibleProperty, element); + } foreach (var child in children) { diff --git a/Xamarin.Forms.Core/Page.cs b/Xamarin.Forms.Core/Page.cs index 22cfee0..2a4bff6 100644 --- a/Xamarin.Forms.Core/Page.cs +++ b/Xamarin.Forms.Core/Page.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Threading.Tasks; using Xamarin.Forms.Internals; using Xamarin.Forms.Platform; +using Xamarin.Forms.PlatformConfiguration.TizenSpecific; namespace Xamarin.Forms { @@ -157,7 +158,12 @@ namespace Xamarin.Forms { get { - var titleviewPart1TheShell = Shell.GetTitleView(this); + View titleviewPart1TheShell = null; + if (OptionalFeatureValues.UseShell) + { + titleviewPart1TheShell = Shell.GetTitleView(this); + } + var titleViewPart2TheNavBar = NavigationPage.GetTitleView(this); if (titleviewPart1TheShell != null) diff --git a/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/OptionalFeatureValues.cs b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/OptionalFeatureValues.cs new file mode 100644 index 0000000..a7e0e97 --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/OptionalFeatureValues.cs @@ -0,0 +1,16 @@ +namespace Xamarin.Forms.PlatformConfiguration.TizenSpecific +{ + public static class OptionalFeatureValues + { + public static bool UseStyle { get; set; } + public static bool UseShell { get; set; } + public static bool UseVisual { get; set; } + + static OptionalFeatureValues() + { + UseStyle = true; + UseShell = true; + UseVisual = true; + } + } +} diff --git a/Xamarin.Forms.Core/Shell/NavigableElement.cs b/Xamarin.Forms.Core/Shell/NavigableElement.cs index 0676fa0..cc5fcfc 100644 --- a/Xamarin.Forms.Core/Shell/NavigableElement.cs +++ b/Xamarin.Forms.Core/Shell/NavigableElement.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.ComponentModel; using Xamarin.Forms.Internals; +using Xamarin.Forms.PlatformConfiguration.TizenSpecific; namespace Xamarin.Forms { @@ -20,7 +21,11 @@ namespace Xamarin.Forms internal NavigableElement() { Navigation = new NavigationProxy(); - _mergedStyle = new MergedStyle(GetType(), this); + + if (OptionalFeatureValues.UseStyle) + { + _mergedStyle = new MergedStyle(GetType(), this); + } } public INavigation Navigation { @@ -30,7 +35,10 @@ namespace Xamarin.Forms public Style Style { get { return (Style)GetValue(StyleProperty); } - set { SetValue(StyleProperty, value); } + set { + if (OptionalFeatureValues.UseStyle) + SetValue(StyleProperty, value); + } } [TypeConverter(typeof(ListStringTypeConverter))] @@ -42,7 +50,10 @@ namespace Xamarin.Forms [TypeConverter(typeof(ListStringTypeConverter))] public IList @class { get { return _mergedStyle.StyleClass; } - set { _mergedStyle.StyleClass = value; } + set { + if (OptionalFeatureValues.UseStyle) + _mergedStyle.StyleClass = value; + } } [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/Xamarin.Forms.Platform.Tizen/Forms.cs b/Xamarin.Forms.Platform.Tizen/Forms.cs index 0bf69e2..2ad180c 100644 --- a/Xamarin.Forms.Platform.Tizen/Forms.cs +++ b/Xamarin.Forms.Platform.Tizen/Forms.cs @@ -11,6 +11,7 @@ using Tizen.Applications; using TSystemInfo = Tizen.System.Information; using ELayout = ElmSharp.Layout; using DeviceOrientation = Xamarin.Forms.Internals.DeviceOrientation; +using Xamarin.Forms.PlatformConfiguration.TizenSpecific; namespace Xamarin.Forms { @@ -29,6 +30,7 @@ namespace Xamarin.Forms public class InitializationOptions { + public ApplicationLifecycle LifeCycle { get; set; } public CoreApplication Context { get; set; } public bool UseDeviceIndependentPixel { get; set; } public HandlerAttribute[] Handlers { get; set; } @@ -39,6 +41,10 @@ namespace Xamarin.Forms public StaticRegistrarStrategy StaticRegistarStrategy { get; set; } public PlatformType PlatformType { get; set; } public bool UseMessagingCenter { get; set; } = true; + public bool UseStyle { get; set; } = true; + public bool UseShell { get; set; } = true; + public bool UseVisual { get; set; } = true; + public struct EffectScope { @@ -65,6 +71,25 @@ namespace Xamarin.Forms Assemblies = assemblies; } + public InitializationOptions(ApplicationLifecycle lifecycle) + { + LifeCycle = lifecycle; + } + + public InitializationOptions(ApplicationLifecycle lifecycle, bool useDeviceIndependentPixel, HandlerAttribute[] handlers) + { + LifeCycle = lifecycle; + UseDeviceIndependentPixel = useDeviceIndependentPixel; + Handlers = handlers; + } + + public InitializationOptions(ApplicationLifecycle lifecycle, bool useDeviceIndependentPixel, params Assembly[] assemblies) + { + LifeCycle = lifecycle; + UseDeviceIndependentPixel = useDeviceIndependentPixel; + Assemblies = assemblies; + } + public void UseStaticRegistrar(StaticRegistrarStrategy strategy, Dictionary> customHandlers=null, bool disableCss=false) { StaticRegistarStrategy = strategy; @@ -217,6 +242,12 @@ namespace Xamarin.Forms private set; } + public static bool IsPreloaded + { + get; + private set; + } + public static DeviceOrientation NaturalOrientation { get; } = GetDeviceOrientation(); public static StaticRegistrarStrategy StaticRegistrarStrategy => s_staticRegistrarStrategy; @@ -342,35 +373,12 @@ namespace Xamarin.Forms } } - public static void Init(ApplicationLifecycle lifecycle, bool useDeviceIndependentPixel, Dictionary> customHandlers = null) - { - if (!IsInitialized) - { - Init(); - } - - s_useDeviceIndependentPixel = useDeviceIndependentPixel; - - if (Device.info != null) - { - var info = ((TizenDeviceInfo)Device.info).RefreshByDIP(); - ((TizenDeviceInfo)Device.info).Dispose(); - Device.info = info; - } - - var appAdapter = Context as AdaptedFormsApplication; - appAdapter.Lifecycle = lifecycle; - lifecycle.FormsApplication = appAdapter; - - if (customHandlers != null) - StaticRegistrar.RegisterHandlers(customHandlers); - } - static void Init() { TizenPlatformServices.AppDomain.CurrentDomain.AddAssembly(typeof(View).Assembly); var appAdapter = new AdaptedFormsApplication(); Init(appAdapter, false); + IsPreloaded = true; } public static void Init(CoreApplication application) @@ -386,7 +394,19 @@ namespace Xamarin.Forms public static void Init(InitializationOptions options) { - SetupInit(options.Context, options); + if (!IsInitialized) + { + var appAdapter = new AdaptedFormsApplication(); + Context = appAdapter; + } + + if (options.LifeCycle != null) + { + var appAdapter = Context as AdaptedFormsApplication; + appAdapter.Lifecycle = options.LifeCycle; + options.LifeCycle.FormsApplication = appAdapter; + } + SetupInit(Context, options); } static void SetupInit(CoreApplication application, InitializationOptions options = null) @@ -403,25 +423,34 @@ namespace Xamarin.Forms Elementary.Initialize(); Elementary.ThemeOverlay(); - } - Device.PlatformServices = new TizenPlatformServices(); - if (Device.info != null) + Device.PlatformServices = new TizenPlatformServices(); + if (Device.info != null) + { + ((TizenDeviceInfo)Device.info).Dispose(); + Device.info = null; + } + + Device.Info = new Forms.TizenDeviceInfo(); + Device.SetFlags(s_flags); + } + else if(Device.info != null) { + var info = ((TizenDeviceInfo)Device.info).RefreshByDIP(); ((TizenDeviceInfo)Device.info).Dispose(); - Device.info = null; + Device.info = info; } - Device.Info = new Forms.TizenDeviceInfo(); - Device.SetFlags(s_flags); - - if (!Forms.IsInitialized) + if (!Forms.IsInitialized || Forms.IsPreloaded) { if (options != null) { s_useDeviceIndependentPixel = options.UseDeviceIndependentPixel; s_platformType = options.PlatformType; s_useMessagingCenter = options.UseMessagingCenter; + OptionalFeatureValues.UseStyle = options.UseStyle; + OptionalFeatureValues.UseShell = options.UseShell; + OptionalFeatureValues.UseVisual = options.UseVisual; if (options.Assemblies != null && options.Assemblies.Length > 0) { @@ -436,7 +465,10 @@ namespace Xamarin.Forms else { // Add Xamarin.Forms.Core assembly by default to apply the styles. - TizenPlatformServices.AppDomain.CurrentDomain.AddAssembly(Assembly.GetAssembly(typeof(Xamarin.Forms.View))); + if (!Forms.IsPreloaded) + { + TizenPlatformServices.AppDomain.CurrentDomain.AddAssembly(Assembly.GetAssembly(typeof(Xamarin.Forms.View))); + } // static registrar if (options.StaticRegistarStrategy != StaticRegistrarStrategy.None) @@ -501,30 +533,33 @@ namespace Xamarin.Forms } } - string profile = ((TizenDeviceInfo)Device.Info).Profile; - if (profile == "mobile") - { - Device.SetIdiom(TargetIdiom.Phone); - } - else if (profile == "tv") - { - Device.SetIdiom(TargetIdiom.TV); - } - else if (profile == "desktop") - { - Device.SetIdiom(TargetIdiom.Desktop); - } - else if (profile == "wearable") - { - Device.SetIdiom(TargetIdiom.Watch); - } - else + if (!Forms.IsInitialized) { - Device.SetIdiom(TargetIdiom.Unsupported); + string profile = ((TizenDeviceInfo)Device.Info).Profile; + if (profile == "mobile") + { + Device.SetIdiom(TargetIdiom.Phone); + } + else if (profile == "tv") + { + Device.SetIdiom(TargetIdiom.TV); + } + else if (profile == "desktop") + { + Device.SetIdiom(TargetIdiom.Desktop); + } + else if (profile == "wearable") + { + Device.SetIdiom(TargetIdiom.Watch); + } + else + { + Device.SetIdiom(TargetIdiom.Unsupported); + } + Color.SetAccent(GetAccentColor(profile)); + ExpressionSearch.Default = new TizenExpressionSearch(); + IsInitialized = true; } - Color.SetAccent(GetAccentColor(profile)); - ExpressionSearch.Default = new TizenExpressionSearch(); - IsInitialized = true; } static Color GetAccentColor(string profile) @@ -635,12 +670,7 @@ namespace Xamarin.Forms [EditorBrowsable(EditorBrowsableState.Never)] public static void Preload() { - Elementary.Initialize(); - Elementary.ThemeOverlay(); var window = new PreloadedWindow(); - TSystemInfo.TryGetValue("http://tizen.org/feature/screen.width", out int width); - TSystemInfo.TryGetValue("http://tizen.org/feature/screen.height", out int height); - Forms.Init(); var types = new[] @@ -682,7 +712,16 @@ namespace Xamarin.Forms typeof(TextCell), typeof(ImageCell), typeof(SwitchCell), - typeof(EntryCell) + typeof(EntryCell), + typeof(VisualElement), + typeof(Page), + typeof(View), + typeof(Element), + typeof(NavigableElement), + typeof(Layout), + typeof(Span), + typeof(TapGestureRecognizer), + typeof(PropertyCondition) }; foreach (var type in types) -- 2.7.4