Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ bool shouldReceive(UIGestureRecognizer g, UITouch t)

UpdatePanGesture();
UpdateApplyShadow(((FlyoutPage)Element).OnThisPlatform().GetApplyShadow());
UpdatePageSpecifics();
}

public override void ViewWillTransitionToSize(CoreGraphics.CGSize toSize, IUIViewControllerTransitionCoordinator coordinator)
Expand Down Expand Up @@ -364,6 +365,9 @@ void HandlePropertyChanged(object sender, PropertyChangedEventArgs e)
UpdateBackground();
else if (e.PropertyName == PlatformConfiguration.iOSSpecific.FlyoutPage.ApplyShadowProperty.PropertyName)
UpdateApplyShadow(((FlyoutPage)Element).OnThisPlatform().GetApplyShadow());
else if (e.PropertyName == PlatformConfiguration.iOSSpecific.Page.PrefersHomeIndicatorAutoHiddenProperty.PropertyName ||
e.PropertyName == PlatformConfiguration.iOSSpecific.Page.PrefersStatusBarHiddenProperty.PropertyName)
UpdatePageSpecifics();
}

void LayoutChildren(bool animated)
Expand Down Expand Up @@ -551,6 +555,7 @@ void UpdateFlyoutPageContainers()
detailRenderer.ViewController.View.Superview.BackgroundColor = Microsoft.Maui.Graphics.Colors.Black.ToPlatform();

ToggleAccessibilityElementsHidden();
UpdatePageSpecifics();
}

void UpdateLeftBarButton()
Expand All @@ -573,6 +578,20 @@ void UpdateApplyShadow(bool value)
_applyShadow = value;
}

void UpdatePageSpecifics()
{
var isHomeIndicatorHidden = ((FlyoutPage)Element).OnThisPlatform().PrefersHomeIndicatorAutoHidden();
var statusBarUpdateAnimation = ((FlyoutPage)Element).OnThisPlatform().PreferredStatusBarUpdateAnimation();
var prefersStatusBarHidden = ((FlyoutPage)Element).OnThisPlatform().PrefersStatusBarHidden();

((FlyoutPage)Element).Detail.OnThisPlatform().SetPrefersHomeIndicatorAutoHidden(isHomeIndicatorHidden);
((FlyoutPage)Element).Detail.OnThisPlatform().SetPreferredStatusBarUpdateAnimation(statusBarUpdateAnimation);
((FlyoutPage)Element).Detail.OnThisPlatform().SetPrefersStatusBarHidden(prefersStatusBarHidden);

ChildViewControllerForHomeIndicatorAutoHidden.SetNeedsUpdateOfHomeIndicatorAutoHidden();
ChildViewControllerForStatusBarHidden().SetNeedsStatusBarAppearanceUpdate();
}

public override UIViewController ChildViewControllerForStatusBarHidden()
{
if (((FlyoutPage)Element).Detail?.Handler is IPlatformViewHandler nvh)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,14 @@ void HandlePropertyChanged(object sender, PropertyChangedEventArgs e)
{
UpdateHideNavigationBarSeparator();
}
else if (e.PropertyName == PrefersHomeIndicatorAutoHiddenProperty.PropertyName)
{
UpdateHomeIndicatorAutoHidden();
}
else if (e.PropertyName == PrefersStatusBarHiddenProperty.PropertyName)
{
UpdateStatusBarHidden();
}
}

void ValidateNavbarExists(Page newCurrentPage)
Expand All @@ -509,6 +517,22 @@ void ValidateNavbarExists(Page newCurrentPage)
View.InvalidateMeasure(Element);
}

void UpdateHomeIndicatorAutoHidden()
{
if (Element == null)
return;

SetNeedsUpdateOfHomeIndicatorAutoHidden();
}

void UpdateStatusBarHidden()
{
if (Element == null)
return;

SetNeedsStatusBarAppearanceUpdate();
}

