fixed some ui
This commit is contained in:
@@ -97,6 +97,30 @@ export default function OtpVerificationScreen() {
|
||||
});
|
||||
|
||||
const handleTextChange = (text: string, index: number) => {
|
||||
// If text length > 1, it's likely a paste operation
|
||||
if (text.length > 1) {
|
||||
const pastedCode = text.trim().slice(0, CELL_COUNT).split('');
|
||||
const newCode = [...code];
|
||||
|
||||
pastedCode.forEach((char, i) => {
|
||||
if (i < CELL_COUNT) {
|
||||
newCode[i] = char;
|
||||
}
|
||||
});
|
||||
|
||||
setCode(newCode);
|
||||
|
||||
// Focus the last filled cell or the next empty one
|
||||
const focusIndex = Math.min(pastedCode.length, CELL_COUNT - 1);
|
||||
inputs.current[focusIndex]?.focus();
|
||||
|
||||
// Trigger verification if OTP complete
|
||||
if (newCode.every((cell) => cell !== '')) {
|
||||
verifyOtp({ mobile, otp: newCode.join('') });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const newCode = [...code];
|
||||
newCode[index] = text.slice(-1);
|
||||
setCode(newCode);
|
||||
@@ -153,13 +177,14 @@ export default function OtpVerificationScreen() {
|
||||
},
|
||||
]}
|
||||
keyboardType="number-pad"
|
||||
maxLength={1}
|
||||
maxLength={CELL_COUNT}
|
||||
value={digit}
|
||||
placeholder="0"
|
||||
placeholderTextColor={theme.colors.textMuted}
|
||||
onChangeText={(text) => handleTextChange(text, index)}
|
||||
onKeyPress={(e) => handleKeyPress(e, index)}
|
||||
selectionColor={theme.colors.primary}
|
||||
textContentType="oneTimeCode"
|
||||
/>
|
||||
))}
|
||||
</View>
|
||||
|
||||
Reference in New Issue
Block a user