From 75bbaa8b39f541c72a32ce5eedd2cb9a82ffb044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Baumeyer?= Date: Mon, 26 Oct 2026 15:28:34 +0100 Subject: [PATCH] [Android] SafeArea: let empty insets reach tracked views so SoftInput padding resets MauiWindowInsetListener returned early on !HasInsets, so on a window with no system bars the dispatch that follows the keyboard closing never reached the view still carrying keyboard-height padding. Co-Authored-By: Claude Opus 5.5 --- .../MauiWindowInsetListenerTests.Android.cs | 25 +++++++++++++++++++ .../Android/MauiWindowInsetListener.cs | 6 ++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Window/MauiWindowInsetListenerTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/Window/MauiWindowInsetListenerTests.Android.cs index eda7e4c1c697..2f76299d9495 100644 --- a/src/Controls/tests/DeviceTests/Elements/Window/MauiWindowInsetListenerTests.Android.cs +++ b/src/Controls/tests/DeviceTests/Elements/Window/MauiWindowInsetListenerTests.Android.cs @@ -304,5 +304,30 @@ await container.AttachAndRun(async () => }); }); } + + [Fact] + public async Task EmptyInsetsReachTrackedViewsOnly() + { + await InvokeOnMainThreadAsync(() => + { + var listener = new MauiWindowInsetListener(); + var tracked = new InsetRecordingView(MauiContext.Context!); + var untracked = new InsetRecordingView(MauiContext.Context!); + + // Keyboard closed on a window with no system bars: every inset is zero + var emptyInsets = new WindowInsetsCompat.Builder().Build()!; + Assert.False(emptyInsets.HasInsets); + + // A tracked view holds padding from earlier insets (e.g. the keyboard height) + // and must get the empty dispatch to reset it + listener.TrackView(tracked); + listener.OnApplyWindowInsets(tracked, emptyInsets); + Assert.Equal(1, tracked.HandledCount); + + // A view that never had padding has nothing to reset + listener.OnApplyWindowInsets(untracked, emptyInsets); + Assert.Equal(0, untracked.HandledCount); + }); + } } } diff --git a/src/Core/src/Platform/Android/MauiWindowInsetListener.cs b/src/Core/src/Platform/Android/MauiWindowInsetListener.cs index 9e1c59edf571..1cb50f15bb1d 100644 --- a/src/Core/src/Platform/Android/MauiWindowInsetListener.cs +++ b/src/Core/src/Platform/Android/MauiWindowInsetListener.cs @@ -274,7 +274,11 @@ internal void NotifyViewAttached(AView view) public virtual WindowInsetsCompat? OnApplyWindowInsets(AView? v, WindowInsetsCompat? insets) { - if (insets is null || !insets.HasInsets || v is null || + // Empty insets still reach a tracked view: once the keyboard closes on a window with + // no system bars (immersive, tablet in desktop windowing), every inset is zero, and + // skipping the dispatch would leave the keyboard-height padding on the view for good. + if (insets is null || v is null || + (!insets.HasInsets && !IsViewTracked(v)) || (IsImeAnimating && !_viewsAttachedDuringImeAnimation.Contains(v))) { if (IsImeAnimating && v is not null)