Skip to content

Commit dd575ff

Browse files
committed
calculate IME inset and pass the event through down to children, otherwise the nested scrollbars can't figure out tto update themselves
1 parent 7cd7192 commit dd575ff

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Simplenote/src/main/java/com/automattic/simplenote/utils/SystemBarUtils.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import androidx.appcompat.widget.Toolbar
1010
import androidx.core.view.ViewCompat
1111
import androidx.core.view.WindowCompat
1212
import androidx.core.view.WindowInsetsCompat
13+
import kotlin.math.max
1314

1415
/**
1516
* Utility class to handle system bar appearance changes in a way that's compatible
@@ -116,19 +117,24 @@ object SystemBarUtils {
116117
}
117118

118119
// Handle content view insets - avoid overlap with navigation bar
119-
if (contentView != null) {
120+
contentView?.let {
120121
ViewCompat.setOnApplyWindowInsetsListener(
121-
contentView,
122+
it,
122123
{ v: View, windowInsets: WindowInsetsCompat ->
123124
val systemBars = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
124-
// Apply bottom padding to avoid navigation bar overlap
125+
val ime = windowInsets.getInsets(WindowInsetsCompat.Type.ime())
126+
// Apply bottom padding to avoid navigation bar overlap, but let's consider IME too
127+
// this will prevent the keyboard from pushing the content down
128+
val bottomPadding = max(systemBars.bottom, ime.bottom)
125129
v.setPadding(
126130
v.getPaddingLeft(),
127131
v.getPaddingTop(),
128132
v.getPaddingRight(),
129-
systemBars.bottom
133+
bottomPadding
130134
)
131-
WindowInsetsCompat.CONSUMED
135+
// WARNING: Don't consume IME insets - let them pass through to child views (scroll views)
136+
// this will allow proper scrolling when keyboard appears
137+
windowInsets.inset(0, 0, 0, systemBars.bottom)
132138
})
133139
}
134140
}

0 commit comments

Comments
 (0)