Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
1c441cb
Implemented safearea handling for android
NirmalKumarYuvaraj Aug 5, 2025
0866122
minor changes
NirmalKumarYuvaraj Aug 6, 2025
86d1853
code updated
NirmalKumarYuvaraj Aug 6, 2025
b7a9bef
code changes
NirmalKumarYuvaraj Aug 12, 2025
ede940a
optimized safearea
NirmalKumarYuvaraj Aug 12, 2025
31d1912
scrollview supports safearea edges
NirmalKumarYuvaraj Aug 14, 2025
a5364f6
Updated code changes
NirmalKumarYuvaraj Aug 18, 2025
d759eaa
fixed contentpage issue
NirmalKumarYuvaraj Aug 18, 2025
95e3982
keyboard fix
NirmalKumarYuvaraj Aug 18, 2025
3abfbdc
Used consumption logic
NirmalKumarYuvaraj Aug 26, 2025
5d1a750
optimized approach
NirmalKumarYuvaraj Sep 1, 2025
89fe4ec
more changes
NirmalKumarYuvaraj Sep 2, 2025
02c969c
Added more test cases
NirmalKumarYuvaraj Sep 3, 2025
d05b624
more changes
NirmalKumarYuvaraj Sep 4, 2025
64e52ad
Test failure fixes
NirmalKumarYuvaraj Sep 4, 2025
2f9d960
more refactor
NirmalKumarYuvaraj Sep 4, 2025
67887db
implemented Global listener
NirmalKumarYuvaraj Sep 8, 2025
ffd5533
Resolved issues
NirmalKumarYuvaraj Sep 8, 2025
97fbf64
updated review corrections
NirmalKumarYuvaraj Sep 9, 2025
c4949b3
modal listener
NirmalKumarYuvaraj Sep 9, 2025
4a0da7c
ScrollviewHandling
NirmalKumarYuvaraj Sep 9, 2025
fa88188
more changes
NirmalKumarYuvaraj Sep 11, 2025
af3bf6c
Implemented GetDisplayDensity
NirmalKumarYuvaraj Sep 12, 2025
1a47f20
Addressed test failures
NirmalKumarYuvaraj Sep 15, 2025
a550e60
Addressed test case failures
NirmalKumarYuvaraj Sep 16, 2025
1c20341
Refactor GlobalWindowInsetListener handling for MauiScrollView to avo…
PureWeen Sep 17, 2025
af1b7e8
scroll view changes
NirmalKumarYuvaraj Sep 17, 2025
663e6d0
added intersecting logic for scrollview
NirmalKumarYuvaraj Sep 18, 2025
52dca66
more changes
NirmalKumarYuvaraj Sep 19, 2025
f9a238e
more changes
NirmalKumarYuvaraj Sep 19, 2025
48ca0fb
intersect logic working
NirmalKumarYuvaraj Sep 19, 2025
01d33bb
final commit
NirmalKumarYuvaraj Sep 19, 2025
e9d7960
- fix intersection calculation code
PureWeen Sep 22, 2025
2218785
turn off decor for all APIs
PureWeen Sep 22, 2025
b4dd37f
- set to container
PureWeen Sep 23, 2025
83c2f31
APi 30 test failures addressed
NirmalKumarYuvaraj Sep 23, 2025
820510e
- fix shell
PureWeen Sep 23, 2025
0fb6308
- appbar layout
PureWeen Sep 23, 2025
0837e5a
- remove listener
PureWeen Sep 23, 2025
0aa3132
- fix shell flyout
PureWeen Sep 23, 2025
dc43cea
- remove from the root view
PureWeen Sep 23, 2025
e6097c6
- additional updates
PureWeen Sep 23, 2025
8d27b3e
- fix on root
PureWeen Sep 23, 2025
17ade41
- fix up tests
PureWeen Sep 23, 2025
3edc7f3
- fix up android tests
PureWeen Sep 23, 2025
08f42c2
- account for bottom tabs
PureWeen Sep 23, 2025
0e03995
- fix orientation changes
PureWeen Sep 24, 2025
11314ec
- fix insets on shell flyout
PureWeen Sep 24, 2025
6054146
- fix up android safearea insets
PureWeen Sep 24, 2025
aeffba9
- more fixes
PureWeen Sep 24, 2025
2a7ad03
- fix resetting of inserts if there's no intersection
PureWeen Sep 25, 2025
167450b
- fix to use measured height and width instead
PureWeen Sep 25, 2025
e7aaa85
- fix runner to rerun tests more correctly
PureWeen Sep 25, 2025
26aed46
- fix
PureWeen Sep 25, 2025
0f713d3
- fix device tests
PureWeen Sep 25, 2025
6af9d1e
- update
PureWeen Sep 25, 2025
1630198
- fix flyout paddings
PureWeen Sep 26, 2025
77d8af3
- faith is a facet
PureWeen Sep 26, 2025
ccb208d
- adjust device tests to account for padding
PureWeen Sep 26, 2025
d5e71a9
- fix
PureWeen Sep 26, 2025
4970a43
- fixes
PureWeen Sep 26, 2025
4a52ff3
Increase epsilon value in ShellFlyoutTests
PureWeen Sep 26, 2025
90340d0
Change epsilon value in ShellFlyoutTests
PureWeen Sep 26, 2025
d99b518
Update ShellFlyoutTests.cs
PureWeen Sep 26, 2025
de7d0cb
Refactor platform-specific safe area insets handling
PureWeen Sep 26, 2025
65d7dd6
Add AndroidX.Core.View import for ShellFlyoutTests
PureWeen Sep 26, 2025
74f56bc
Fix formatting in ShellFlyoutTests.cs
PureWeen Sep 26, 2025
209de68
Improve assertion message and add conditional return
PureWeen Sep 26, 2025
d229d7a
Document test behavior for Android headless mode
PureWeen Sep 26, 2025
74e5e61
Clean up ShellFlyoutTests by removing comments
PureWeen Sep 27, 2025
7aeb687
Refactor ShellFlyoutTests for improved readability
PureWeen Sep 27, 2025
de4abaf
Update ShellFlyoutTests.cs
PureWeen Sep 27, 2025
2b1b4d4
Add Theory attribute to FlyoutHeaderScroll test
PureWeen Sep 27, 2025
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 @@ -144,7 +144,7 @@ public override AView OnCreateView(LayoutInflater inflater, ViewGroup container,

var appBar = _root.FindViewById<AppBarLayout>(Resource.Id.shellcontent_appbar);

ViewCompat.SetOnApplyWindowInsetsListener(appBar, new ShellSectionRenderer.WindowsListener());
GlobalWindowInsetListenerExtensions.TrySetGlobalWindowInsetListener(_root, this.Context);

appBar.AddView(_toolbar);
_viewhandler = _page.ToHandler(shellContentMauiContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class ShellFlyoutTemplatedContentRenderer : Java.Lang.Object, IShellFlyou
protected IShellContext ShellContext => _shellContext;
protected AView FooterView => _footerView?.PlatformView;
protected AView View => _rootView;
WindowsListener _windowsListener;


public ShellFlyoutTemplatedContentRenderer(IShellContext shellContext)
Expand Down Expand Up @@ -86,15 +87,84 @@ void OnFlyoutStateChanging(object sender, AndroidX.DrawerLayout.Widget.DrawerLay
// - Do not extend; add new logic to the forthcoming implementation instead.
internal class WindowsListener : Java.Lang.Object, IOnApplyWindowInsetsListener
{
private WeakReference<ImageView> _bgImageRef;
private WeakReference<AView> _flyoutViewRef;
private WeakReference<AView> _footerViewRef;

public AView FlyoutView
{
get
{
if (_flyoutViewRef != null && _flyoutViewRef.TryGetTarget(out var flyoutView))
return flyoutView;

return null;
}
set
{
_flyoutViewRef = new WeakReference<AView>(value);
}
}
public AView FooterView
{
get
{
if (_footerViewRef != null && _footerViewRef.TryGetTarget(out var footerView))
return footerView;

return null;
}
set
{
_footerViewRef = new WeakReference<AView>(value);
}
}

public WindowsListener(ImageView bgImage)
{
_bgImageRef = new WeakReference<ImageView>(bgImage);
}

public WindowInsetsCompat OnApplyWindowInsets(AView v, WindowInsetsCompat insets)
{
if (insets == null || v == null)
return insets;

// The flyout overlaps the status bar so we don't really care about insetting it
var systemBars = insets.GetInsets(WindowInsetsCompat.Type.SystemBars());
var displayCutout = insets.GetInsets(WindowInsetsCompat.Type.DisplayCutout());
var topInset = Math.Max(systemBars?.Top ?? 0, displayCutout?.Top ?? 0);
var bottomInset = Math.Max(systemBars?.Bottom ?? 0, displayCutout?.Bottom ?? 0);
var appbarLayout = v.FindDescendantView<AppBarLayout>((v) => true);

int flyoutViewBottomInset = 0;

if (FooterView is not null)
{
v.SetPadding(0, 0, 0, bottomInset);
flyoutViewBottomInset = 0;
}
else
{
flyoutViewBottomInset = bottomInset;
v.SetPadding(0, 0, 0, 0);
}

if (appbarLayout.MeasuredHeight > 0)
{
FlyoutView?.SetPadding(0, 0, 0, flyoutViewBottomInset);
appbarLayout?.SetPadding(0, topInset, 0, 0);
}
else
{
FlyoutView?.SetPadding(0, topInset, 0, flyoutViewBottomInset);
appbarLayout?.SetPadding(0, 0, 0, 0);
}

v.SetPadding(0, displayCutout?.Top ?? 0, 0, 0);
if (_bgImageRef != null && _bgImageRef.TryGetTarget(out var bgImage) && bgImage != null)
{
bgImage.SetPadding(0, topInset, 0, bottomInset);
}

return WindowInsetsCompat.Consumed;
}
Expand All @@ -107,7 +177,6 @@ protected virtual void LoadView(IShellContext shellContext)
var coordinator = (ViewGroup)layoutInflator.Inflate(Controls.Resource.Layout.flyoutcontent, null);

_appBar = coordinator.FindViewById<AppBarLayout>(Controls.Resource.Id.flyoutcontent_appbar);
ViewCompat.SetOnApplyWindowInsetsListener(_appBar, new WindowsListener());

(_appBar.LayoutParameters as CoordinatorLayout.LayoutParams)
.Behavior = new AppBarLayout.Behavior();
Expand All @@ -132,6 +201,9 @@ protected virtual void LoadView(IShellContext shellContext)
LayoutParameters = new LP(coordinator.LayoutParameters)
};

_windowsListener = new WindowsListener(_bgImage);
ViewCompat.SetOnApplyWindowInsetsListener(coordinator, _windowsListener);

UpdateFlyoutHeaderBehavior();
_shellContext.Shell.PropertyChanged += OnShellPropertyChanged;

Expand Down Expand Up @@ -226,6 +298,7 @@ protected virtual void UpdateFlyoutContent()
}

_flyoutContentView = CreateFlyoutContent(_rootView);
_windowsListener.FlyoutView = _flyoutContentView;
if (_flyoutContentView == null)
return;

Expand Down Expand Up @@ -341,6 +414,7 @@ protected virtual void UpdateFlyoutFooter()
var oldFooterView = _footerView;
_rootView.RemoveView(_footerView);
_footerView = null;
_windowsListener.FooterView = null;
oldFooterView.View = null;
}

Expand All @@ -357,6 +431,8 @@ protected virtual void UpdateFlyoutFooter()
MatchWidth = true
};

_windowsListener.FooterView = _footerView;

var footerViewLP = new CoordinatorLayout.LayoutParams(0, 0)
{
Gravity = (int)(GravityFlags.Bottom | GravityFlags.End)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public override AView OnCreateView(LayoutInflater inflater, ViewGroup container,
var context = Context;
var root = PlatformInterop.CreateShellCoordinatorLayout(context);
var appbar = PlatformInterop.CreateShellAppBar(context, Resource.Attribute.appBarLayoutStyle, root);
ViewCompat.SetOnApplyWindowInsetsListener(appbar, new WindowsListener());
GlobalWindowInsetListenerExtensions.TrySetGlobalWindowInsetListener(root, this.Context);
int actionBarHeight = context.GetActionBarHeight();

var shellToolbar = new Toolbar(shellSection);
Expand Down Expand Up @@ -151,34 +151,6 @@ public override AView OnCreateView(LayoutInflater inflater, ViewGroup container,
return _rootView = root;
}

// Temporary workaround:
// Android 15 / API 36 removed the prior opt‑out path for edge‑to‑edge
// (legacy "edge to edge ignore" + decor fitting). This placeholder exists
// so we can keep apps from regressing (content accidentally covered by
// system bars) until a proper, unified edge‑to‑edge + system bar inset
// configuration API is implemented in MAUI.
//
// NOTE:
// - Keep this minimal.
// - Will be replaced by the planned comprehensive window insets solution.
// - Do not extend; add new logic to the forthcoming implementation instead.
internal class WindowsListener : Java.Lang.Object, IOnApplyWindowInsetsListener
{
public WindowInsetsCompat OnApplyWindowInsets(AView v, WindowInsetsCompat insets)
{
if (insets == null || v == null)
return insets;

var systemBars = insets.GetInsets(WindowInsetsCompat.Type.SystemBars());
var displayCutout = insets.GetInsets(WindowInsetsCompat.Type.DisplayCutout());
var topInset = Math.Max(systemBars?.Top ?? 0, displayCutout?.Top ?? 0);

v.SetPadding(0, topInset, 0, 0);

return WindowInsetsCompat.Consumed;
}
}

void OnShellContentPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == ShellContent.TitleProperty.PropertyName && sender is ShellContent shellContent)
Expand Down
11 changes: 11 additions & 0 deletions src/Controls/src/Core/ContentPage/ContentPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Maui.Graphics;
using Microsoft.Maui.HotReload;
using Microsoft.Maui.Layouts;
using Microsoft.Maui.Devices;

namespace Microsoft.Maui.Controls
{
Expand Down Expand Up @@ -179,6 +180,9 @@ SafeAreaRegions ISafeAreaView2.GetSafeAreaRegionsForEdge(int edge)
return SafeAreaEdges.GetEdge(edge);
}


#if IOS || MACCATALYST

// Developer hasn't set SafeAreaEdges, fall back to legacy IgnoreSafeArea behavior
var ignoreSafeArea = ((ISafeAreaView)this).IgnoreSafeArea;
if (ignoreSafeArea)
Expand All @@ -189,6 +193,13 @@ SafeAreaRegions ISafeAreaView2.GetSafeAreaRegionsForEdge(int edge)
{
return SafeAreaRegions.Container; // If legacy says "don't ignore", return Container
}

#else

// By default on android it was never edge to edge so we set this to container by default
return SafeAreaRegions.Container;

#endif
}

