tttstudios / react-native-otp-input

Tiny Javascript library which provides an elegant UI for user to input one time passcode.
MIT License
530 stars 239 forks source link

onCodeFilled is not triggered when automatically filling the code. #102

Open edwardigates opened 3 years ago

edwardigates commented 3 years ago

Describe the bug A clear and concise description of what the bug is. I use this library to extract the code from the sms. I also use useState hook to save the otp, and I use the otp as a value for OTPInputView like that:

<OTPInputView   pinCount={6}
                                code = {otp}
                                onCodeChanged = { (code:string) => console.log("new code" + code)}
                                onCodeFilled = {((code:string) => {
                                    console.log(`Code is ${code}, you are good to go!`)
                                    doLogin(code)
                                })}/>

After updating, the otp value, I see that the code is filled in the input view, but neither onCodeChanged nor onCodeFilled are called. If however I enter the code manually everything work as expected.

I tested that on Andorid 10 and Android 8.1.0 in both case it was the same behavior

eric-dao37 commented 3 years ago

Hi @edwardigates,

We have tested on both Andorid 10 and Android 8, onCodeChanged and onCodeFilled are working as expected.

edwardigates commented 3 years ago

Hi @ericdao-ttt I tried to fill the code using useEffect but still the onCodeFilled is not triggered, am I missing something with my configs?

    const [otp, setOtp] = React.useState<string>('')
    React.useEffect(() => {

            setTimeout( () => setOtp('111111') , 5000)

    }, [])

<OTPInputView      
                                        pinCount={6}
                                        code = {otp}
                                        editable={true}
                                        autoFocusOnLoad={false}
                                        onCodeChanged = { (code:string) => console.log("new code" + code)}
                                        onCodeFilled = {((code:string) => {
                                            console.log(`Code is ${code}, you are good to go!`)
                                            doLogin(code)
                                        })}         
eric-dao37 commented 3 years ago

Hi @edwardigates

Can you try to add the ref for the OTPInputView and call ref.current.notifyCodeChanged() in useEffect

imavipatel commented 3 years ago

Describe the bug A clear and concise description of what the bug is. I use this library to extract the code from the sms. I also use useState hook to save the otp, and I use the otp as a value for OTPInputView like that:

<OTPInputView   pinCount={6}
                                code = {otp}
                                onCodeChanged = { (code:string) => console.log("new code" + code)}
                                onCodeFilled = {((code:string) => {
                                    console.log(`Code is ${code}, you are good to go!`)
                                    doLogin(code)
                                })}/>

After updating, the otp value, I see that the code is filled in the input view, but neither onCodeChanged nor onCodeFilled are called. If however I enter the code manually everything work as expected.

I tested that on Andorid 10 and Android 8.1.0 in both case it was the same behavior

i have the same problem did you find the solution? any way to workout this Please help?

venomkage commented 2 years ago

I have noticed that only one digit is being left to insert while auto-updating the fields. If you write even 1 digit after auto-filling it works. I don't know why is it happening but let's see what happend.