Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Add PlatformConfiguration guard
Browse files Browse the repository at this point in the history
  • Loading branch information
akamud committed Jan 5, 2020
1 parent 24744ad commit 86e3e92
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<iOS>().SetApplyShadow(!On<iOS>().GetApplyShadow());
IsPresented = false;
}

var navItems = new List<NavItem>
{
new NavItem("Display Alert", "\uE171", new Command(() => DisplayAlert("Alert", "This is an alert", "OK"))),
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<iOS, FormsElement> SetApplyShadow(this IPlatformElementConfiguration<iOS, FormsElement> config, bool value)
{
SetApplyShadow(config.Element, value);
return config;
}

public static bool GetApplyShadow(this IPlatformElementConfiguration<iOS, FormsElement> config)
{
return GetApplyShadow(config.Element);
}
#endregion
}
}
18 changes: 15 additions & 3 deletions Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class PhoneMasterDetailRenderer : UIViewController, IVisualElementRendere
UIGestureRecognizer _tapGesture;

VisualElementTracker _tracker;
bool _applyShadow;

Page Page => Element as Page;

Expand Down Expand Up @@ -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)
Expand All @@ -257,7 +260,8 @@ void LayoutChildren(bool animated)
if (Presented)
{
target.X += masterFrame.Width;
opacity = 0.5f;
if (_applyShadow)
opacity = 0.5f;
}

if (isRTL)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 86e3e92

Please sign in to comment.