void UpdateHideNavigationBarSeparator()
{
bool shouldHide = NavPage.OnThisPlatform().HideNavigationBarSeparator();
Expand Down Expand Up @@ -1480,6 +1504,7 @@ void UpdatePrefersStatusBarHidden()
{
View.SetNeedsLayout();
ParentViewController?.View.SetNeedsLayout();
SetNeedsStatusBarAppearanceUpdate();
}

void TrackerOnCollectionChanged(object sender, EventArgs eventArgs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ void IAppearanceObserver.OnAppearanceChanged(ShellAppearance appearance)

UIViewController IShellFlyoutRenderer.ViewController => this;

public override bool PrefersHomeIndicatorAutoHidden => Detail.PrefersHomeIndicatorAutoHidden;

public override bool PrefersStatusBarHidden() => Detail.PrefersStatusBarHidden();

public override UIStatusBarAnimation PreferredStatusBarUpdateAnimation => Detail.PreferredStatusBarUpdateAnimation;

void IShellFlyoutRenderer.AttachFlyout(IShellContext context, UIViewController content)
{
Context = context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Controls.Platform.Compatibility;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
using Microsoft.Maui.Graphics;
using UIKit;

Expand All @@ -21,6 +22,29 @@ public ShellRenderer()

}

public override bool PrefersHomeIndicatorAutoHidden
=> Shell?.CurrentPage?.OnThisPlatform()?.PrefersHomeIndicatorAutoHidden() ?? base.PrefersHomeIndicatorAutoHidden;


public override bool PrefersStatusBarHidden()
=> Shell?.CurrentPage?.OnThisPlatform()?.PrefersStatusBarHidden() == StatusBarHiddenMode.True;

public override UIKit.UIStatusBarAnimation PreferredStatusBarUpdateAnimation
{
get
{
var mode = Shell?.CurrentPage?.OnThisPlatform()?.PreferredStatusBarUpdateAnimation();
return mode switch
{
PlatformConfiguration.iOSSpecific.UIStatusBarAnimation.None => UIKit.UIStatusBarAnimation.None,
PlatformConfiguration.iOSSpecific.UIStatusBarAnimation.Fade => UIKit.UIStatusBarAnimation.Fade,
PlatformConfiguration.iOSSpecific.UIStatusBarAnimation.Slide => UIKit.UIStatusBarAnimation.Slide,
_ => base.PreferredStatusBarUpdateAnimation,
};
}
}


#region IShellContext

bool IShellContext.AllowFlyoutGesture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using System.Windows.Input;
using Foundation;
using Microsoft.Maui.Controls.Handlers.Compatibility;
using Microsoft.Maui.Controls.Internals;
using ObjCRuntime;
using UIKit;
Expand Down Expand Up @@ -221,6 +222,15 @@ public override void ViewDidLoad()
}


public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear(animated);
if (_context is ShellRenderer shellRenderer)
{
shellRenderer.ViewController.SetNeedsUpdateOfHomeIndicatorAutoHidden();
shellRenderer.ViewController.SetNeedsStatusBarAppearanceUpdate();
}
}

void IDisconnectable.Disconnect()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void SetElement(VisualElement element)
UpdateBarTextColor();
UpdateSelectedTabColors();
UpdateBarTranslucent();
UpdatePageSpecifics();
}

public UIViewController ViewController
Expand Down Expand Up @@ -209,6 +210,8 @@ void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
if (controller == null)
return;

