Skip to content

Commit 058136b

Browse files
committed
ui: Tweak PinCheck UI
1 parent 9692d92 commit 058136b

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

app/src/main/java/to/bitkit/ui/screens/wallets/send/PinCheckScreen.kt

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package to.bitkit.ui.screens.wallets.send
22

3+
import androidx.compose.animation.AnimatedVisibility
34
import androidx.compose.foundation.background
45
import androidx.compose.foundation.layout.Column
56
import androidx.compose.foundation.layout.Spacer
@@ -57,19 +58,27 @@ fun PinCheckScreen(
5758
PinCheckContent(
5859
pin = pin,
5960
attemptsRemaining = attemptsRemaining,
60-
onPinChange = { pin = it },
61+
onKeyPress = { key ->
62+
if (key == KEY_DELETE) {
63+
if (pin.isNotEmpty()) {
64+
pin = pin.dropLast(1)
65+
}
66+
} else if (pin.length < Env.PIN_LENGTH) {
67+
pin += key
68+
}
69+
},
6170
onBack = onBack,
62-
onForgotPin = { app.setShowForgotPin(true) },
71+
onClickForgotPin = { app.setShowForgotPin(true) },
6372
)
6473
}
6574

6675
@Composable
6776
private fun PinCheckContent(
6877
pin: String,
6978
attemptsRemaining: Int,
70-
onPinChange: (String) -> Unit,
79+
onKeyPress: (String) -> Unit,
7180
onBack: () -> Unit,
72-
onForgotPin: () -> Unit,
81+
onClickForgotPin: () -> Unit,
7382
) {
7483
val isLastAttempt = attemptsRemaining == 1
7584

@@ -96,7 +105,7 @@ private fun PinCheckContent(
96105

97106
Spacer(modifier = Modifier.height(32.dp))
98107

99-
if (attemptsRemaining < Env.PIN_ATTEMPTS) {
108+
AnimatedVisibility(visible = attemptsRemaining < Env.PIN_ATTEMPTS) {
100109
if (isLastAttempt) {
101110
BodyS(
102111
text = stringResource(R.string.security__pin_last_attempt),
@@ -112,7 +121,7 @@ private fun PinCheckContent(
112121
textAlign = TextAlign.Center,
113122
modifier = Modifier
114123
.padding(horizontal = 32.dp)
115-
.clickableAlpha { onForgotPin() }
124+
.clickableAlpha { onClickForgotPin() }
116125
)
117126
}
118127
Spacer(modifier = Modifier.height(16.dp))
@@ -126,14 +135,7 @@ private fun PinCheckContent(
126135
Spacer(modifier = Modifier.weight(1f))
127136

128137
PinNumberPad(
129-
onPress = { key ->
130-
val newPin = when {
131-
key == KEY_DELETE && pin.isNotEmpty() -> pin.dropLast(1)
132-
key != KEY_DELETE && pin.length < Env.PIN_LENGTH -> pin + key
133-
else -> pin
134-
}
135-
onPinChange(newPin)
136-
},
138+
onPress = onKeyPress,
137139
modifier = Modifier
138140
.height(350.dp)
139141
.background(Colors.Black)
@@ -149,9 +151,9 @@ private fun Preview() {
149151
PinCheckContent(
150152
pin = "123",
151153
attemptsRemaining = 8,
152-
onPinChange = {},
154+
onKeyPress = {},
153155
onBack = {},
154-
onForgotPin = {},
156+
onClickForgotPin = {},
155157
)
156158
}
157159
}
@@ -163,9 +165,9 @@ private fun PreviewAttempts() {
163165
PinCheckContent(
164166
pin = "123",
165167
attemptsRemaining = 3,
166-
onPinChange = {},
168+
onKeyPress = {},
167169
onBack = {},
168-
onForgotPin = {},
170+
onClickForgotPin = {},
169171
)
170172
}
171173
}
@@ -177,9 +179,9 @@ private fun PreviewAttemptsLast() {
177179
PinCheckContent(
178180
pin = "123",
179181
attemptsRemaining = 1,
180-
onPinChange = {},
182+
onKeyPress = {},
181183
onBack = {},
182-
onForgotPin = {},
184+
onClickForgotPin = {},
183185
)
184186
}
185187
}

0 commit comments

Comments
 (0)