summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.UnitTests
diff options
context:
space:
mode:
authorSamantha Houts <samantha@teamredwall.com>2016-08-30 10:46:14 -0700
committerJason Smith <jason.smith@xamarin.com>2016-08-30 10:46:14 -0700
commit5e553f6195e66e48688b8ab324f1bab1e9251f0a (patch)
treef8843e5e9e8afe89a05a1cc91c3b7fa05588bac7 /Xamarin.Forms.Core.UnitTests
parentf551654b1cfe654c579ca50978445e7cb93f287d (diff)
downloadxamarin-forms-5e553f6195e66e48688b8ab324f1bab1e9251f0a.tar.gz
xamarin-forms-5e553f6195e66e48688b8ab324f1bab1e9251f0a.tar.bz2
xamarin-forms-5e553f6195e66e48688b8ab324f1bab1e9251f0a.zip
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
Diffstat (limited to 'Xamarin.Forms.Core.UnitTests')
-rw-r--r--Xamarin.Forms.Core.UnitTests/PlatformSpecificsTests.cs227
-rw-r--r--Xamarin.Forms.Core.UnitTests/Xamarin.Forms.Core.UnitTests.csproj1
2 files changed, 228 insertions, 0 deletions
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<iOS>().GetVendorFoo());
+
+ x.On<iOS>().SetVendorFoo(false);
+
+ Assert.IsFalse(x.On<iOS>().GetVendorFoo());
+ }
+
+ [Test]
+ public void ConsumeVendorSetting()
+ {
+ var x = new MasterDetailPage();
+ x.On<iOS>().SetVendorFoo(false);
+
+ Assert.IsFalse(x.On<iOS>().GetVendorFoo());
+ }
+
+ [Test]
+ public void Properties()
+ {
+ var x = new MasterDetailPage();
+ x.On<Android>().SetSomeAndroidThing(42);
+
+ Assert.IsTrue(x.On<Android>().GetSomeAndroidThing() == 42);
+ }
+
+ [Test]
+ public void ConvenienceConfiguration()
+ {
+ var x = new MasterDetailPage();
+
+ x.On<Android>().UseTabletDefaults();
+
+ Assert.IsTrue(x.On<Android>().GetSomeAndroidThing() == 10);
+ Assert.IsTrue(x.On<Android>().GetSomeOtherAndroidThing() == 45);
+
+ x.On<Android>().UsePhabletDefaults();
+
+ Assert.IsTrue(x.On<Android>().GetSomeAndroidThing() == 8);
+ Assert.IsTrue(x.On<Android>().GetSomeOtherAndroidThing() == 40);
+ }
+
+ [Test]
+ public void NavigationPageiOSConfiguration()
+ {
+ var x = new NavigationPage();
+
+ x.On<iOS>().SetIsNavigationBarTranslucent(true);
+
+ Assert.IsTrue(x.On<iOS>().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<iOS, FormsElement> SetVendorFoo(this IPlatformElementConfiguration<iOS, FormsElement> config, bool value)
+ {
+ SetVendorFoo(config.Element, value);
+ return config;
+ }
+
+ public static bool GetVendorFoo(this IPlatformElementConfiguration<iOS, FormsElement> 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<iOS, FormsElement> config)
+ {
+ return GetIsNavigationBarTranslucent(config.Element);
+ }
+
+ public static IPlatformElementConfiguration<iOS, FormsElement> EnableTranslucentNavigationBarVendor(this IPlatformElementConfiguration<iOS, FormsElement> 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<Android, FormsElement> config)
+ {
+ return (int)config.Element.GetValue(SomeAndroidThingProperty);
+ }
+
+ public static IPlatformElementConfiguration<Android, FormsElement> SetSomeAndroidThing(this IPlatformElementConfiguration<Android, FormsElement> config,
+ int value)
+ {
+ config.Element.SetValue(SomeAndroidThingProperty, value);
+ return config;
+ }
+
+ public static int GetSomeOtherAndroidThing(this IPlatformElementConfiguration<Android, FormsElement> config)
+ {
+ return (int)config.Element.GetValue(SomeOtherAndroidThingProperty);
+ }
+
+ public static IPlatformElementConfiguration<Android, FormsElement> SetSomeOtherAndroidThing(this IPlatformElementConfiguration<Android, FormsElement> config, int value)
+ {
+ config.Element.SetValue(SomeOtherAndroidThingProperty, value);
+ return config;
+ }
+
+ public static IPlatformElementConfiguration<Android, FormsElement> UseTabletDefaults(this IPlatformElementConfiguration<Android, FormsElement> config)
+ {
+ config.SetSomeAndroidThing(10);
+ config.SetSomeOtherAndroidThing(45);
+ return config;
+ }
+
+ public static IPlatformElementConfiguration<Android, FormsElement> UsePhabletDefaults(this IPlatformElementConfiguration<Android, FormsElement> 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 @@
<Compile Include="PageTests.cs" />
<Compile Include="PanGestureRecognizerUnitTests.cs" />
<Compile Include="PinTests.cs" />
+ <Compile Include="PlatformSpecificsTests.cs" />
<Compile Include="PointTests.cs" />
<Compile Include="PositionTests.cs" />
<Compile Include="ProgressBarTests.cs" />