- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.9k
 
[Android] Fix SafeArea padding calculation with AdjustPan and Container+SoftInput #31998
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 a bug in Android SafeArea padding calculation when using Container SafeAreaEdges with SoftInput on the bottom edge in AdjustPan window mode. When the keyboard appears and causes the window to pan, the existing position-based overlap calculations fail because view coordinates become unreliable (negative Y values), incorrectly removing top padding and causing content to overlap with system UI.
Key changes:
- Added detection for AdjustPan mode when keyboard is showing
 - Skip position-based overlap calculations in AdjustPan mode to prevent incorrect padding removal
 - Added comprehensive UI test to validate the fix
 
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description | 
|---|---|
| src/Core/src/Platform/Android/SafeAreaExtensions.cs | Core fix: detects AdjustPan mode and bypasses unreliable position calculations | 
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28986.cs | Adds UI test to validate Container+SoftInput behavior with keyboard | 
Comments suppressed due to low confidence (1)
src/Core/src/Platform/Android/SafeAreaExtensions.cs:1
- Removed unused import 
Google.Android.Material.AppBarwhich is good for maintainability, but verify that this import isn't used elsewhere in the file that wasn't shown in the diff. 
using System;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 
           /rebase  | 
    
| // and there isn't a bottom inset to apply then just don't touch anything | ||
| var softInputMode = attr.SoftInputMode; | ||
| if (softInputMode == SoftInput.AdjustPan | ||
| && bottom == 0 | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsuarezruiz , Is the bottom == 0 check actually needed?
Consider this scenario: the user sets the SoftInputMode to Pan, deploys the host app, and navigates to Issue28986_ContentPage.xaml. By default, the content page’s SafeAreaEdges property is set to All.
Now, click the Entry control. Notice that the window gets resized.
This happens because when the content page’s SafeAreaEdges is set to All, or when the bottom edge is configured for the SoftInput, the ApplyAdjustedSafeAreaInsetsPx() method processes the visual tree. Initially, the ContentPage is processed, and the bottom value is not 0—it’s 883 (the keyboard inset value). As a result, the condition softInputMode == SoftInput.AdjustPan && bottom == 0 fails, and instead of panning, the window gets resized.


Description of Change
When setting SafeAreaEdges to Container on all sides and SoftInput on bottom, the padding calculation is incorrect when the keyboard appears and causes the window to pan.
The code performs position-based overlap calculations by checking if the view extends into safe area regions. However, when the window is in AdjustPan mode:
GetLocationOnScreenreturns negative Y coordinates (view pushed above visible screen) and then conditionviewTop >= 0at line 114 fails, causing top padding to be set to 0Modified SafeAreaExtensions.cs to detect AdjustPan mode and skip unreliable position-based calculations. Detect if window is in AdjustPan mode when keyboard shows. When in AdjustPan mode with keyboard showing, bypass position-based overlap logic.
Issues Fixed
Fixes #31871