Skip to content

[Android] Fix SafeAreaEdges.SoftInput applying bottom padding when keyboard is hidden#31938

Closed
jsuarezruiz wants to merge 3 commits intonet10.0from
fix-31870
Closed

[Android] Fix SafeAreaEdges.SoftInput applying bottom padding when keyboard is hidden#31938
jsuarezruiz wants to merge 3 commits intonet10.0from
fix-31870

Conversation

@jsuarezruiz
Copy link
Contributor

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.

image

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 return originalSafeArea, 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:

  • Setting bottom edge to None as baseline
  • Setting bottom edge to SoftInput (keyboard hidden)
  • Verifying MainGrid height remains the same (no bottom padding)
image

The expected behavior would be:

Scenario Before After
SoftInput + Keyboard Hidden ❌ Navigation bar padding (~48-80px) ✅ No padding (0px)
SoftInput + Keyboard Showing ✅ Keyboard height padding ✅ Keyboard height padding
Container + Keyboard Hidden ✅ Navigation bar padding ✅ Navigation bar padding
Container + Keyboard Showing ✅ No padding ✅ No padding

Issues Fixed

Fixes #31870

Copilot AI review requested due to automatic review settings October 9, 2025 11:27
@jsuarezruiz jsuarezruiz added t/bug Something isn't working platform/android labels Oct 9, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 GetSafeAreaForEdge to 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 PureWeen added this to the .NET 10.0 GA milestone Oct 9, 2025
@PureWeen PureWeen moved this from Todo to Ready To Review in MAUI SDK Ongoing Oct 9, 2025
Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsuarezruiz do we need to also account for these changes on ios?

@github-project-automation github-project-automation bot moved this from Ready To Review to Changes Requested in MAUI SDK Ongoing Oct 10, 2025
@PureWeen PureWeen added the p/0 Current heighest priority issues that we are targeting for a release. label Oct 13, 2025
@jsuarezruiz
Copy link
Contributor Author

@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))
Copy link
Member

@PureWeen PureWeen Oct 17, 2025

Choose a reason for hiding this comment

The 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!

// 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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing to check here.

@PureWeen
Copy link
Member

closing in favor of
#32064

@PureWeen PureWeen closed this Oct 22, 2025
@github-project-automation github-project-automation bot moved this from Changes Requested to Done in MAUI SDK Ongoing Oct 22, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Nov 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

p/0 Current heighest priority issues that we are targeting for a release. platform/android t/bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants