From 88ef0a703efffa42654a12dec34ac57dd3aa2322 Mon Sep 17 00:00:00 2001 From: dankito Date: Wed, 4 Sep 2024 21:37:50 +0200 Subject: [PATCH] Focussing amount TextField after selecting a recipient from dropdown --- .../banking/ui/dialogs/TransferMoneyDialog.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/TransferMoneyDialog.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/TransferMoneyDialog.kt index 693bb58..08bd2e9 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/TransferMoneyDialog.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/TransferMoneyDialog.kt @@ -7,14 +7,14 @@ import androidx.compose.material.* import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext +import kotlinx.coroutines.* import net.codinux.banking.client.model.Amount import net.codinux.banking.client.model.BankAccountFeatures import net.codinux.banking.ui.IOorDefault @@ -71,6 +71,8 @@ fun TransferMoneyDialog( var isTransferringMoney by remember { mutableStateOf(false) } + val amountFocus = remember { FocusRequester() } + val verticalSpace = 8.dp val coroutineScope = rememberCoroutineScope() @@ -139,6 +141,11 @@ fun TransferMoneyDialog( recipientName = it.name recipientAccountIdentifier = it.accountIdentifier // TODO: set recipient bank identifier + + coroutineScope.launch { + delay(250) + amountFocus.requestFocus() + } } else { recipientName = "" recipientAccountIdentifier = "" @@ -177,7 +184,7 @@ fun TransferMoneyDialog( value = amount, onValueChange = { amount = it }, label = { Text("Betrag") }, - modifier = Modifier.fillMaxWidth(), + modifier = Modifier.fillMaxWidth().focusRequester(amountFocus), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal, imeAction = ImeAction.Next) )