react-native-forms icon indicating copy to clipboard operation
react-native-forms copied to clipboard

Focus input onSubmitEditing

Open svenadlung opened this issue 7 years ago • 1 comments

Thank you for this nice library! Really appreciate your work!

I was wondering how to focus another text input on pressing "Next" in the keyboard. Usually I used to give the first input a prop like onSubmitEditing={() => this.refs.input2.focus()} which focuses the input with the ref input2. This doesn't seem to work in this case.

Neither I use <TextInputCell ref="input2"

nor defining a ref in the inputProps. inputProps={{ ref: 'input2',

Any suggestions?

svenadlung avatar May 23 '17 08:05 svenadlung

Thanks so much for your interest!

I actually don't think that's currently possible because of how the library wraps the native components (like TextInput) with React.cloneElement. It's definitely a fault in the library. In order to support this, I believe the library would have to maintain an internal reference to the native TextInput component with a callback ref when React.cloneElement is called here and then manually implement component methods like focus. As it stands, the ref is overwritten.

Unfortunately I don't really have time time to work on this library anymore. I wrote it a number of months ago for a use case at work, and open sourced it in the general spirit of sharing code that had proved useful to me. Now it's pretty dated (for example, in the way that it uses string refs which are deprecated by React) and I think there's probably some much better UI libraries out there with form elements included (for example, this library: https://react-native-training.github.io/react-native-elements/). I'm going to update the README so that folks know the status of the project.

Thanks again! I'm sorry I couldn't be of more help.

michaelhelvey avatar May 23 '17 13:05 michaelhelvey