Clear focus when submitting forms to prevent issues with the IME keyboard. (#139)

This commit is contained in:
Jorge Martin Espinosa
2023-03-08 15:30:40 +01:00
committed by GitHub
parent c718c9b737
commit 0c8d8b62f8
3 changed files with 21 additions and 4 deletions

1
changelog.d/133.bugfix Normal file
View File

@@ -0,0 +1 @@
Clear focus on TextFields when submitting forms to prevent issues with the IME keyboard.

View File

@@ -92,6 +92,14 @@ fun ChangeServerView(
}
}
val focusManager = LocalFocusManager.current
fun submit() {
// Clear focus to prevent keyboard issues with textfields
focusManager.clearFocus(force = true)
eventSink(ChangeServerEvents.Submit)
}
Scaffold(
topBar = {
TopAppBar(
@@ -175,7 +183,7 @@ fun ChangeServerView(
imeAction = ImeAction.Done,
),
keyboardActions = KeyboardActions(
onDone = { eventSink(ChangeServerEvents.Submit) }
onDone = { submit() }
),
singleLine = true,
maxLines = 1,
@@ -216,7 +224,7 @@ fun ChangeServerView(
)
Spacer(Modifier.height(32.dp))
Button(
onClick = { eventSink(ChangeServerEvents.Submit) },
onClick = ::submit,
enabled = interactionEnabled && state.submitEnabled,
modifier = Modifier
.fillMaxWidth()

View File

@@ -223,6 +223,14 @@ internal fun LoginForm(
val focusManager = LocalFocusManager.current
val eventSink = state.eventSink
fun submit() {
// Clear focus to prevent keyboard issues with textfields
focusManager.clearFocus(force = true)
eventSink(LoginRootEvents.Submit)
}
Column(modifier) {
Text(
text = stringResource(StringR.string.login_form_title),
@@ -301,7 +309,7 @@ internal fun LoginForm(
imeAction = ImeAction.Done,
),
keyboardActions = KeyboardActions(
onDone = { eventSink(LoginRootEvents.Submit) }
onDone = { submit() }
),
singleLine = true,
maxLines = 1,
@@ -310,7 +318,7 @@ internal fun LoginForm(
// Submit
Button(
onClick = { eventSink(LoginRootEvents.Submit) },
onClick = ::submit,
enabled = interactionEnabled && state.submitEnabled,
modifier = Modifier
.fillMaxWidth()