julioromano
04/08/2021, 7:40 AMjulioromano
04/08/2021, 7:42 AMval keyboardController = LocalSoftwareKeyboardController.current
SideEffect {
keyboardController?.show()
}
This code doesn’t seem to make it happen.Filip Wiesner
04/08/2021, 7:45 AMSideEffect
is triggered for every recomposition so I would use either LaunchedEffect
or DisposableEffect
. Basically any effect with key. The reason this is not ideal is that doing something on the first render of composable is suspicious and probably should be done elsewhere like ViewModel. There were several discussions around this topic if I recall correctly.julioromano
04/08/2021, 7:48 AMval keyboardController = LocalSoftwareKeyboardController.current
DisposableEffect(null) {
keyboardController?.show()
onDispose {}
}
Doesn’t work eitherFilip Wiesner
04/08/2021, 7:49 AMjulioromano
04/08/2021, 7:49 AMNavHost
.Filip Wiesner
04/08/2021, 7:52 AMThe software keyboard will never show if there is no composable that will accept text input, such as a TextField when it is focused. You may find it useful to ensure focus when calling this function.
julioromano
04/08/2021, 7:52 AMjulioromano
04/08/2021, 7:52 AMTextField
in the screen on purposejulioromano
04/08/2021, 7:59 AMval focusRequester = FocusRequester()
DisposableEffect(null) {
focusRequester.requestFocus()
onDispose {}
}
var text by remember { mutableStateOf("") }
TextField(
value = text,
onValueChange = { text = it },
modifier = Modifier.focusRequester(focusRequester)
)
This did it 🤷Filip Wiesner
04/08/2021, 7:59 AMFilip Wiesner
04/08/2021, 8:00 AMjulioromano
04/08/2021, 8:00 AMFilip Wiesner
04/08/2021, 8:02 AMtextInputService.showSoftwareKeybord()
and it says:
Request showing onscreen keyboard.
This call will be ignored if there is not an open TextInputSession, as it means there is nothing that will accept typed input. The most common way to open a TextInputSession is to set the focus to an editable text composable.So you would need to focus the TextField anyway. This API seems to be for opening keyboard for components that can't do it themselves and we would have to focus them first.
Filip Wiesner
04/08/2021, 8:11 AMLocalSoftwareKeyboardController
was meant more for closing the keyboard rather than opening it 😄Adam Powell
04/08/2021, 1:19 PMSean McQuillan [G]
04/08/2021, 4:16 PMSean McQuillan [G]
04/08/2021, 4:17 PMSean McQuillan [G]
04/08/2021, 4:18 PMjulioromano
04/09/2021, 7:12 AMAndroidView
and run out of ideas. So I tried SoftwareKeyboardController
and FocusRequester
too (without success tho).
Ref: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1617831016388200Lucien Guimaraes
04/09/2021, 3:22 PMThe SoftwareKeyboardController only needs used if you've manually hidden it or are building your own textfield-like thing, focus on BasicTextField causes keybord hide/show as an intrinsic behavirorCan it be customized ? For example when user click somewhere else of the BasicTextField the focus is removed which dismiss the keyboard. In one of my use case, I would like to avoid this behaviour. Is it possible ?
Sean McQuillan [G]
04/09/2021, 4:26 PMSean McQuillan [G]
04/09/2021, 4:33 PMTextInputService
and it'll be automatically closed when the next TextField
gets focus.Lucien Guimaraes
04/09/2021, 4:40 PMSean McQuillan [G]
04/09/2021, 4:46 PMSean McQuillan [G]
04/09/2021, 4:46 PMLucien Guimaraes
04/09/2021, 4:54 PM