mirror of
https://github.com/bitwarden/android.git
synced 2025-03-16 19:28:44 +03:00
[PM-10697] Auto-focus on PIN Dialog field (#3713)
This commit is contained in:
parent
b7a47eb91e
commit
2789b1cc37
3 changed files with 13 additions and 2 deletions
|
@ -7,11 +7,14 @@ import androidx.compose.material3.MaterialTheme
|
|||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
|
@ -61,10 +64,11 @@ fun BitwardenTextField(
|
|||
shouldAddCustomLineBreaks: Boolean = false,
|
||||
keyboardType: KeyboardType = KeyboardType.Text,
|
||||
isError: Boolean = false,
|
||||
autoFocus: Boolean = false,
|
||||
visualTransformation: VisualTransformation = VisualTransformation.None,
|
||||
) {
|
||||
var widthPx by remember { mutableIntStateOf(0) }
|
||||
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
val currentTextStyle = textStyle ?: LocalTextStyle.current
|
||||
val formattedText = if (shouldAddCustomLineBreaks) {
|
||||
value.withLineBreaksAtWidth(
|
||||
|
@ -78,7 +82,8 @@ fun BitwardenTextField(
|
|||
|
||||
OutlinedTextField(
|
||||
modifier = modifier
|
||||
.onGloballyPositioned { widthPx = it.size.width },
|
||||
.onGloballyPositioned { widthPx = it.size.width }
|
||||
.focusRequester(focusRequester),
|
||||
enabled = enabled,
|
||||
label = { Text(text = label) },
|
||||
value = formattedText,
|
||||
|
@ -113,6 +118,9 @@ fun BitwardenTextField(
|
|||
isError = isError,
|
||||
visualTransformation = visualTransformation,
|
||||
)
|
||||
if (autoFocus) {
|
||||
LaunchedEffect(Unit) { focusRequester.requestFocus() }
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
|
|
|
@ -108,6 +108,7 @@ fun PinInputDialog(
|
|||
BitwardenTextField(
|
||||
label = stringResource(id = R.string.pin),
|
||||
value = pin,
|
||||
autoFocus = true,
|
||||
onValueChange = { pin = it },
|
||||
keyboardType = KeyboardType.Number,
|
||||
modifier = Modifier
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.x8bit.bitwarden.ui.platform.feature.settings.accountsecurity
|
|||
|
||||
import androidx.compose.ui.test.assert
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.assertIsFocused
|
||||
import androidx.compose.ui.test.assertIsOff
|
||||
import androidx.compose.ui.test.assertIsOn
|
||||
import androidx.compose.ui.test.assertTextEquals
|
||||
|
@ -281,6 +282,7 @@ class AccountSecurityScreenTest : BaseComposeTest() {
|
|||
.onAllNodesWithText("PIN")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.assertIsDisplayed()
|
||||
.assertIsFocused()
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Cancel")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
|
|
Loading…
Add table
Reference in a new issue