SafeAreaEdges ISafeAreaElement.SafeAreaEdgesDefaultValueCreator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ internal class ModalFragment : DialogFragment
Page _modal;
IMauiContext _mauiWindowContext;
NavigationRootManager? _navigationRootManager;
GlobalWindowInsetListener? _modalInsetListener;
static readonly ColorDrawable TransparentColorDrawable = new(AColor.Transparent);
bool _pendingAnimation = true;

Expand Down Expand Up @@ -311,8 +312,15 @@ public override AView OnCreateView(LayoutInflater inflater, ViewGroup? container

var rootView = _navigationRootManager?.RootView ??
throw new InvalidOperationException("Root view not initialized");

ViewCompat.SetOnApplyWindowInsetsListener(rootView, new WindowHandler.WindowsListener());

var context = rootView.Context ?? inflater.Context;
if (context is not null)
{
// Modal pages get their own separate GlobalWindowInsetListener instance
// This prevents cross-contamination with the main window's inset tracking
_modalInsetListener = new GlobalWindowInsetListener();
ViewCompat.SetOnApplyWindowInsetsListener(rootView, _modalInsetListener);
}

if (IsAnimated)
{
Expand Down Expand Up @@ -368,6 +376,20 @@ public override void OnDismiss(IDialogInterface dialog)
_modal.Toolbar.Handler = null;
}

// Clean up the modal's separate GlobalWindowInsetListener
if (_modalInsetListener is not null)
{
_modalInsetListener.ResetAllViews();
_modalInsetListener.Dispose();
_modalInsetListener = null;
}

var rootView = _navigationRootManager?.RootView;
if (rootView is not null)
{
ViewCompat.SetOnApplyWindowInsetsListener(rootView, null);
}

_modal.Handler = null;
_modal = null!;
_mauiWindowContext = null!;
Expand Down
14 changes: 4 additions & 10 deletions src/Controls/src/Core/SafeAreaElement.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.ComponentModel;
using Microsoft.Maui;
#if ANDROID
using Microsoft.Maui.Platform;
#endif

namespace Microsoft.Maui.Controls
{
Expand All @@ -10,17 +13,8 @@ internal static class SafeAreaElement
/// The backing store for the <see cref="ISafeAreaElement.SafeAreaEdges" /> bindable property.
/// </summary>
public static readonly BindableProperty SafeAreaEdgesProperty =
BindableProperty.Create("SafeAreaEdges", typeof(SafeAreaEdges), typeof(ISafeAreaElement), SafeAreaEdges.Default,
propertyChanged: OnSafeAreaEdgesChanged,
BindableProperty.Create(nameof(ISafeAreaElement.SafeAreaEdges), typeof(SafeAreaEdges), typeof(ISafeAreaElement), SafeAreaEdges.Default,
defaultValueCreator: SafeAreaEdgesDefaultValueCreator);
static void OnSafeAreaEdgesChanged(BindableObject bindable, object oldValue, object newValue)
{
// Centralized implementation - invalidate measure to trigger layout recalculation
if (bindable is IView view)
{
view.InvalidateMeasure();
}
}

static object SafeAreaEdgesDefaultValueCreator(BindableObject bindable)
=> ((ISafeAreaElement)bindable).SafeAreaEdgesDefaultValueCreator();
Expand Down
9 changes: 5 additions & 4 deletions src/Controls/tests/Core.UnitTests/SafeAreaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,11 @@ public void Page_GetSafeAreaRegionsForEdge_DefaultsToNoneForContentPage()
// ContentPage has special logic - defaults to SafeAreaRegions.None (edge-to-edge) on iOS
var safeAreaView2 = (ISafeAreaView2)page;

Assert.Equal(SafeAreaRegions.None, safeAreaView2.GetSafeAreaRegionsForEdge(0));
Assert.Equal(SafeAreaRegions.None, safeAreaView2.GetSafeAreaRegionsForEdge(1));
Assert.Equal(SafeAreaRegions.None, safeAreaView2.GetSafeAreaRegionsForEdge(2));
Assert.Equal(SafeAreaRegions.None, safeAreaView2.GetSafeAreaRegionsForEdge(3));
// only iOS defaults to "None" for ContentPage so we are just validating that the default is container
Assert.Equal(SafeAreaRegions.Container, safeAreaView2.GetSafeAreaRegionsForEdge(0));
Assert.Equal(SafeAreaRegions.Container, safeAreaView2.GetSafeAreaRegionsForEdge(1));
Assert.Equal(SafeAreaRegions.Container, safeAreaView2.GetSafeAreaRegionsForEdge(2));
Assert.Equal(SafeAreaRegions.Container, safeAreaView2.GetSafeAreaRegionsForEdge(3));
}

// Tests based on existing iOS safe area usage patterns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public static object GetFlyoutContentAction(string name, Thickness margin)
switch (name)
{
case "ScrollView":
return new ScrollView() { Content = new Label() { Text = "ScrollView" }, Margin = margin, BackgroundColor = Colors.Orange };
return new ScrollView() { SafeAreaEdges = SafeAreaEdges.None, Content = new Label() { Text = "ScrollView" }, Margin = margin, BackgroundColor = Colors.Orange };
case "VerticalStackLayout":
return new VerticalStackLayout() { Margin = margin, Children = { new Label() { Text = "VerticalStackLayout" } }, BackgroundColor = Colors.Orange };
return new VerticalStackLayout() { SafeAreaEdges = SafeAreaEdges.None, Margin = margin, Children = { new Label() { Text = "VerticalStackLayout" } }, BackgroundColor = Colors.Orange };
}

throw new ArgumentException(nameof(name));
Expand Down
Loading
Loading