Skip to content

Commit 0ddfb98

Browse files
committed
Refactor: Move ISafeAreaIgnoredContainer check to FindListenerForView
Move the ISafeAreaIgnoredContainer logic from SafeAreaExtensions to MauiWindowInsetListener.FindListenerForView(). This prevents inset listeners from being added to ListView/TableView children in the first place, rather than applying listeners and then zeroing out safe area. Benefits: - Cleaner architecture: listeners aren't added where they shouldn't be - More efficient: no unnecessary listener attachment or calculations - Clearer intent: early rejection at listener discovery phase
1 parent 3a0ac63 commit 0ddfb98

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/Core/src/Platform/Android/MauiWindowInsetListener.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ internal void RegisterView(AView view)
120120
}
121121
else if (ReferenceEquals(registeredView, parentView))
122122
{
123+
// Before returning the listener, check if any ancestor is a safe-area-ignored container
124+
// If so, don't apply inset listeners to this view or any of its children
125+
if (entry.Listener.IsInsideSafeAreaIgnoredContainer(view))
126+
{
127+
return null;
128+
}
129+
123130
return entry.Listener;
124131
}
125132
}
@@ -132,6 +139,38 @@ internal void RegisterView(AView view)
132139
}
133140

134141
/// <summary>
142+
/// <summary>
143+
/// Checks if a view is inside a container that ignores safe area (ListView, TableView).
144+
/// These containers manage their own layout and should NOT have safe area insets applied to their content.
145+
/// </summary>
146+
/// <param name="view">The view to check</param>
147+
/// <returns>True if the view is inside an ISafeAreaIgnoredContainer, false otherwise</returns>
148+
private bool IsInsideSafeAreaIgnoredContainer(AView view)
149+
{
150+
// Walk up from the current view to find its IView representation
151+
var currentView = view;
152+
while (currentView != null)
153+
{
154+
if (currentView is IViewHandler handler && handler.VirtualView is IView virtualView)
155+
{
156+
// Check if any ancestor in the virtual view hierarchy is ISafeAreaIgnoredContainer
157+
var ancestor = virtualView.Parent as IView;
158+
while (ancestor != null)
159+
{
160+
if (ancestor is ISafeAreaIgnoredContainer)
161+
{
162+
return true;
163+
}
164+
ancestor = ancestor.Parent as IView;
165+
}
166+
break;
167+
}
168+
currentView = currentView.Parent as AView;
169+
}
170+
171+
return false;
172+
}
173+
135174
/// Sets up a view to use this listener for inset handling.
136175
/// This method registers the view and attaches the listener.
137176
/// Must be called on UI thread.

0 commit comments

Comments
 (0)