Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shift to next text input field without closing keyboard in react-native

I have 6 text input fields and when i click on any text input field, firstly the text input field closes and I have to again click on the same input field to open it again

Is there a way to switch to next input field without using the returnKeyType="next" so that when I just switch to any input field, the keyboard remains opened.

here is my text input field code:

<View style={styles.inputContainer}>
              <TextInput
                ref='fname'
                autoCorrect={false}
                placeholder="First Name"
                style={styles.textInput}
                placeholderTextColor='#848484'
                autoCapitalize='words'
                maxLength={20}
                onFocus={()=>context._handleScrollView(ReactNative.findNodeHandle(context.refs.fname))}
                onBlur={()=>context._resetScrollView(ReactNative.findNodeHandle(context.refs.fname))}
                onChangeText={(fname) => context.setState({fname: fname.capitalizeFirstLetter()})} />
            </View>

What property or some method or function should i add to overcome this problem?

like image 529
Ankush Rishi Avatar asked Feb 05 '23 13:02

Ankush Rishi


2 Answers

You are probably inside a scroll. You need to add keyboardShouldPersistTaps to the ScrollView component:

When false, tapping outside of the focused text input when the keyboard is up dismisses the keyboard. When true, the keyboard will not dismiss automatically, and the scroll view will not catch taps, but children of the scroll view can catch taps. The default value is false.

<ScrollView
    keyboardShouldPersistTaps
    ...
>
like image 66
atlanteh Avatar answered Feb 11 '23 00:02

atlanteh


As of react-native 0.40 the right way is keyboardShouldPersistTaps='always', keyboardShouldPersistTaps or keyboardShouldPersistTaps=true is deprecated.

See more here

like image 22
U Rogel Avatar answered Feb 10 '23 23:02

U Rogel