From 86e3e92b1cb3efafb7ae53d479f587c1cf543363 Mon Sep 17 00:00:00 2001 From: Mahmoud Ali Date: Sun, 5 Jan 2020 09:46:29 -0400 Subject: [PATCH] Add PlatformConfiguration guard --- .../MasterDetailPageiOS.cs | 9 ++++- .../iOSSpecific/MasterDetailPage.cs | 33 +++++++++++++++++++ .../Renderers/PhoneMasterDetailRenderer.cs | 18 ++++++++-- 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/MasterDetailPage.cs diff --git a/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/MasterDetailPageiOS.cs b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/MasterDetailPageiOS.cs index 9e6b140d0de..015367ed1bf 100644 --- a/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/MasterDetailPageiOS.cs +++ b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/MasterDetailPageiOS.cs @@ -18,7 +18,13 @@ public MasterDetailPageiOS(ICommand restore) Title = "This is the detail page's Title", Padding = new Thickness(0,20,0,0) }; - + + void ToggleApplyShadow() + { + On().SetApplyShadow(!On().GetApplyShadow()); + IsPresented = false; + } + var navItems = new List { new NavItem("Display Alert", "\uE171", new Command(() => DisplayAlert("Alert", "This is an alert", "OK"))), @@ -27,6 +33,7 @@ public MasterDetailPageiOS(ICommand restore) new NavItem("Audio", "\uE189", new Command(() => DisplayAlert("Audio", "Never gonna give you up...", "OK"))), new NavItem("Set Detail to Navigation Page", "\uE16F", new Command(() => Detail = CreateNavigationPage())), new NavItem("Set Detail to Content Page", "\uE160", new Command(() => Detail = detail)), + new NavItem("Toggle Apply Shadow", "\u2728", new Command(ToggleApplyShadow)) }; var navList = new NavList(navItems); diff --git a/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/MasterDetailPage.cs b/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/MasterDetailPage.cs new file mode 100644 index 00000000000..55718e5c1eb --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/MasterDetailPage.cs @@ -0,0 +1,33 @@ + +namespace Xamarin.Forms.PlatformConfiguration.iOSSpecific +{ + using FormsElement = Forms.MasterDetailPage; + + public static class MasterDetailPage + { + #region ApplyShadow + public static readonly BindableProperty ApplyShadowProperty = BindableProperty.Create("ApplyShadow", typeof(bool), typeof(MasterDetailPage), false); + + public static bool GetApplyShadow(BindableObject element) + { + return (bool)element.GetValue(ApplyShadowProperty); + } + + public static void SetApplyShadow(BindableObject element, bool value) + { + element.SetValue(ApplyShadowProperty, value); + } + + public static IPlatformElementConfiguration SetApplyShadow(this IPlatformElementConfiguration config, bool value) + { + SetApplyShadow(config.Element, value); + return config; + } + + public static bool GetApplyShadow(this IPlatformElementConfiguration config) + { + return GetApplyShadow(config.Element); + } + #endregion + } +} diff --git a/Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs index 72b636303fe..6539a710995 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs @@ -24,6 +24,7 @@ public class PhoneMasterDetailRenderer : UIViewController, IVisualElementRendere UIGestureRecognizer _tapGesture; VisualElementTracker _tracker; + bool _applyShadow; Page Page => Element as Page; @@ -235,6 +236,8 @@ void HandlePropertyChanged(object sender, PropertyChangedEventArgs e) UpdateBackground(); else if (e.PropertyName == Page.BackgroundImageSourceProperty.PropertyName) UpdateBackground(); + else if (e.PropertyName == PlatformConfiguration.iOSSpecific.MasterDetailPage.ApplyShadowProperty.PropertyName) + UpdateApplyShadow(((MasterDetailPage)Element).OnThisPlatform().GetApplyShadow()); } void LayoutChildren(bool animated) @@ -257,7 +260,8 @@ void LayoutChildren(bool animated) if (Presented) { target.X += masterFrame.Width; - opacity = 0.5f; + if (_applyShadow) + opacity = 0.5f; } if (isRTL) @@ -367,6 +371,11 @@ void UpdateLeftBarButton() NavigationRenderer.SetMasterLeftBarButton(firstPage, masterDetailPage); } + void UpdateApplyShadow(bool value) + { + _applyShadow = value; + } + public override UIViewController ChildViewControllerForStatusBarHidden() { if (((MasterDetailPage)Element).Detail != null) @@ -429,8 +438,11 @@ void UpdatePanGesture() targetFrame.X = (nfloat)Math.Min(_masterController.View.Frame.Width, Math.Max(0, motion)); targetFrame.X = targetFrame.X * directionModifier; - var openProgress = targetFrame.X / _masterController.View.Frame.Width; - ApplyDetailShadow((nfloat)openProgress); + if (_applyShadow) + { + var openProgress = targetFrame.X / _masterController.View.Frame.Width; + ApplyDetailShadow((nfloat)openProgress); + } detailView.Frame = targetFrame; break;