Skip to content

Commit 365c14b

Browse files
fixed test failures
1 parent 6aba8cf commit 365c14b

File tree

7 files changed

+13
-44
lines changed

7 files changed

+13
-44
lines changed

src/Core/src/Handlers/View/ViewHandler.Android.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,9 @@ internal static void MapSafeAreaEdges(IViewHandler handler, IView view)
268268
}
269269

270270
// Use our static registry approach to find and reset the appropriate listener
271-
var listener = GlobalWindowInsetListener.FindListenerForView(platformView) ??
272-
handler.MauiContext.Context.GetGlobalWindowInsetListener(); // Check for specific view group types that handle safe area
271+
var listener = GlobalWindowInsetListener.FindListenerForView(platformView);
272+
273+
// Check for specific view group types that handle safe area
273274
if (handler.PlatformView is ContentViewGroup cvg)
274275
{
275276
listener?.ResetAppliedSafeAreas(cvg);

src/Core/src/Platform/Android/ContentViewGroup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ protected override void OnConfigurationChanged(Configuration? newConfig)
155155
{
156156
base.OnConfigurationChanged(newConfig);
157157

158-
Context?.GetGlobalWindowInsetListener()?.ResetView(this);
158+
GlobalWindowInsetListener.FindListenerForView(this)?.ResetView(this);
159159
_didSafeAreaEdgeConfigurationChange = true;
160160
}
161161

@@ -231,7 +231,7 @@ internal IBorderStroke? Clip
231231
{
232232
_originalPadding = (PaddingLeft, PaddingTop, PaddingRight, PaddingBottom);
233233
_hasStoredOriginalPadding = true;
234-
}
234+
}
235235

236236
return SafeAreaExtensions.ApplyAdjustedSafeAreaInsetsPx(insets, CrossPlatformLayout, _context, view);
237237
}

src/Core/src/Platform/Android/GlobalWindowInsetListener.cs

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -397,20 +397,8 @@ static bool IsImeAnimation(WindowInsetsAnimationCompat? animation) =>
397397
internal static class GlobalWindowInsetListenerExtensions
398398
{
399399
/// <summary>
400-
/// Gets the shared GlobalWindowInsetListener instance from the current MauiAppCompatActivity.
401-
/// </summary>
402-
/// <param name="context">The Android context</param>
403-
/// <returns>The shared GlobalWindowInsetListener instance, or null if not available</returns>
404-
public static GlobalWindowInsetListener? GetGlobalWindowInsetListener(this Context context)
405-
{
406-
return context.GetActivity() as MauiAppCompatActivity is MauiAppCompatActivity activity
407-
? activity.GlobalWindowInsetListener
408-
: null;
409-
}
410-
411-
/// <summary>
412-
/// Sets the shared GlobalWindowInsetListener on the specified view.
413-
/// This ensures all views use the same listener instance for coordinated inset management.
400+
/// Sets the appropriate GlobalWindowInsetListener on the specified view.
401+
/// This prioritizes local coordinator layout listeners over global ones.
414402
/// </summary>
415403
/// <param name="view">The Android view to set the listener on</param>
416404
/// <param name="context">The Android context to get the listener from</param>
@@ -431,15 +419,7 @@ public static bool TrySetGlobalWindowInsetListener(this View view, Context conte
431419
return false;
432420
}
433421

434-
// Set the global listener
435-
var globalListener = context.GetGlobalWindowInsetListener();
436-
if (globalListener is not null)
437-
{
438-
ViewCompat.SetOnApplyWindowInsetsListener(view, globalListener);
439-
ViewCompat.SetWindowInsetsAnimationCallback(view, globalListener);
440-
return true;
441-
}
442-
422+
// If no listener available, this is likely a configuration issue but not critical
443423
return false;
444424
}
445425

@@ -456,7 +436,7 @@ public static void RemoveGlobalWindowInsetListener(this View view, Context conte
456436
ViewCompat.SetWindowInsetsAnimationCallback(view, null);
457437

458438
// Reset view state - prefer local listener if available, otherwise use global
459-
var listener = GlobalWindowInsetListener.FindListenerForView(view) ?? context.GetGlobalWindowInsetListener();
439+
var listener = GlobalWindowInsetListener.FindListenerForView(view);
460440
listener?.ResetView(view);
461441
}
462442
}

src/Core/src/Platform/Android/LayoutViewGroup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected override void OnDetachedFromWindow()
6060
base.OnDetachedFromWindow();
6161
if (_isInsetListenerSet)
6262
GlobalWindowInsetListenerExtensions.RemoveGlobalWindowInsetListener(this, _context);
63-
63+
6464
_didSafeAreaEdgeConfigurationChange = true;
6565
_isInsetListenerSet = false;
6666
}
@@ -172,7 +172,7 @@ protected override void OnConfigurationChanged(Configuration? newConfig)
172172
{
173173
base.OnConfigurationChanged(newConfig);
174174

175-
Context?.GetGlobalWindowInsetListener()?.ResetView(this);
175+
GlobalWindowInsetListener.FindListenerForView(this)?.ResetView(this);
176176
_didSafeAreaEdgeConfigurationChange = true;
177177
}
178178

src/Core/src/Platform/Android/MauiAppCompatActivity.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@ namespace Microsoft.Maui
1111
{
1212
public partial class MauiAppCompatActivity : AppCompatActivity
1313
{
14-
15-
GlobalWindowInsetListener? _globalWindowInsetListener;
16-
17-
/// <summary>
18-
/// Gets the shared GlobalWindowInsetListener instance for this activity.
19-
/// This ensures all views use the same listener instance for coordinated inset management.
20-
/// </summary>
21-
internal GlobalWindowInsetListener GlobalWindowInsetListener =>
22-
_globalWindowInsetListener ??= new GlobalWindowInsetListener();
23-
2414
// Override this if you want to handle the default Android behavior of restoring fragments on an application restart
2515
protected virtual bool AllowFragmentRestore => false;
2616

@@ -44,8 +34,6 @@ protected override void OnCreate(Bundle? savedInstanceState)
4434

4535
protected override void OnDestroy()
4636
{
47-
_globalWindowInsetListener?.Dispose();
48-
_globalWindowInsetListener = null;
4937
base.OnDestroy();
5038
}
5139

src/Core/src/Platform/Android/MauiScrollView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ protected override void OnConfigurationChanged(Configuration? newConfig)
309309
{
310310
base.OnConfigurationChanged(newConfig);
311311

312-
Context?.GetGlobalWindowInsetListener()?.ResetView(this);
312+
GlobalWindowInsetListener.FindListenerForView(this)?.ResetView(this);
313313
_didSafeAreaEdgeConfigurationChange = true;
314314
}
315315

src/Core/src/Platform/Android/SafeAreaExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ internal static SafeAreaRegions GetSafeAreaRegionForEdge(int edge, ICrossPlatfor
7777
}
7878
}
7979

80-
var globalWindowInsetsListener = context.GetGlobalWindowInsetListener();
80+
var globalWindowInsetsListener = GlobalWindowInsetListener.FindListenerForView(view);
8181
bool hasTrackedViews = globalWindowInsetsListener?.HasTrackedView == true;
8282

8383
// Check intersection with view bounds to determine which edges actually need padding

0 commit comments

Comments
 (0)