-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Fix SafeAreaEdges.SoftInput applying bottom padding when keyboard is hidden #31938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -235,14 +235,20 @@ internal static double GetSafeAreaForEdge(SafeAreaRegions safeAreaRegion, double | |
| } | ||
|
|
||
| // Handle SoftInput specifically - only apply keyboard insets for bottom edge when keyboard is showing | ||
| if (isKeyboardShowing && edge == 3) | ||
| if (edge == 3) | ||
| { | ||
| if (SafeAreaEdges.IsSoftInput(safeAreaRegion)) | ||
| return keyBoardInsets.Bottom; | ||
|
|
||
| // 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)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing to check here. |
||
| { | ||
| // SoftInput only applies padding when keyboard is showing | ||
| return isKeyboardShowing ? keyBoardInsets.Bottom : 0; | ||
| } | ||
|
|
||
| if (isKeyboardShowing) | ||
| { | ||
| // if the 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; | ||
| } | ||
| } | ||
|
|
||
| // All other regions respect safe area in some form | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -143,16 +143,25 @@ SafeAreaRegions GetSafeAreaRegionForEdge(int edge) | |
| return SafeAreaRegions.None; | ||
| } | ||
|
|
||
| static double GetSafeAreaForEdge(SafeAreaRegions safeAreaRegion, double originalSafeArea) | ||
| double GetSafeAreaForEdge(SafeAreaRegions safeAreaRegion, double originalSafeArea, int edge) | ||
| { | ||
| // Edge-to-edge content - no safe area padding | ||
| if (safeAreaRegion == SafeAreaRegions.None) | ||
| return 0; | ||
|
|
||
| // Handle SoftInput specifically - only apply padding when keyboard is actually showing | ||
| if (edge == 3 && SafeAreaEdges.IsSoftInput(safeAreaRegion)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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! |
||
| { | ||
| // SoftInput only applies padding when keyboard is showing | ||
| // When keyboard is hidden, return 0 to avoid showing home indicator padding | ||
| if (!_isKeyboardShowing) | ||
| return 0; | ||
| } | ||
|
|
||
| // All other regions respect safe area in some form | ||
| // This includes: | ||
| // - Default: Platform default behavior | ||
| // - All: Obey all safe area insets | ||
| // - All: Obey all safe area insets (includes SoftInput when keyboard) | ||
| // - SoftInput: Always pad for keyboard/soft input | ||
| // - Container: Content flows under keyboard but stays out of bars/notch | ||
| // - Any combination of the above flags | ||
|
|
@@ -336,10 +345,10 @@ SafeAreaPadding GetAdjustedSafeAreaInsets() | |
| if (View is ISafeAreaView2) | ||
| { | ||
| // Apply safe area selectively per edge based on SafeAreaRegions | ||
| var left = GetSafeAreaForEdge(GetSafeAreaRegionForEdge(0), baseSafeArea.Left); | ||
| var top = GetSafeAreaForEdge(GetSafeAreaRegionForEdge(1), baseSafeArea.Top); | ||
| var right = GetSafeAreaForEdge(GetSafeAreaRegionForEdge(2), baseSafeArea.Right); | ||
| var bottom = GetSafeAreaForEdge(GetSafeAreaRegionForEdge(3), baseSafeArea.Bottom); | ||
| var left = GetSafeAreaForEdge(GetSafeAreaRegionForEdge(0), baseSafeArea.Left, 0); | ||
| var top = GetSafeAreaForEdge(GetSafeAreaRegionForEdge(1), baseSafeArea.Top, 1); | ||
| var right = GetSafeAreaForEdge(GetSafeAreaRegionForEdge(2), baseSafeArea.Right, 2); | ||
| var bottom = GetSafeAreaForEdge(GetSafeAreaRegionForEdge(3), baseSafeArea.Bottom, 3); | ||
|
|
||
| return new SafeAreaPadding(left, right, top, bottom); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.