Skip to content

Instantly share code, notes, and snippets.

@go-cristian
Created December 9, 2021 17:48
Show Gist options
  • Save go-cristian/acb1eb44670618b90e2f0b8a426b610f to your computer and use it in GitHub Desktop.
Save go-cristian/acb1eb44670618b90e2f0b8a426b610f to your computer and use it in GitHub Desktop.
@Composable
fun ExampleDialog() {
val scope = rememberCoroutineScope()
val keyboardController = LocalSoftwareKeyboardController.current
val focusRequester = remember { FocusRequester() }
val textState = remember { mutableStateOf(TextFieldValue()) }
LaunchedEffect(Unit) {
scope.launch {
delay(200)
focusRequester.requestFocus()
delay(200)
}
}
TextField(
value = textState.value,
onValueChange = {
textState.value = it
},
singleLine = true,
modifier = Modifier.focusRequester(focusRequester),
)
BaseButton(
text = "Click Me",
variant = Variant.PRIMARY,
onClick = {
scope.launch {
keyboardController?.hide()
textState.value = TextFieldValue()
}
},
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment