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

AutoFocusOnLoad is not working #122

Open selva21kd opened 3 years ago

selva21kd commented 3 years ago

AutoFocusOnLoad is not working, it is just open the keypad but not focusing on the first text input field.

To Reproduce Steps to reproduce the behavior:

  1. <OTPInput style={styles.otpContainer} pinCount={6} autoFocusOnLoad={true} codeInputFieldStyle={styles.underlineStyleBase} codeInputHighlightStyle={styles.underlineStyleHighLighted} onCodeFilled={(code) => { console.log(code }} />

Expected behavior when loading into new screen it should open keypad and focus on the first text input field.

Screenshots

Smartphone (please complete the following information): All Devices Screenshot_2021-03-15-13-04-01-11

Additional context Add any other context about the problem here.

Raunak-Agrawal commented 3 years ago

Hi guys. I am able to solve it.

The way which I implemented is: Copy the code ( basically source index.ts and helper files which it uses ) and then we need to either convert the code to use functional component or else edit this line here inside componentDidMount

setTimeout(() => this.bringUpKeyBoardIfNeeded(), 250);

For anyone looking up for explanation: https://stackoverflow.com/questions/46715378/react-native-textinput-does-not-get-focus

Either we can contribute the same change for which it needs to get it approved :D but this should do it for now :)

Vrishabhsk commented 2 years ago

is this issue fixed yet?

rizwan92 commented 2 years ago

when this get fixed ??

vikasatappinlay commented 2 years ago

i got the solution from this link

Here is how you can easily disconnect your hardware key board. Now when you will focus inside textInput area, it will open the keypad of iOS simulator

PndvX

https://stackoverflow.com/questions/34977588/input-text-doesnt-show-keyboard-on-ios-simulator

vikasatappinlay commented 2 years ago

when this get fixed ??

this not the issue of library have a look on my given solution.

mokshmodi96 commented 2 years ago

Anyone else facing the same issue download the package from my forked repo. @Raunak-Agrawal 's fix is implemented into the code

Rubiojen commented 2 years ago

A working workarount:

in previous screen:

Keyboard.dismiss(); await wait(250); navigateToOtop()

const wait = (delay: number): Promise => new Promise(res => setTimeout(res, delay));

Villa2311 commented 1 year ago

Solution:

const OTPContainer = () => { const otpRef = useRef(null);

useEffect(() => { setTimeout(() => otpRef.current.focusField(0), 250); }, []);

return <OTPInputView ref={otpRef} autoFocusOnLoad={false} ... /> }

timothyerwin commented 1 year ago

this is actually covered in one of the closed tickets...you need to call Keyboard.dismiss() before showing the otp screen.