Fix FAB lifted twice above the soft keyboard

On SDK < 35 the parent's fitsSystemWindows already shrinks the
FAB container above the soft keyboard, because the deprecated
systemWindowInsets include the IME there.

Adding the IME inset to the container as well lifted the FAB
twice, placing it about twice as high as needed.

Only apply the IME inset on SDK 35+, where the window is
edge-to-edge and the parent is not resized for the keyboard.
This commit is contained in:
Markus Fisch
2026-06-10 18:36:08 +02:00
parent dcecec4d6f
commit 328d0d704c
@@ -48,7 +48,18 @@ fun setPaddingFromWindowInsets(
fun View.setPaddingFromWindowInsets(bottom: Boolean = true) {
doOnApplyWindowInsets { v, insets, windowInsets ->
if (!bottom) {
insets.bottom = getImeBottomInsetWithoutSystemBars(windowInsets)
// On SDK 35+ the window is edge-to-edge and the parent isn't
// resized for the soft keyboard, so lift this view by the IME
// inset (above the navigation bar) here. On older versions the
// parent's fitsSystemWindows already shrinks this view above the
// keyboard, so adding the IME inset again would lift it twice.
insets.bottom = if (
Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM
) {
getImeBottomInsetWithoutSystemBars(windowInsets)
} else {
0
}
}
v.setPadding(insets)
}