Set focused state only on the digit.

This commit is contained in:
Benoit Marty
2026-07-02 13:38:25 +02:00
parent 4efc82fa74
commit 416da32c40
@@ -28,12 +28,11 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.focus.onFocusChanged import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import io.element.android.compound.theme.ElementTheme import io.element.android.compound.theme.ElementTheme
@@ -59,7 +58,9 @@ fun PinEntryTextField(
BasicTextField( BasicTextField(
modifier = modifier modifier = modifier
.onFocusChanged { isFocused = it.isFocused } .onFocusChanged { isFocused = it.isFocused }
.semantics { contentDescription = "$pinFieldLabel, $digitsEnteredLabel" }, .clearAndSetSemantics {
contentDescription = "$pinFieldLabel, $digitsEnteredLabel"
},
value = pinEntry.toText(), value = pinEntry.toText(),
onValueChange = { onValueChange = {
onValueChange(it) onValueChange(it)
@@ -76,19 +77,18 @@ fun PinEntryTextField(
private fun PinEntryRow( private fun PinEntryRow(
pinEntry: PinEntry, pinEntry: PinEntry,
isSecured: Boolean, isSecured: Boolean,
isFocused: Boolean = false, isFocused: Boolean,
) { ) {
FlowRow( FlowRow(
modifier = Modifier.border(
width = 2.dp,
color = if (isFocused) ElementTheme.colors.borderInteractiveHovered else Color.Transparent,
shape = RoundedCornerShape(8.dp),
),
horizontalArrangement = Arrangement.spacedBy(8.dp, alignment = Alignment.CenterHorizontally), horizontalArrangement = Arrangement.spacedBy(8.dp, alignment = Alignment.CenterHorizontally),
verticalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp),
) { ) {
for (digit in pinEntry.digits) { pinEntry.digits.forEachIndexed { index, digit ->
PinDigitView(digit = digit, isSecured = isSecured) PinDigitView(
digit = digit,
isSecured = isSecured,
isFocused = isFocused && index == pinEntry.digits.indexOfFirst { it is PinDigit.Empty }
)
} }
} }
} }
@@ -97,11 +97,16 @@ private fun PinEntryRow(
private fun PinDigitView( private fun PinDigitView(
digit: PinDigit, digit: PinDigit,
isSecured: Boolean, isSecured: Boolean,
isFocused: Boolean,
) { ) {
val shape = RoundedCornerShape(8.dp) val shape = RoundedCornerShape(8.dp)
val appearanceModifier = when (digit) { val appearanceModifier = when (digit) {
PinDigit.Empty -> { PinDigit.Empty -> {
Modifier.border(1.dp, ElementTheme.colors.iconPrimary, shape) if (isFocused) {
Modifier.border(2.dp, ElementTheme.colors.borderFocused, shape)
} else {
Modifier.border(1.dp, ElementTheme.colors.iconSecondary, shape)
}
} }
is PinDigit.Filled -> { is PinDigit.Filled -> {
Modifier.background(ElementTheme.colors.pinDigitBg, shape) Modifier.background(ElementTheme.colors.pinDigitBg, shape)