Skip to content

Commit 68f5a7d

Browse files
Fix keyboard overlapping content issue
1 parent d9c689a commit 68f5a7d

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

src/Core/src/Platform/Android/SafeAreaExtensions.cs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,6 @@ internal static SafeAreaRegions GetSafeAreaRegionForEdge(int edge, ICrossPlatfor
6262
var right = GetSafeAreaForEdge(GetSafeAreaRegionForEdge(2, layout), baseSafeArea.Right, 2, isKeyboardShowing, keyboardInsets);
6363
var bottom = GetSafeAreaForEdge(GetSafeAreaRegionForEdge(3, layout), baseSafeArea.Bottom, 3, isKeyboardShowing, keyboardInsets);
6464

65-
if (isKeyboardShowing &&
66-
context.GetActivity()?.Window is Window window &&
67-
window?.Attributes is WindowManagerLayoutParams attr)
68-
{
69-
// If the window is panned from the keyboard being open
70-
// and there isn't a bottom inset to apply then just don't touch anything
71-
var softInputMode = attr.SoftInputMode;
72-
if (softInputMode == SoftInput.AdjustPan
73-
&& bottom == 0
74-
)
75-
{
76-
return WindowInsetsCompat.Consumed;
77-
}
78-
}
7965

8066
var globalWindowInsetsListener = context.GetGlobalWindowInsetListener();
8167
bool hasTrackedViews = globalWindowInsetsListener?.HasTrackedView == true;
@@ -255,12 +241,18 @@ internal static double GetSafeAreaForEdge(SafeAreaRegions safeAreaRegion, double
255241
// Handle SoftInput specifically - only apply keyboard insets for bottom edge when keyboard is showing
256242
if (isKeyboardShowing && edge == 3)
257243
{
244+
// Always apply keyboard insets when keyboard is showing to prevent content overlap
245+
// Use keyboard height or original safe area, whichever is larger
246+
var keyboardInset = keyBoardInsets.Bottom;
258247
if (SafeAreaEdges.IsSoftInput(safeAreaRegion))
259-
return keyBoardInsets.Bottom;
248+
return Math.Max(keyboardInset, originalSafeArea);
260249

261-
// if they keyboard is showing then we will just return 0 for the bottom inset
262-
// because that part of the view is covered by the keyboard so we don't want to pad the view
263-
return 0;
250+
// For non-SoftInput regions, still apply keyboard padding to prevent overlap
251+
// unless explicitly set to None region
252+
if (safeAreaRegion != SafeAreaRegions.None)
253+
return Math.Max(keyboardInset, originalSafeArea);
254+
255+
return keyboardInset;
264256
}
265257

266258
// All other regions respect safe area in some form

0 commit comments

Comments
 (0)