https://kotlinlang.org logo
#compose
Title
# compose
r

Robert Menke

11/03/2020, 8:13 PM
I’m running into an intermittent issue in alpha06 where `TextField`s don’t bring up the keyboard when focused. Has anyone run into this issue? Another issue I have with my
TextField
in alpha06 is that
ImeAction.GO
doesn’t seem to be working the same way it was in previous versions.
Copy code
val focusRequester = FocusRequester()

            TextField(
                value = text,
                onValueChange = viewModel::setEmail,
                label = { Text(text = "What's your email address?") },
                placeholder = { Text(text = "<mailto:jane.doe@gmail.com|jane.doe@gmail.com>") },
                keyboardType = KeyboardType.Email,
                modifier = frameFillWidth(60.dp).focusRequester(focusRequester),
                backgroundColor = MaterialTheme.colors.background,
                imeAction = ImeAction.Go,
                onImeActionPerformed = { action, keyboardState ->
                    submit()
                }
            )

            onActive(callback = {
                focusRequester.requestFocus()
            })
s

Siyamed

11/03/2020, 8:15 PM
Ime action and action performed is regression and fixed (for the next release)
I didn't hear about keyboard not showing up before
r

Robert Menke

11/03/2020, 8:16 PM
Seems to be specifically when I use the focus requester API
Updated my example to show how I’m using focus requester
s

Siyamed

11/03/2020, 8:17 PM
@Ralston Da Silva
r

Robert Menke

11/03/2020, 8:18 PM
If I comment out the
onActive
block I’m able to get the keyboard working but obviously don’t have automatic focus. The issue is also intermittent and seems to happen more frequently when I launch without updating (quicker start up time bc of cache)
r

Ralston Da Silva

11/03/2020, 8:47 PM
Thanks for reporting this Robert I tried to reproduce, but I don't see the issue. Does this work for you?
Copy code
@OptIn(ExperimentalFocus::class)
@Composable
fun TextFocusSample() {
    val focusRequester = FocusRequester()
    val textFieldValue = remember { mutableStateOf(TextFieldValue()) }
            TextField(
                value = textFieldValue.value,
                onValueChange = { textFieldValue.value = it },
                modifier = Modifier.focusRequester(focusRequester)
            )
    onActive { focusRequester.requestFocus() }
}
r

Robert Menke

11/03/2020, 9:32 PM
@Ralston Da Silva I added that component to and existing screen and recorded a sample reproducing the issue
Device is a pixel 2 on Android 10
s

steelahhh

11/04/2020, 5:11 AM
I’ve run into the same problem with BaseTextField and focusRequester. But I’m requesting focus with onClick of a container. Reproducing it isn’t really consistent - keyboard shows up 2 times out of 5, and only restarting the app sometimes works. I’m running Android 11
m

Mantas Varnagiris

11/04/2020, 7:43 AM
I've run into same issue on Pixel 2 XL. Also if keyboard is hidden, and text field has focus, if you tap on the text keyboard does not shop up, you need to tap on the padded area for keyboard to come up