SetNeedsUpdateOfHomeIndicatorAutoHidden();
SetNeedsStatusBarAppearanceUpdate();
SelectedViewController = controller;
}
else if (e.PropertyName == TabbedPage.BarBackgroundColorProperty.PropertyName)
Expand All @@ -223,8 +226,8 @@ void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
UpdateCurrentPagePreferredStatusBarUpdateAnimation();
else if (e.PropertyName == TabbedPage.SelectedTabColorProperty.PropertyName || e.PropertyName == TabbedPage.UnselectedTabColorProperty.PropertyName)
UpdateSelectedTabColors();
else if (e.PropertyName == PrefersHomeIndicatorAutoHiddenProperty.PropertyName)
UpdatePrefersHomeIndicatorAutoHiddenOnPages();
else if (e.PropertyName == PrefersHomeIndicatorAutoHiddenProperty.PropertyName || e.PropertyName == PrefersStatusBarHiddenProperty.PropertyName)
UpdatePageSpecifics();
else if (e.PropertyName == TabbedPageConfiguration.TranslucencyModeProperty.PropertyName)
UpdateBarTranslucent();

Expand Down Expand Up @@ -265,12 +268,21 @@ public override UIViewController ChildViewControllerForHomeIndicatorAutoHidden
}
}

void UpdatePrefersHomeIndicatorAutoHiddenOnPages()
void UpdatePageSpecifics()
{
bool isHomeIndicatorHidden = Tabbed.OnThisPlatform().PrefersHomeIndicatorAutoHidden();
var isHomeIndicatorHidden = Tabbed.OnThisPlatform().PrefersHomeIndicatorAutoHidden();
var statusBarUpdateAnimation = Tabbed.OnThisPlatform().PreferredStatusBarUpdateAnimation();
var prefersStatusBarHidden = Tabbed.OnThisPlatform().PrefersStatusBarHidden();
for (var i = 0; i < ViewControllers.Length; i++)
{
Tabbed.GetPageByIndex(i).OnThisPlatform().SetPrefersHomeIndicatorAutoHidden(isHomeIndicatorHidden);
var page = Tabbed.GetPageByIndex(i).OnThisPlatform();
var viewController = ViewControllers[i];

page.SetPrefersHomeIndicatorAutoHidden(isHomeIndicatorHidden);
page.SetPreferredStatusBarUpdateAnimation(statusBarUpdateAnimation);
page.SetPrefersStatusBarHidden(prefersStatusBarHidden);
viewController.SetNeedsUpdateOfHomeIndicatorAutoHidden();
viewController.SetNeedsStatusBarAppearanceUpdate();
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/Controls/src/Core/ContentPage/ContentPage.Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,24 @@ public partial class ContentPage
internal new static void RemapForControls()
{
PageHandler.Mapper.ReplaceMapping<ContentPage, IPageHandler>(nameof(ContentPage.HideSoftInputOnTapped), MapHideSoftInputOnTapped);
#if IOS
PageHandler.Mapper.ReplaceMapping<ContentPage, IPageHandler>(PlatformConfiguration.iOSSpecific.Page.PrefersHomeIndicatorAutoHiddenProperty.PropertyName, MapPrefersHomeIndicatorAutoHidden);
PageHandler.Mapper.ReplaceMapping<ContentPage, IPageHandler>(PlatformConfiguration.iOSSpecific.Page.PrefersStatusBarHiddenProperty.PropertyName, MapPrefersStatusBarHidden);
#endif
}

#if IOS
static void MapPrefersHomeIndicatorAutoHidden(IPageHandler handler, ContentPage page)
{
handler?.UpdateValue(nameof(IiOSPageSpecifics.IsHomeIndicatorAutoHidden));
}

static void MapPrefersStatusBarHidden(IPageHandler handler, ContentPage page)
{
handler?.UpdateValue(nameof(IiOSPageSpecifics.PrefersStatusBarHiddenMode));
}
#endif

static void MapHideSoftInputOnTapped(IPageHandler handler, ContentPage page)
{
page.UpdateHideSoftInputOnTapped();
Expand Down
14 changes: 14 additions & 0 deletions src/Controls/src/Core/Page/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ namespace Microsoft.Maui.Controls
/// <remarks><see cref = "Page" /> is primarily a base class for more useful derived types. Objects that are derived from the <see cref="Page"/> class are most prominently used as the top level UI element in .NET MAUI applications. In addition to their role as the main pages of applications, <see cref="Page"/> objects and their descendants can be used with navigation classes, such as <see cref="NavigationPage"/> or <see cref="FlyoutPage"/>, among others, to provide rich user experiences that conform to the expected behaviors on each platform.
/// </remarks>
public partial class Page : VisualElement, ILayout, IPageController, IElementConfiguration<Page>, IPaddingElement, ISafeAreaView, ISafeAreaView2, IView, ITitledElement, IToolbarElement
#if IOS
,IiOSPageSpecifics
#endif
{
/// <summary>
/// The identifier used by the internal messaging system to set <see cref="IsBusy"/>.
Expand Down Expand Up @@ -207,6 +210,17 @@ public bool IgnoresContainerArea
/// <inheritdoc/>
bool ISafeAreaView.IgnoreSafeArea => !On<PlatformConfiguration.iOS>().UsingSafeArea();

#if IOS
/// <inheritdoc/>
bool IiOSPageSpecifics.IsHomeIndicatorAutoHidden => On<PlatformConfiguration.iOS>().PrefersHomeIndicatorAutoHidden();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we can leverage interfaces here a bit more to avoid having to always propagate the setting of this property down.

In theory we can check here if the parent has this set and then just return that from the interface.

And then inside the xplat code you'd really just trigger handler updates and not have to do anything inside the renderers.

like, if the user sets this property on TabbedPage you just call "CurrentPage.Handler.Updatevalue"

could probably even just add that to the TabbedPage/Shell/FlyoutPage mappers


/// <inheritdoc/>
int IiOSPageSpecifics.PrefersStatusBarHiddenMode => (int)On<PlatformConfiguration.iOS>().PrefersStatusBarHidden();

/// <inheritdoc/>
int IiOSPageSpecifics.PreferredStatusBarUpdateAnimationMode => (int)On<PlatformConfiguration.iOS>().PreferredStatusBarUpdateAnimation();
#endif

/// <inheritdoc/>
Thickness ISafeAreaView2.SafeAreaInsets
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#nullable enable
override Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer.PreferredStatusBarUpdateAnimation.get -> UIKit.UIStatusBarAnimation
override Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer.PrefersStatusBarHidden() -> bool
override Microsoft.Maui.Controls.Label.ArrangeOverride(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
Microsoft.Maui.Controls.DropCompletedEventArgs.PlatformArgs.get -> Microsoft.Maui.Controls.PlatformDropCompletedEventArgs?
Microsoft.Maui.Controls.PlatformDragEventArgs
Expand Down Expand Up @@ -74,6 +76,11 @@ Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommand.set -> v
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommandParameter.set -> void
override Microsoft.Maui.Controls.Handlers.Items.ItemsViewController<TItemsView>.LoadView() -> void
override Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer.PrefersHomeIndicatorAutoHidden.get -> bool
override Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutRenderer.PreferredStatusBarUpdateAnimation.get -> UIKit.UIStatusBarAnimation
override Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutRenderer.PrefersHomeIndicatorAutoHidden.get -> bool
override Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutRenderer.PrefersStatusBarHidden() -> bool
override Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRenderer.ViewDidAppear(bool animated) -> void
static readonly Microsoft.Maui.Controls.KeyboardAccelerator.KeyProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.KeyboardAccelerator.ModifiersProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.DragGestureRecognizer.CanDragProperty -> Microsoft.Maui.Controls.BindableProperty!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable
override Microsoft.Maui.Controls.Label.ArrangeOverride(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
override Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer.PreferredStatusBarUpdateAnimation.get -> UIKit.UIStatusBarAnimation
override Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer.PrefersStatusBarHidden() -> bool
Microsoft.Maui.Controls.PlatformDragStartingEventArgs
Microsoft.Maui.Controls.PlatformDragStartingEventArgs.DragInteraction.get -> UIKit.UIDragInteraction!
Microsoft.Maui.Controls.PlatformDragStartingEventArgs.DragSession.get -> UIKit.IUIDragSession!
Expand Down Expand Up @@ -84,6 +86,11 @@ static readonly Microsoft.Maui.Controls.PointerGestureRecognizer.PointerPressedC
static readonly Microsoft.Maui.Controls.PointerGestureRecognizer.PointerPressedCommandProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommandParameterProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommandProperty -> Microsoft.Maui.Controls.BindableProperty!
override Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer.PrefersHomeIndicatorAutoHidden.get -> bool
override Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutRenderer.PreferredStatusBarUpdateAnimation.get -> UIKit.UIStatusBarAnimation
override Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutRenderer.PrefersHomeIndicatorAutoHidden.get -> bool
override Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutRenderer.PrefersStatusBarHidden() -> bool
override Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRenderer.ViewDidAppear(bool animated) -> void
virtual Microsoft.Maui.Controls.DragEventArgs.GetPosition(Microsoft.Maui.Controls.Element? relativeTo) -> Microsoft.Maui.Graphics.Point?
virtual Microsoft.Maui.Controls.DragStartingEventArgs.GetPosition(Microsoft.Maui.Controls.Element? relativeTo) -> Microsoft.Maui.Graphics.Point?
virtual Microsoft.Maui.Controls.DropEventArgs.GetPosition(Microsoft.Maui.Controls.Element? relativeTo) -> Microsoft.Maui.Graphics.Point?
Expand Down
4 changes: 4 additions & 0 deletions src/Core/src/Handlers/Page/PageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ public partial class PageHandler : ContentViewHandler, IPageHandler
{
#if IOS || TIZEN
[nameof(IContentView.Background)] = MapBackground,
#if IOS
[nameof(IiOSPageSpecifics.IsHomeIndicatorAutoHidden)] = MapHomeIndicatorAutoHidden,
[nameof(IiOSPageSpecifics.PrefersStatusBarHiddenMode)] = MapPrefersStatusBarHiddenMode,
#endif
#endif
[nameof(ITitledElement.Title)] = MapTitle,
};
Expand Down
16 changes: 16 additions & 0 deletions src/Core/src/Handlers/Page/PageHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ public static void MapBackground(IPageHandler handler, IContentView page)
}
}

public static void MapHomeIndicatorAutoHidden(IPageHandler handler, IContentView page)
{
if (handler is IPlatformViewHandler platformViewHandler && platformViewHandler.ViewController is not null)
{
platformViewHandler.ViewController.SetNeedsUpdateOfHomeIndicatorAutoHidden();
}
}

public static void MapPrefersStatusBarHiddenMode(IPageHandler handler, IContentView page)
{
if (handler is IPlatformViewHandler platformViewHandler && platformViewHandler.ViewController is not null)
{
platformViewHandler.ViewController.SetNeedsStatusBarAppearanceUpdate();
}
}

public static void MapTitle(IPageHandler handler, IContentView page)
{
if (handler is IPlatformViewHandler platformViewHandler && platformViewHandler.ViewController is not null)
Expand Down
26 changes: 26 additions & 0 deletions src/Core/src/Platform/iOS/IiOSPageSpecifics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace Microsoft.Maui.Platform;

/// <summary>
/// Provides functionality for requesting hiding the home indicator on the device screen.
/// </summary>
/// <remarks>
/// This interface may be applied to IContentView.
/// This interface is only recognized on the iOS platform; other platforms will ignore it.
/// </remarks>
internal interface IiOSPageSpecifics
{
/// <summary>
/// Gets a Boolean value that, if true, hides the HomeIndicator.
/// </summary>
bool IsHomeIndicatorAutoHidden { get; }

/// <summary>
/// Gets the preferred mode for the status bar.
/// </summary>
int PrefersStatusBarHiddenMode { get; }

/// <summary>
/// Gets the preferred animation for updating the status bar.
/// </summary>
int PreferredStatusBarUpdateAnimationMode { get; }
}
Loading