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>
<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 & TV"
Icon="film.png" FlyoutIcon="filmflyout.png" ContentTemplate="{DataTemplate local:MoviesPage}">
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);
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);
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;
{
get
{
- var animation = ((Page)Element).OnThisPlatform().PreferredStatusBarUpdateAnimation();
+ var animation = Page.OnThisPlatform().PreferredStatusBarUpdateAnimation();
switch (animation)
{
case (PageUIStatusBarAnimation.Fade):
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()
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
public override bool PrefersStatusBarHidden()
{
- var mode = ((Page)Element).OnThisPlatform().PrefersStatusBarHidden();
+ var mode = Page.OnThisPlatform().PrefersStatusBarHidden();
switch (mode)
{
case (StatusBarHiddenMode.True):
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)
SetNeedsUpdateOfHomeIndicatorAutoHidden();
}
- public override bool PrefersHomeIndicatorAutoHidden => ((Page)Element).OnThisPlatform().PrefersHomeIndicatorAutoHidden();
+ public override bool PrefersHomeIndicatorAutoHidden => Page.OnThisPlatform().PrefersHomeIndicatorAutoHidden();
}
}
\ No newline at end of file
-using CoreGraphics;
+using CoreAnimation;
+using CoreGraphics;
using System;
using UIKit;
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()
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);
}
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:
LayoutParallax();
}
+
+ float SafeAreaOffset => (float)Platform.SafeAreaInsetsForWindow.Top;
}
}
\ No newline at end of file