[Android] Fix SafeAreaEdges.SoftInput applying bottom padding when keyboard is hidden #31938
+48
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Change
When setting SafeAreaEdges.Bottom = SafeAreaRegions.SoftInput on Android, the bottom edge was incorrectly applying padding from the navigation bar even when the keyboard was not showing. The SoftInput region is designed to only apply padding when the soft keyboard is visible, allowing content to flow under the navigation bar when the keyboard is hidden.
In the screenshot above, notice the unwanted padding at the bottom (yellow area) when Bottom:SoftInput is set, even though the keyboard is not visible.
The issue was in the GetSafeAreaForEdge method in SafeAreaExtensions.cs. When the keyboard was hidden, the condition
isKeyboardShowing && edge == 3
evaluated to false, causing the code to skip the SoftInput handling entirely and fall through to returnoriginalSafeArea
, which returns the navigation bar padding (~48-80px) for all regions including SoftInput.This PR add changes to the logic to check the edge first, then check if the region is SoftInput, and only then check the keyboard state.
Added a new UITest:
The expected behavior would be:
SoftInput
+ Keyboard HiddenSoftInput
+ Keyboard ShowingContainer
+ Keyboard HiddenContainer
+ Keyboard ShowingIssues Fixed
Fixes #31870