Permalink
Browse files

Attach Effect on PropertyChanging for XAML support!

  • Loading branch information...
1 parent 63a924d commit 1f9482e4b5969f19fcde5c691443fcccc848c54e @samhouts samhouts committed Jul 18, 2016
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<local:TestNavigationPage xmlns="http://xamarin.com/schemas/2014/forms"
+ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+ xmlns:local="clr-namespace:Xamarin.Forms.Controls"
+ xmlns:ios="clr-namespace:ImAVendor.Forms.PlatformConfiguration.iOS;assembly=Xamarin.Forms.Core"
+ x:Class="Xamarin.Forms.Controls.Issues.PlatformSpecifics_iOSTranslucentNavBarX"
+ BackgroundColor="Pink"
+ ios:FakeVendorConfig.IsNavigationBarTranslucent="true">
+</local:TestNavigationPage>
@@ -0,0 +1,45 @@
+using ImAVendor.Forms.PlatformConfiguration.iOS;
+using Xamarin.Forms;
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+using Xamarin.Forms.PlatformConfiguration.iOS;
+using Xamarin.Forms.Xaml;
+
+namespace Xamarin.Forms.Controls.Issues
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Bugzilla, 60001, "Platform Specifics - iOS Translucent Navigation Bar XAML", PlatformAffected.iOS)]
+#if APP
+ [XamlCompilation(XamlCompilationOptions.Compile)]
+#endif
+ public partial class PlatformSpecifics_iOSTranslucentNavBarX : TestNavigationPage
+ {
+ public PlatformSpecifics_iOSTranslucentNavBarX()
+ {
+#if APP
+ InitializeComponent ();
+#endif
+ }
+
+ protected override void Init()
+ {
+ var button = new Button { Text = "Toggle Translucent", BackgroundColor = Color.Yellow };
+
+ button.Clicked += (sender, args) => On<IConfigIOS>()
+ .SetNavigationBarIsTranslucentVendor(!On<IConfigIOS>().GetNavigationBarIsTranslucentVendor());
+
+ var content = new ContentPage
+ {
+ Title = "iOS Translucent Navigation Bar",
+ Content = new StackLayout
+ {
+ VerticalOptions = LayoutOptions.Center,
+ HorizontalOptions = LayoutOptions.Center,
+ Children = { button }
+ }
+ };
+
+ PushAsync(content);
+ }
+ }
+}
@@ -169,6 +169,10 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla39458.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla39853.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PlatformSpecifics_iOSTranslucentNavBar.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)PlatformSpecifics_iOSTranslucentNavBarX.xaml.cs">
+ <DependentUpon>PlatformSpecifics_iOSTranslucentNavBarX.xaml</DependentUpon>
+ <SubType>Code</SubType>
+ </Compile>
<Compile Include="$(MSBuildThisFileDirectory)TestPages\ScreenshotConditionalApp.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla41842.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42277.cs" />
@@ -557,6 +561,12 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
+ <EmbeddedResource Include="$(MSBuildThisFileDirectory)PlatformSpecifics_iOSTranslucentNavBarX.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+ </EmbeddedResource>
+ </ItemGroup>
+ <ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla42069_Page.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
@@ -211,29 +211,43 @@ public static bool GetVendorFoo(this IPlatformElementConfiguration<IConfigIOS, M
}
+ public static bool GetIsNavigationBarTranslucent(BindableObject element)
+ {
+ return (bool)element.GetValue(IsNavigationBarTranslucentProperty);
+ }
+
public static readonly BindableProperty IsNavigationBarTranslucentProperty =
- BindableProperty.Create("IsNavigationBarTranslucent", typeof(bool),
- typeof(FakeVendorConfig), false);
+ BindableProperty.CreateAttached("IsNavigationBarTranslucent", typeof(bool),
+ typeof(FakeVendorConfig), false, propertyChanging: IsNavigationBarTranslucentPropertyChanging);
+
+ public static void SetIsNavigationBarTranslucent(BindableObject element, bool value)
+ {
+ element.SetValue(IsNavigationBarTranslucentProperty, value);
+ }
public static bool GetNavigationBarIsTranslucentVendor(this IPlatformElementConfiguration<IConfigIOS, NavigationPage> config)
{
- AttachEffect(config);
- return (bool)config.Element.GetValue(IsNavigationBarTranslucentProperty);
+ return GetIsNavigationBarTranslucent(config.Element);
}
+
public static IPlatformElementConfiguration<IConfigIOS, NavigationPage> SetNavigationBarIsTranslucentVendor(this IPlatformElementConfiguration<IConfigIOS, NavigationPage> config, bool value)
{
- AttachEffect(config);
- config.Element.SetValue(IsNavigationBarTranslucentProperty, value);
+ SetIsNavigationBarTranslucent(config.Element, value);
return config;
}
- static void AttachEffect(IPlatformElementConfiguration<IConfigIOS, NavigationPage> config)
+ static void IsNavigationBarTranslucentPropertyChanging(BindableObject bindable, object oldValue, object newValue)
+ {
+ AttachEffect(bindable as NavigationPage);
+ }
+
+ static void AttachEffect(NavigationPage element)
{
- IElementController controller = config.Element;
- if (controller.EffectIsAttached(NavBarTranslucentEffectName))
+ IElementController controller = element;
+ if (controller == null || controller.EffectIsAttached(NavBarTranslucentEffectName))
return;
- config.Element.Effects.Add(Effect.Resolve(NavBarTranslucentEffectName));
+ element.Effects.Add(Effect.Resolve(NavBarTranslucentEffectName));
}
}
}

0 comments on commit 1f9482e

Please sign in to comment.