Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -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);
});
}
}
}
6 changes: 5 additions & 1 deletion src/Core/src/Platform/Android/MauiWindowInsetListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading