I have a MyBasicTextField in a composable to request user input:
@Composable
fun MyBasicTextField() {
val keyboardController = LocalSoftwareKeyboardController.current
val focusRequester = remember{ FocusRequester() }
BasicTextField(
modifier = Modifier
.focusRequester(focusRequester),
keyboardActions = keyboardActions ?: KeyboardActions(onAny = { keyboardController?.hide() }),
)
LaunchedEffect(Unit) {
focusRequester.requestFocus()
}
}
The keyboard automatically slides in when showing this composable, always.
But wherever MyBasicTextField is used:
- I tap on a LinkifiedText to leave and open a browser to show link
- I tap BACK
- and come back to previous MyBasicTextField screen, the keyboard is not shown
- also the
focusRequester.requestFocus()is not triggered again when coming back
How can I solve my issue?
Create a top-level variable in your activity, then modify it from within the
onStartoverridden method. Use that variable as the key forLaunchedEffectin place of Unit. That variable basically keeps track of when the user enters the app.var userIn by mutableStateOf (true)In your Composable,
Boring,