From fca48046fc8b2c2d9ba05a6c693ecd2043d75407 Mon Sep 17 00:00:00 2001 From: eranl <1707552+eranl@users.noreply.github.com> Date: Mon, 27 Oct 2025 03:04:35 +0200 Subject: [PATCH] Fix `TextInputDialog` focus on launch --- .../keyboard/settings/dialogs/TextInputDialog.kt | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/settings/dialogs/TextInputDialog.kt b/app/src/main/java/helium314/keyboard/settings/dialogs/TextInputDialog.kt index fa9b8a105..947a4c6ae 100644 --- a/app/src/main/java/helium314/keyboard/settings/dialogs/TextInputDialog.kt +++ b/app/src/main/java/helium314/keyboard/settings/dialogs/TextInputDialog.kt @@ -44,17 +44,6 @@ fun TextInputDialog( reducePadding: Boolean = false, checkTextValid: (text: String) -> Boolean = { it.isNotBlank() } ) { - val focusRequester = remember { FocusRequester() } - // crappy workaround because otherwise we get a disappearing dialog and a crash - // but doesn't work perfectly, dialog doesn't nicely show up again... - // todo: understand why it works in ExpandableSearchField, but not here - var done by rememberSaveable { mutableStateOf(false) } - LaunchedEffect(initialText) { - if (done) return@LaunchedEffect - focusRequester.requestFocus() - done = true - } - var value by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue(initialText, selection = TextRange(if (singleLine) initialText.length else 0))) } @@ -69,6 +58,7 @@ fun TextInputDialog( modifier = modifier, title = title, content = { + val focusRequester = remember { FocusRequester() } OutlinedTextField( value = value, onValueChange = { value = it }, @@ -80,6 +70,7 @@ fun TextInputDialog( singleLine = singleLine, textStyle = contentTextDirectionStyle, ) + LaunchedEffect(Unit) { focusRequester.requestFocus() } }, properties = properties, reducePadding = reducePadding,