[Android] Fix SafeAreaEdges.SoftInput applying bottom padding when keyboard is hidden#31938
[Android] Fix SafeAreaEdges.SoftInput applying bottom padding when keyboard is hidden#31938jsuarezruiz wants to merge 3 commits intonet10.0from
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an Android-specific bug where SafeAreaEdges.SoftInput was incorrectly applying bottom padding from the navigation bar when the keyboard was hidden. The SoftInput region should only apply padding when the soft keyboard is visible, allowing content to flow under the navigation bar otherwise.
- Refactored the conditional logic in
GetSafeAreaForEdgeto properly handle SoftInput region by checking edge first, then region type, then keyboard state - Added comprehensive UI test to verify SoftInput behavior when keyboard is hidden
- Ensures SoftInput only applies keyboard height padding when keyboard is showing, otherwise returns 0
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Core/src/Platform/Android/SafeAreaExtensions.cs | Fixed logic flow in GetSafeAreaForEdge to properly handle SoftInput region behavior |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28986.cs | Added UI test to validate SoftInput doesn't apply bottom padding when keyboard is hidden |
PureWeen
left a comment
There was a problem hiding this comment.
@jsuarezruiz do we need to also account for these changes on ios?
Right, applied changes too 980459d |
| return 0; | ||
|
|
||
| // Handle SoftInput specifically - only apply padding when keyboard is actually showing | ||
| if (edge == 3 && SafeAreaEdges.IsSoftInput(safeAreaRegion)) |
There was a problem hiding this comment.
I don't think this check is quite right
It needs to validate if the user only wants SoftInput
For example, if I set the SafeAreaEdges to ALL it's no no longer working on the bottom edge because ALL means softinput and bottom edge.
Since the tests on this one are currently green, please also add a test that would have caught this!
| // if they keyboard is showing then we will just return 0 for the bottom inset | ||
| // because that part of the view is covered by the keyboard so we don't want to pad the view | ||
| return 0; | ||
| if (SafeAreaEdges.IsSoftInput(safeAreaRegion)) |
|
closing in favor of |
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 == 3evaluated 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