maui-linux/Xamarin.Forms.Core.UnitTests/PlatformSpecificsTests.cs

228 строки
6.6 KiB
C#
Исходник Обычный вид История

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
2016-08-30 20:46:14 +03:00
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;
}
}
}