PinEntryTextField : add isSecured parameter

This commit is contained in:
ganfra 2023-10-24 11:30:43 +02:00
parent 6ee1c2eb4c
commit 3733ee7e80
2 changed files with 14 additions and 5 deletions

View file

@ -30,7 +30,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import io.element.android.features.lockscreen.impl.pin.model.PinDigit import io.element.android.features.lockscreen.impl.pin.model.PinDigit
import io.element.android.features.lockscreen.impl.pin.model.PinEntry import io.element.android.features.lockscreen.impl.pin.model.PinEntry
@ -42,6 +41,7 @@ import io.element.android.libraries.theme.ElementTheme
@Composable @Composable
fun PinEntryTextField( fun PinEntryTextField(
pinEntry: PinEntry, pinEntry: PinEntry,
isSecured: Boolean,
onValueChange: (String) -> Unit, onValueChange: (String) -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
@ -53,7 +53,7 @@ fun PinEntryTextField(
}, },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.NumberPassword), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.NumberPassword),
decorationBox = { decorationBox = {
PinEntryRow(pinEntry = pinEntry) PinEntryRow(pinEntry = pinEntry, isSecured = isSecured)
} }
) )
} }
@ -61,6 +61,7 @@ fun PinEntryTextField(
@Composable @Composable
private fun PinEntryRow( private fun PinEntryRow(
pinEntry: PinEntry, pinEntry: PinEntry,
isSecured: Boolean,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
Row( Row(
@ -69,7 +70,7 @@ private fun PinEntryRow(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
) { ) {
for (digit in pinEntry.digits) { for (digit in pinEntry.digits) {
PinDigitView(digit = digit) PinDigitView(digit = digit, isSecured = isSecured)
} }
} }
} }
@ -77,6 +78,7 @@ private fun PinEntryRow(
@Composable @Composable
private fun PinDigitView( private fun PinDigitView(
digit: PinDigit, digit: PinDigit,
isSecured: Boolean,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
val shape = RoundedCornerShape(8.dp) val shape = RoundedCornerShape(8.dp)
@ -96,8 +98,13 @@ private fun PinDigitView(
) { ) {
if (digit is PinDigit.Filled) { if (digit is PinDigit.Filled) {
val text = if(isSecured) {
""
} else {
digit.value.toString()
}
Text( Text(
text = digit.toText(), text = text,
style = ElementTheme.typography.fontHeadingMdBold style = ElementTheme.typography.fontHeadingMdBold
) )
} }
@ -111,6 +118,7 @@ internal fun PinEntryTextFieldPreview() {
ElementPreview { ElementPreview {
PinEntryTextField( PinEntryTextField(
pinEntry = PinEntry.createEmpty(4).fillWith("12"), pinEntry = PinEntry.createEmpty(4).fillWith("12"),
isSecured = true,
onValueChange = {}, onValueChange = {},
) )
} }

View file

@ -114,7 +114,8 @@ private fun SetupPinContent(
focusRequester.requestFocus() focusRequester.requestFocus()
} }
PinEntryTextField( PinEntryTextField(
state.activePinEntry, pinEntry = state.activePinEntry,
isSecured = true,
onValueChange = { onValueChange = {
state.eventSink(SetupPinEvents.OnPinEntryChanged(it)) state.eventSink(SetupPinEvents.OnPinEntryChanged(it))
}, },