[iOS] remove SetPaddingInsets api and just have it pad content and flyout by default...
authorShane Neuville <shane94@hotmail.com>
Sat, 27 Apr 2019 03:29:42 +0000 (21:29 -0600)
committerGitHub <noreply@github.com>
Sat, 27 Apr 2019 03:29:42 +0000 (21:29 -0600)
* remove content setting api and just set by default

* - address comments and centralize window insets check

* add check if height < 0

Xamarin.Forms.Controls/ShellContentTest.xaml
Xamarin.Forms.Controls/XamStore/StoreShell.xaml
Xamarin.Forms.Core/Shell/Shell.cs
Xamarin.Forms.Platform.iOS/Platform.cs
Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs
Xamarin.Forms.Platform.iOS/Renderers/ShellTableViewController.cs

index 8fd4ecc..98ec546 100644 (file)
@@ -3,7 +3,6 @@
              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                         Title="Welcome"
                         Routing.Route="shellcontent"
-                        Shell.SetPaddingInsets="true"
                         Shell.TabBarIsVisible="false"
              x:Class="Xamarin.Forms.Controls.ShellContentTest">
        <Page.ToolbarItems>
index cf119bf..41f7e04 100644 (file)
@@ -58,7 +58,7 @@
 
        <ShellItem Route="store" x:Name="_storeItem" FlyoutDisplayOptions="AsMultipleItems">
                <ShellContent Route="home" Style="{StaticResource GreenShell}" Title="Home" Icon="home.png" FlyoutIcon="homeflyout.png" ContentTemplate="{DataTemplate local:HomePage}" />
-        <ShellContent Route="list" Title="List"  Icon="games.png" FlyoutIcon="gamesflyout.png" ContentTemplate="{DataTemplate local:DemoShellPage}" Shell.SetPaddingInsets="true" />
+        <ShellContent Route="list" Title="List"  Icon="games.png" FlyoutIcon="gamesflyout.png" ContentTemplate="{DataTemplate local:DemoShellPage}" />
                <ShellContent Route="games" Style="{StaticResource GreenShell}" Title="Games" Icon="games.png" FlyoutIcon="gamesflyout.png" ContentTemplate="{DataTemplate local:GamesPage}" />
                <ShellContent Route="movies" Style="{StaticResource MoviesShell}" Title="Movies &amp; TV" 
                                          Icon="film.png" FlyoutIcon="filmflyout.png" ContentTemplate="{DataTemplate local:MoviesPage}">
index 0945642..5532102 100644 (file)
@@ -47,9 +47,6 @@ namespace Xamarin.Forms
                                SetInheritedBindingContext(newHandler, bindable.BindingContext);
                }
 
-               public static readonly BindableProperty SetPaddingInsetsProperty =
-                       BindableProperty.CreateAttached("SetPaddingInsets", typeof(bool), typeof(Shell), false);
-
                public static readonly BindableProperty TabBarIsVisibleProperty =
                        BindableProperty.CreateAttached("TabBarIsVisible", typeof(bool), typeof(Shell), true);
 
@@ -68,9 +65,6 @@ namespace Xamarin.Forms
                public static SearchHandler GetSearchHandler(BindableObject obj) => (SearchHandler)obj.GetValue(SearchHandlerProperty);
                public static void SetSearchHandler(BindableObject obj, SearchHandler handler) => obj.SetValue(SearchHandlerProperty, handler);
 
-               public static bool GetSetPaddingInsets(BindableObject obj) => (bool)obj.GetValue(SetPaddingInsetsProperty);
-               public static void SetSetPaddingInsets(BindableObject obj, bool value) => obj.SetValue(SetPaddingInsetsProperty, value);
-
                public static bool GetTabBarIsVisible(BindableObject obj) => (bool)obj.GetValue(TabBarIsVisibleProperty);
                public static void SetTabBarIsVisible(BindableObject obj, bool value) => obj.SetValue(TabBarIsVisibleProperty, value);
 
index 9a33b8c..41129f9 100644 (file)
@@ -220,6 +220,25 @@ namespace Xamarin.Forms.Platform.iOS
                        base.OnBindingContextChanged();
                }
 
