Keyboard does not open if the TextField inside LazyColumn is in the bottom of the screen
Asked Answered
P

0

9

If you focus a TextField near the bottom of the screen, keyboard appears for a moment and then immediately hides. But if you focus some TextField from above, keyboard opens as usual and you can scroll to the bottom. This happens if windowSoftInputMode is set to adjustResize. If none is set, then the behaviour goes to i would say random (keyboard may overlap content, also it may push toolbar and etc.). Perhaps i am simply doing all this wrong, i dunno. I wonder if anyone faced this issue before and could give me a hand.

Sample code (for simplicity i hold mutable states right here, not using ViewModel):

@Composable
fun Greeting() {
    Scaffold(topBar = {
        TopAppBar(title = { Text(text = "Some title") })
    }) {
        val focusManager = LocalFocusManager.current
        LazyColumn(
            contentPadding = PaddingValues(all = 16.dp),
            verticalArrangement = Arrangement.spacedBy(space = 16.dp)
        ) {
            items(count = 20) { index ->
                val (value, onValueChange) = rememberSaveable { mutableStateOf("Some value $index") }
                TextField(
                    value = value,
                    onValueChange = onValueChange,
                    modifier = Modifier.fillMaxWidth(),
                    label = { Text(text = "Some label $index") },
                    keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
                    keyboardActions = KeyboardActions(onNext = {
                        if (!focusManager.moveFocus(FocusDirection.Down))
                            focusManager.clearFocus()
                    }),
                    singleLine = true
                )
            }
        }
    }
}

Compose version 1.0.5

Pyretic answered 7/12, 2021 at 14:27 Comment(11)
workaround without dirty code All workarounds are basically dirty code. BTW that's an opinion ... However for your 2nd problem you can refer this #64065382Gamine
Don't ask more than one question at a time. It will be difficult for others to find the right answer when they encounter a similar problem. You can edit the text/title of the question and create one or two more. The third problem is close to this known problem, the thread has several workarounds until it is fixed.Adhamh
@Gamine agree on workarounds, and thank you for the tip.Pyretic
@PhilipDukhov understood, i have split my question into several ones. And thanks for the link.Pyretic
@ArtemRadivilov I wasn't been able to reproduce it - keyboard appears fine for the bottom text field, even if it's half visible. It's not scrolling to become visible, but as I said, it's a known issue. Sure you can reproduce it in a clean project with the code attached? I have android:windowSoftInputMode="adjustResize" as you saidAdhamh
@PhilipDukhov if i click the very bottom TextField, then it behaves just as you described (show keyboard, but does not scroll). If i click a TextField a bit higher (lets say a bit below than keyboard may occupy) then it behaves the way i described (opens and immediately closes)Pyretic
Can reproduce this issue.Bultman
Did anyone find a solution for this issue??Viguerie
@Viguerie there is a pin feature in lazycolumn in recent updateBultman
can you point me in the right direction @Bultman ?Viguerie
@Viguerie issuetracker.google.com/issues/259274257#comment7Bultman

© 2022 - 2024 — McMap. All rights reserved.