How do I fix a textfield above the ime (during its...
# compose-android
v
How do I fix a textfield above the ime (during its opening animation) when the field's parent is scrollable? I'm able to replicate figure 2 in https://developer.android.com/develop/ui/compose/layouts/insets#inset-consumption, but it has the same issue where the scroll lags behind the ime's opening animation. I can verify that the scroll lags by replacing my
imePadding()
call with:
Copy code
.composed {
    val ime = WindowInsets.ime
    Log.i("COMPOSE", "ime: $ime")
    Log.i("COMPOSE", "scroll: ${scroll.value}") // scroll: ScrollState
    Modifier.windowInsetsPadding(ime)
}
(
ime
starts updating ~50ms before and ~100ms after
scroll
)
Here's the mentioned video figure for posterity:
Here's a slowed down recording of the issue. I would like the ime to not occlude the selected textfield
h
which overload of TextField are you using?
value, onValueChange
or
TextFieldState
? Also what is compose foundation version in your project?
v
Thank you for looking at this, I'm using the
value, onValueChange
overload with compose BOM 2024.11.00 (compose.foundation 1.7.5). Also here's a quick MRE (both
LazyColumn
and
Column
cause the issue):
Copy code
@Composable
fun MRE() {
    LazyColumn(
        Modifier
            .padding(horizontal = 24.dp)
            .imePadding(),
        verticalArrangement = Arrangement.spacedBy(8.dp)
    ) {
        items(20) {
            OutlinedTextField("",
                onValueChange = {},
                modifier = Modifier.fillMaxWidth(),
                label = { Text("Field ${it + 1}") })
        }
        item {
            Spacer(Modifier.navigationBarsPadding())
        }
    }
}
Actually, I'm able to hack around the issue for
LazyColumn
by setting
reverseLayout = true
and placing my items in reverse (and reversing the initial scroll state index).
Only works for the last textfield.
s
Could you then try with the version which takes in TextFieldState and use the latest BOM at first but also try the latest Alpha BOM? If it works with any of these combinations, you know what to use. If not, you can file a bug report.
v