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
55af89f
Implemented safearea handling for android
NirmalKumarYuvaraj Aug 5, 2025
3c2f526
minor changes
NirmalKumarYuvaraj Aug 6, 2025
4b32af8
code updated
NirmalKumarYuvaraj Aug 6, 2025
f264ae6
code changes
NirmalKumarYuvaraj Aug 12, 2025
a369234
optimized safearea
NirmalKumarYuvaraj Aug 12, 2025
0bf66e3
scrollview supports safearea edges
NirmalKumarYuvaraj Aug 14, 2025
8aef853
Updated code changes
NirmalKumarYuvaraj Aug 18, 2025
150139a
fixed contentpage issue
NirmalKumarYuvaraj Aug 18, 2025
e6f6d74
keyboard fix
NirmalKumarYuvaraj Aug 18, 2025
acae4ce
Used consumption logic
NirmalKumarYuvaraj Aug 26, 2025
056b5ef
optimized approach
NirmalKumarYuvaraj Sep 1, 2025
fc6fec3
more changes
NirmalKumarYuvaraj Sep 2, 2025
9a0f1ba
Added more test cases
NirmalKumarYuvaraj Sep 3, 2025
4af3b0b
more changes
NirmalKumarYuvaraj Sep 4, 2025
194b85f
Test failure fixes
NirmalKumarYuvaraj Sep 4, 2025
065c32d
more refactor
NirmalKumarYuvaraj Sep 4, 2025
b4ced92
implemented Global listener
NirmalKumarYuvaraj Sep 8, 2025
9f0c3a0
Resolved issues
NirmalKumarYuvaraj Sep 8, 2025
60d75b7
updated review corrections
NirmalKumarYuvaraj Sep 9, 2025
6412686
modal listener
NirmalKumarYuvaraj Sep 9, 2025
5713dcf
ScrollviewHandling
NirmalKumarYuvaraj Sep 9, 2025
5c6a2db
more changes
NirmalKumarYuvaraj Sep 11, 2025
987f9e1
Implemented GetDisplayDensity
NirmalKumarYuvaraj Sep 12, 2025
6073cfe
Addressed test failures
NirmalKumarYuvaraj Sep 15, 2025
5514f98
Addressed test case failures
NirmalKumarYuvaraj Sep 16, 2025
6967ffe
Refactor GlobalWindowInsetListener handling for MauiScrollView to avo…
PureWeen Sep 17, 2025
fa0b18d
scroll view changes
NirmalKumarYuvaraj Sep 17, 2025
798fc25
added intersecting logic for scrollview
NirmalKumarYuvaraj Sep 18, 2025
d502a78
more changes
NirmalKumarYuvaraj Sep 19, 2025
b13cda0
more changes
NirmalKumarYuvaraj Sep 19, 2025
0f68157
intersect logic working
NirmalKumarYuvaraj Sep 19, 2025
aceea8a
final commit
NirmalKumarYuvaraj Sep 19, 2025
25cfaa2
- fix intersection calculation code
PureWeen Sep 22, 2025
6d61050
turn off decor for all APIs
PureWeen Sep 22, 2025
0a2b64c
- set to container
PureWeen Sep 23, 2025
b50fd1e
APi 30 test failures addressed
NirmalKumarYuvaraj Sep 23, 2025
7236ab8
- fix shell
PureWeen Sep 23, 2025
af2e179
- appbar layout
PureWeen Sep 23, 2025
b2e4b00
- remove listener
PureWeen Sep 23, 2025
66992c6
- fix shell flyout
PureWeen Sep 23, 2025
75fa9b8
- remove from the root view
PureWeen Sep 23, 2025
c940b2e
- additional updates
PureWeen Sep 23, 2025
357b01c
- fix on root
PureWeen Sep 23, 2025
1900fbf
- fix up tests
PureWeen Sep 23, 2025
3ba5bed
- fix up android tests
PureWeen Sep 23, 2025
cf171d8
- account for bottom tabs
PureWeen Sep 23, 2025
744b89a
- fix orientation changes
PureWeen Sep 24, 2025
b206267
- fix insets on shell flyout
PureWeen Sep 24, 2025
344082b
- fix up android safearea insets
PureWeen Sep 24, 2025
6c55690
- more fixes
PureWeen Sep 24, 2025
f1040d0
- fix resetting of inserts if there's no intersection
PureWeen Sep 25, 2025
fd6c2c6
- fix to use measured height and width instead
PureWeen Sep 25, 2025
2174b8c
- fix runner to rerun tests more correctly
PureWeen Sep 25, 2025
d1dd039
- fix
PureWeen Sep 25, 2025
92d7f8e
- fix device tests
PureWeen Sep 25, 2025
2abba28
- update
PureWeen Sep 25, 2025
b3d0984
- fix flyout paddings
PureWeen Sep 26, 2025
e8f20cc
- faith is a facet
PureWeen Sep 26, 2025
702c9b6
- adjust device tests to account for padding
PureWeen Sep 26, 2025
606ca0c
- fix
PureWeen Sep 26, 2025
305fabb
- fixes
PureWeen Sep 26, 2025
410589c
Increase epsilon value in ShellFlyoutTests
PureWeen Sep 26, 2025
eced60a
Change epsilon value in ShellFlyoutTests
PureWeen Sep 26, 2025
97a437d
Update ShellFlyoutTests.cs
PureWeen Sep 26, 2025
9a7fb4d
Refactor platform-specific safe area insets handling
PureWeen Sep 26, 2025
7daf0e2
Add AndroidX.Core.View import for ShellFlyoutTests
PureWeen Sep 26, 2025
883572e
Fix formatting in ShellFlyoutTests.cs
PureWeen Sep 26, 2025
8eea96a
Improve assertion message and add conditional return
PureWeen Sep 26, 2025
55510a2
Document test behavior for Android headless mode
PureWeen Sep 26, 2025
c1f46f1
Clean up ShellFlyoutTests by removing comments
PureWeen Sep 27, 2025
a91d8dd
Refactor ShellFlyoutTests for improved readability
PureWeen Sep 27, 2025
20592c0
Update ShellFlyoutTests.cs
PureWeen Sep 27, 2025
ba8d01b
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