From 5e553f6195e66e48688b8ab324f1bab1e9251f0a Mon Sep 17 00:00:00 2001 From: Samantha Houts Date: Tue, 30 Aug 2016 10:46:14 -0700 Subject: Platform Specifics (#301) * Playing around with how the platform specifics interfaces etc. might work * Sample implementation of iOS navigation translucency * Very slightly reduced code * Better vendor stuff * Drop single-implemenation interfaces * Generics on NavigationPage * On-demand vendor stuff * Remove functionally duplicate classes and make ControlGallery work again * Namespace all the things. XAML test. * Can use Effect to attach platform specific * Attach Effect on PropertyChanging for XAML support! * Rename IConfigPlatform interfaces for readability * Some renaming to match the documents * Split class files * Clear out test-only code * Re-namespace * Added On method to rendered Elements * Allow for removal of platform suffix, convenience methods on specific platforms * Creating a gallery page for specifics * Add rudimentary Platform Specifics gallery; make CollapseStyle work on UWP; Add CollapsedPaneWidth specific property * Toolbar now working with both collapse styles * MDP now displaying Content title; toolbar routing around title * Add a gallery for the iOS NavigationPage stuff * Add Navigation Page as detail page to verify it works with new Toolbar options * Make titlebar/toolbar background colors consistent * ToolbarPlacement now working on NavigationPage * Toolbar Placement working for tabbed and nav pages * Fix bug where phone doesn't get default toolbar placement on start * [Core] Add PS WindowSoftInputModeAdjust [Core] Make Application extendable * Toolbar placement now working on Nav, Tabbed, and Master pages on desktop/phone Remove unnecessary style indirection Fix build errors * [A] Add PlatformConfigurationExtensions * SetSoftInputMode test page * [A] SetSoftInputMode Known issue: Status bar color does not work in AdjustResize mode * [Core] Add PS Blur * [iOS] Configure renderer for blur * Add test page * Move to blur VisualElement for broader support * Move test pages to gallery * Update docs * Use lazy initializer for PlatformConfigurationRegistry --- .../PlatformSpecificsTests.cs | 227 +++++++++++++++++++++ .../Xamarin.Forms.Core.UnitTests.csproj | 1 + 2 files changed, 228 insertions(+) create mode 100644 Xamarin.Forms.Core.UnitTests/PlatformSpecificsTests.cs (limited to 'Xamarin.Forms.Core.UnitTests') diff --git a/Xamarin.Forms.Core.UnitTests/PlatformSpecificsTests.cs b/Xamarin.Forms.Core.UnitTests/PlatformSpecificsTests.cs new file mode 100644 index 00000000..44a2a3b0 --- /dev/null +++ b/Xamarin.Forms.Core.UnitTests/PlatformSpecificsTests.cs @@ -0,0 +1,227 @@ +using NUnit.Framework; +using ImAVendor.Forms.PlatformConfiguration.iOS; +using Xamarin.Forms.PlatformConfiguration; +using Xamarin.Forms.PlatformConfiguration.AndroidSpecific; +using Xamarin.Forms.PlatformConfiguration.iOSSpecific; + +namespace Xamarin.Forms.Core.UnitTests +{ + [TestFixture] + public class PlatformSpecificsTests + { + [Test] + public void VendorPlatformProperty() + { + var x = new MasterDetailPage(); + + Assert.IsTrue(x.On().GetVendorFoo()); + + x.On().SetVendorFoo(false); + + Assert.IsFalse(x.On().GetVendorFoo()); + } + + [Test] + public void ConsumeVendorSetting() + { + var x = new MasterDetailPage(); + x.On().SetVendorFoo(false); + + Assert.IsFalse(x.On().GetVendorFoo()); + } + + [Test] + public void Properties() + { + var x = new MasterDetailPage(); + x.On().SetSomeAndroidThing(42); + + Assert.IsTrue(x.On().GetSomeAndroidThing() == 42); + } + + [Test] + public void ConvenienceConfiguration() + { + var x = new MasterDetailPage(); + + x.On().UseTabletDefaults(); + + Assert.IsTrue(x.On().GetSomeAndroidThing() == 10); + Assert.IsTrue(x.On().GetSomeOtherAndroidThing() == 45); + + x.On().UsePhabletDefaults(); + + Assert.IsTrue(x.On().GetSomeAndroidThing() == 8); + Assert.IsTrue(x.On().GetSomeOtherAndroidThing() == 40); + } + + [Test] + public void NavigationPageiOSConfiguration() + { + var x = new NavigationPage(); + + x.On().SetIsNavigationBarTranslucent(true); + + Assert.IsTrue(x.On().IsNavigationBarTranslucent()); + } + } +} + +namespace ImAVendor.Forms.PlatformConfiguration.iOS +{ + using Xamarin.Forms; + using Xamarin.Forms.PlatformConfiguration; + using FormsElement = Xamarin.Forms.MasterDetailPage; + + public static class MasterDetailPage + { + public static readonly BindableProperty FooProperty = + BindableProperty.Create("VendorFoo", typeof(bool), + typeof(MasterDetailPage), true); + + public static void SetVendorFoo(BindableObject element, bool value) + { + element.SetValue(FooProperty, value); + } + + public static bool GetVendorFoo(BindableObject element) + { + return (bool)element.GetValue(FooProperty); + } + + public static IPlatformElementConfiguration SetVendorFoo(this IPlatformElementConfiguration config, bool value) + { + SetVendorFoo(config.Element, value); + return config; + } + + public static bool GetVendorFoo(this IPlatformElementConfiguration mdp) + { + return GetVendorFoo(mdp.Element); + } + } +} + +namespace ImAVendor.Forms.PlatformConfiguration.iOS +{ + using Xamarin.Forms; + using Xamarin.Forms.PlatformConfiguration; + using FormsElement = Xamarin.Forms.NavigationPage; + + public static class NavigationPage + { + const string NavBarTranslucentEffectName = "XamControl.NavigationPageTranslucentEffect"; + + public static readonly BindableProperty IsNavigationBarTranslucentProperty = + BindableProperty.CreateAttached("IsNavigationBarTranslucent", typeof(bool), + typeof(NavigationPage), false, propertyChanging: IsNavigationBarTranslucentPropertyChanging); + + public static bool GetIsNavigationBarTranslucent(BindableObject element) + { + return (bool)element.GetValue(IsNavigationBarTranslucentProperty); + } + + public static void SetIsNavigationBarTranslucent(BindableObject element, bool value) + { + element.SetValue(IsNavigationBarTranslucentProperty, value); + } + + public static bool IsNavigationBarTranslucentVendor(this IPlatformElementConfiguration config) + { + return GetIsNavigationBarTranslucent(config.Element); + } + + public static IPlatformElementConfiguration EnableTranslucentNavigationBarVendor(this IPlatformElementConfiguration config, bool value) + { + SetIsNavigationBarTranslucent(config.Element, value); + return config; + } + + static void IsNavigationBarTranslucentPropertyChanging(BindableObject bindable, object oldValue, object newValue) + { + AttachEffect(bindable as FormsElement); + } + + static void AttachEffect(FormsElement element) + { + IElementController controller = element; + if (controller == null || controller.EffectIsAttached(NavBarTranslucentEffectName)) + return; + + element.Effects.Add(Effect.Resolve(NavBarTranslucentEffectName)); + } + } +} + +namespace Xamarin.Forms.PlatformConfiguration.AndroidSpecific +{ + using FormsElement = Xamarin.Forms.MasterDetailPage; + + public static class MasterDetailPage + { + public static readonly BindableProperty SomeAndroidThingProperty = + BindableProperty.Create("SomeAndroidThing", typeof(int), + typeof(MasterDetailPage), 1); + + public static readonly BindableProperty SomeOtherAndroidThingProperty = + BindableProperty.Create("SomeOtherAndroidThing", typeof(int), + typeof(MasterDetailPage), 1); + + public static int GetSomeAndroidThing(BindableObject element) + { + return (int)element.GetValue(SomeAndroidThingProperty); + } + + public static void SetSomeAndroidThing(BindableObject element, int value) + { + element.SetValue(SomeAndroidThingProperty, value); + } + + public static int GetSomeOtherAndroidThing(BindableObject element) + { + return (int)element.GetValue(SomeOtherAndroidThingProperty); + } + + public static void SetSomeOtherAndroidThing(BindableObject element, int value) + { + element.SetValue(SomeOtherAndroidThingProperty, value); + } + + public static int GetSomeAndroidThing(this IPlatformElementConfiguration config) + { + return (int)config.Element.GetValue(SomeAndroidThingProperty); + } + + public static IPlatformElementConfiguration SetSomeAndroidThing(this IPlatformElementConfiguration config, + int value) + { + config.Element.SetValue(SomeAndroidThingProperty, value); + return config; + } + + public static int GetSomeOtherAndroidThing(this IPlatformElementConfiguration config) + { + return (int)config.Element.GetValue(SomeOtherAndroidThingProperty); + } + + public static IPlatformElementConfiguration SetSomeOtherAndroidThing(this IPlatformElementConfiguration config, int value) + { + config.Element.SetValue(SomeOtherAndroidThingProperty, value); + return config; + } + + public static IPlatformElementConfiguration UseTabletDefaults(this IPlatformElementConfiguration config) + { + config.SetSomeAndroidThing(10); + config.SetSomeOtherAndroidThing(45); + return config; + } + + public static IPlatformElementConfiguration UsePhabletDefaults(this IPlatformElementConfiguration config) + { + config.SetSomeAndroidThing(8); + config.SetSomeOtherAndroidThing(40); + return config; + } + } +} diff --git a/Xamarin.Forms.Core.UnitTests/Xamarin.Forms.Core.UnitTests.csproj b/Xamarin.Forms.Core.UnitTests/Xamarin.Forms.Core.UnitTests.csproj index 4eae5d53..74544605 100644 --- a/Xamarin.Forms.Core.UnitTests/Xamarin.Forms.Core.UnitTests.csproj +++ b/Xamarin.Forms.Core.UnitTests/Xamarin.Forms.Core.UnitTests.csproj @@ -122,6 +122,7 @@ + -- cgit v1.2.3