Clear keyboard focus once inputs are done
This commit is contained in:
parent
e8624b5635
commit
f8fcf8b642
|
@ -4,11 +4,13 @@ import android.os.Bundle
|
|||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
|
@ -45,6 +47,8 @@ fun isLoginCodeValid(code: String): Boolean = code.trim().count { it.isDigit() }
|
|||
|
||||
@Composable
|
||||
fun PhoneInput(phone: String, onPhoneChanged: (String) -> Unit, onSendCode: () -> Unit) {
|
||||
val focusManager = LocalFocusManager.current
|
||||
|
||||
Text(stringResource(R.string.enter_phone))
|
||||
TextField(
|
||||
phone,
|
||||
|
@ -55,6 +59,7 @@ fun PhoneInput(phone: String, onPhoneChanged: (String) -> Unit, onSendCode: () -
|
|||
keyboardType = KeyboardType.Phone,
|
||||
imeAction = ImeAction.Done
|
||||
),
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
onValueChange = onPhoneChanged
|
||||
)
|
||||
|
@ -70,6 +75,8 @@ fun PhoneInput(phone: String, onPhoneChanged: (String) -> Unit, onSendCode: () -
|
|||
|
||||
@Composable
|
||||
fun OtpInput(otp: String, onOtpChanged: (String) -> Unit, onConfirmOtp: () -> Unit) {
|
||||
val focusManager = LocalFocusManager.current
|
||||
|
||||
Text(stringResource(R.string.enter_otp))
|
||||
TextField(
|
||||
otp,
|
||||
|
@ -80,6 +87,7 @@ fun OtpInput(otp: String, onOtpChanged: (String) -> Unit, onConfirmOtp: () -> Un
|
|||
keyboardType = KeyboardType.Number,
|
||||
imeAction = ImeAction.Done
|
||||
),
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
onValueChange = onOtpChanged
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue