From 081a6374637fc3d34fe6f10c36d5e22df2ad01fc Mon Sep 17 00:00:00 2001 From: Salwa Aisyah Date: Sun, 27 Apr 2025 19:52:00 +0700 Subject: [PATCH] Add counter logic to Account Verification screen --- src/screens/accountVerification/index.tsx | 27 ++++++++++++++++++++-- src/screens/accountVerification/styles.tsx | 8 +++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/screens/accountVerification/index.tsx b/src/screens/accountVerification/index.tsx index 1af35f2..4c2f82c 100644 --- a/src/screens/accountVerification/index.tsx +++ b/src/screens/accountVerification/index.tsx @@ -25,8 +25,19 @@ function AccountVerificationScreen() { const navigation = useNavigation(); const [otp, setOtp] = useState(Array(6).fill('')); + const [counter, setCounter] = useState(10); const inputRefs = useRef([]); + useEffect(() => { + if (counter > 0) { + const timer = setTimeout(() => { + setCounter(counter - 1); + }, 1000); + + return () => clearTimeout(timer); + } + }, [counter]); + const handleChange = (text: string, index: number) => { const newOtp = [...otp]; newOtp[index] = text; @@ -87,10 +98,22 @@ function AccountVerificationScreen() { ))} - Kirim ulang kode OTP dalam 10 detik + Kirim ulang kode OTP dalam {counter} detik - Kirim Ulang Kode OTP + setCounter(10)} + style={({pressed}) => ({ + transform: [{scale: pressed ? 0.95 : 1}], + })}> + + Kirim Ulang Kode OTP + +