|
1 | | -import { View, Text, TouchableOpacity, Image, TextInput } from 'react-native'; |
| 1 | +import { useState } from 'react'; |
| 2 | +import { View, Text, TouchableOpacity, Image } from 'react-native'; |
2 | 3 | import Gradient from '../assets/gradient.png'; |
3 | 4 | import OtpImage from '../assets/otp.png'; |
4 | 5 | import { NativeStackScreenProps } from '@react-navigation/native-stack'; |
5 | 6 | import { RootStackParamList } from '../navigation/navigator.types'; |
6 | 7 | import IonIcon from 'react-native-vector-icons/Ionicons'; |
7 | 8 | import { KeyboardAwareScrollView } from 'react-native-keyboard-controller'; |
| 9 | +import OtpInput from '../components/OtpInput'; |
8 | 10 |
|
9 | 11 | type OtpProps = NativeStackScreenProps<RootStackParamList, 'Otp'>; |
10 | 12 |
|
11 | 13 | const Otp = ({ navigation }: OtpProps) => { |
| 14 | + const [otpValue, setOtpValue] = useState<Array<string>>(['', '', '', '']); |
| 15 | + const [isBtnDisabled, setIsBtnDisabled] = useState(true); |
| 16 | + |
| 17 | + const handleOtpChange = (value: Array<string>) => { |
| 18 | + setOtpValue(value); |
| 19 | + |
| 20 | + const allFilled = value.every(v => v.length > 0); |
| 21 | + setIsBtnDisabled(!allFilled); |
| 22 | + }; |
| 23 | + |
12 | 24 | return ( |
13 | 25 | <KeyboardAwareScrollView |
14 | 26 | bottomOffset={100} |
@@ -36,17 +48,26 @@ const Otp = ({ navigation }: OtpProps) => { |
36 | 48 | <Text className="text-[#A3A3A3] text-center text-2xl font-medium mb-6 underline"> |
37 | 49 | RESEND? |
38 | 50 | </Text> |
39 | | - <TextInput |
| 51 | + {/* <TextInput |
40 | 52 | keyboardType="numeric" |
41 | 53 | placeholder="OTP" |
42 | 54 | placeholderTextColor={'#fff'} |
43 | 55 | // autoFocus={true} |
44 | 56 | className="w-full bg-[#262626] p-3 border border-[#F8D48D40] focus:border-[#F8D48D] rounded-lg text-[#FFF] text-base" |
| 57 | + /> */} |
| 58 | + <OtpInput |
| 59 | + length={4} |
| 60 | + value={otpValue} |
| 61 | + disabled={false} |
| 62 | + onChange={handleOtpChange} |
45 | 63 | /> |
46 | 64 | <TouchableOpacity |
47 | 65 | activeOpacity={0.8} |
48 | 66 | onPress={() => navigation.navigate('Name')} |
49 | | - className="bg-[#EDEAE2] rounded-lg py-3 mt-8" |
| 67 | + className={`bg-[#EDEAE2] rounded-lg py-3 mt-8 ${ |
| 68 | + isBtnDisabled ? 'opacity-60' : '' |
| 69 | + }`} |
| 70 | + disabled={isBtnDisabled} |
50 | 71 | > |
51 | 72 | <Text className="text-center text-[#0A0A0A] font-semibold text-base"> |
52 | 73 | Next |
|
0 commit comments