+               internal static UIEdgeInsets SafeAreaInsetsForWindow
+               {
+                       get
+                       {
+                               UIEdgeInsets safeAreaInsets;
+
+                               if (!Forms.IsiOS11OrNewer)
+                                       safeAreaInsets = new UIEdgeInsets(UIApplication.SharedApplication.StatusBarFrame.Size.Height, 0, 0, 0);
+                               else if (UIApplication.SharedApplication.KeyWindow != null)
+                                       safeAreaInsets = UIApplication.SharedApplication.KeyWindow.SafeAreaInsets;
+                               else if (UIApplication.SharedApplication.Windows.Length > 0)
+                                       safeAreaInsets = UIApplication.SharedApplication.Windows[0].SafeAreaInsets;
+                               else
+                                       safeAreaInsets = UIEdgeInsets.Zero;
+
+                               return safeAreaInsets;
+                       }
+               }
+
                internal void DidAppear()
                {
                        _animateModals = false;
index f698d39..abaf0c4 100644 (file)
@@ -301,7 +301,7 @@ namespace Xamarin.Forms.Platform.iOS
                {
                        get
                        {
-                               var animation = ((Page)Element).OnThisPlatform().PreferredStatusBarUpdateAnimation();
+                               var animation = Page.OnThisPlatform().PreferredStatusBarUpdateAnimation();
                                switch (animation)
                                {
                                        case (PageUIStatusBarAnimation.Fade):
@@ -339,32 +339,24 @@ namespace Xamarin.Forms.Platform.iOS
 
                void UpdateShellInsetPadding()
                {
-                       if (Element == null)
+                       if (!(Element?.Parent is ShellContent))
                                return;
 
-                       var setInsets = Shell.GetSetPaddingInsets(Element);
-
-                       if (!setInsets && Element.Parent != null)
-                               setInsets = Shell.GetSetPaddingInsets(Element.Parent);
+                       nfloat topPadding = 0;
+                       nfloat bottomPadding = 0;
 
-                       if (setInsets)
+                       if (Forms.IsiOS11OrNewer)
                        {
-                               nfloat topPadding = 0;
-                               nfloat bottomPadding = 0;
-
-                               if (Forms.IsiOS11OrNewer)
-                               {
-                                       topPadding = View.SafeAreaInsets.Top;
-                                       bottomPadding = View.SafeAreaInsets.Bottom;
-                               }
-                               else
-                               {
-                                       topPadding = TopLayoutGuide.Length;
-                                       bottomPadding = BottomLayoutGuide.Length;
-                               }
-
-                               (Element as Page).Padding = new Thickness(0, topPadding, 0, bottomPadding);
+                               topPadding = View.SafeAreaInsets.Top;
+                               bottomPadding = View.SafeAreaInsets.Bottom;
+                       }
+                       else
+                       {
+                               topPadding = TopLayoutGuide.Length;
+                               bottomPadding = BottomLayoutGuide.Length;
                        }
+
+                       Page.Padding = new Thickness(0, topPadding, 0, bottomPadding);
                }
 
                void UpdateStatusBarPrefersHidden()
@@ -372,7 +364,7 @@ namespace Xamarin.Forms.Platform.iOS
                        if (Element == null)
                                return;
 
-                       var animation = ((Page)Element).OnThisPlatform().PreferredStatusBarUpdateAnimation();
+                       var animation = Page.OnThisPlatform().PreferredStatusBarUpdateAnimation();
                        if (animation == PageUIStatusBarAnimation.Fade || animation == PageUIStatusBarAnimation.Slide)
                                UIView.Animate(0.25, () => SetNeedsStatusBarAppearanceUpdate());
                        else
@@ -392,7 +384,7 @@ namespace Xamarin.Forms.Platform.iOS
 
                public override bool PrefersStatusBarHidden()
                {
-                       var mode = ((Page)Element).OnThisPlatform().PrefersStatusBarHidden();
+                       var mode = Page.OnThisPlatform().PrefersStatusBarHidden();
                        switch (mode)
                        {
                                case (StatusBarHiddenMode.True):
@@ -426,8 +418,8 @@ namespace Xamarin.Forms.Platform.iOS
 
                void UpdateTitle()
                {
-                       if (!string.IsNullOrWhiteSpace(((Page)Element).Title))
-                               NavigationItem.Title = ((Page)Element).Title;
+                       if (!string.IsNullOrWhiteSpace(Page.Title))
+                               NavigationItem.Title = Page.Title;
                }
 
                IEnumerable<UIView> ViewAndSuperviewsOfView(UIView view)
@@ -447,6 +439,6 @@ namespace Xamarin.Forms.Platform.iOS
                        SetNeedsUpdateOfHomeIndicatorAutoHidden();
                }
 
-               public override bool PrefersHomeIndicatorAutoHidden => ((Page)Element).OnThisPlatform().PrefersHomeIndicatorAutoHidden();
+               public override bool PrefersHomeIndicatorAutoHidden => Page.OnThisPlatform().PrefersHomeIndicatorAutoHidden();
        }
 }
\ No newline at end of file
index 080f020..a97c67c 100644 (file)
@@ -1,4 +1,5 @@
-using CoreGraphics;
+using CoreAnimation;
+using CoreGraphics;
 using System;
 using UIKit;
 
@@ -40,10 +41,20 @@ namespace Xamarin.Forms.Platform.iOS
                public void LayoutParallax()
                {
                        var parent = TableView.Superview;
-
-                       TableView.Frame = parent.Bounds;
+                       TableView.Frame = parent.Bounds.Inset(0, SafeAreaOffset);
                        if (_headerView != null)
-                               _headerView.Frame = new CGRect(0, _headerOffset, parent.Frame.Width, _headerSize);
+                       {
+                               _headerView.Frame = new CGRect(0, _headerOffset + SafeAreaOffset, parent.Frame.Width, _headerSize);
+
+                               if (_headerOffset < 0 && _headerSize + _headerOffset >= 0)
+                               {
+                                       CAShapeLayer shapeLayer = new CAShapeLayer();
+                                       CGRect rect = new CGRect(0, _headerOffset * -1, parent.Frame.Width, _headerSize + _headerOffset);
+                                       var path = CGPath.FromRect(rect);
+                                       shapeLayer.Path = path;
+                                       _headerView.Layer.Mask = shapeLayer;
+                               }
+                       }
                }
 
                public override void ViewDidLoad()
@@ -53,18 +64,18 @@ namespace Xamarin.Forms.Platform.iOS
                        TableView.SeparatorStyle = UITableViewCellSeparatorStyle.None;
                        if (Forms.IsiOS11OrNewer)
                                TableView.ContentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior.Never;
-                       TableView.ContentInset = new UIEdgeInsets((nfloat)_headerMax, 0, 0, 0);
+                       TableView.ContentInset = new UIEdgeInsets((nfloat)_headerMax + SafeAreaOffset, 0, 0, 0);
                        TableView.Source = _source;
                }
 
                protected override void Dispose(bool disposing)
                {
-                       if(disposing)
+                       if (disposing)
                        {
                                if ((_context?.Shell as IShellController) != null)
                                        ((IShellController)_context.Shell).StructureChanged -= OnStructureChanged;
                        }
-                       
+
                        base.Dispose(disposing);
                }
 
@@ -81,7 +92,7 @@ namespace Xamarin.Forms.Platform.iOS
 
                                case FlyoutHeaderBehavior.Scroll:
                                        _headerSize = _headerMax;
-                                       _headerOffset = Math.Min (0, -(_headerMax + e.ContentOffset.Y));
+                                       _headerOffset = Math.Min(0, -(_headerMax + e.ContentOffset.Y));
                                        break;
 
                                case FlyoutHeaderBehavior.CollapseOnScroll:
@@ -91,5 +102,7 @@ namespace Xamarin.Forms.Platform.iOS
 
                        LayoutParallax();
                }
+
+               float SafeAreaOffset => (float)Platform.SafeAreaInsetsForWindow.Top;
        }
 }
\ No newline at end of file