React Native two time taps required for onPress event inside scrollview

Viewed 1347

I'm using TextInput inside ScrollView and KeyboardAvoidingView but it require two time taps for submit text when keyboard is open.
for soluation i'm add keyboardShouldPersistTaps="always" but it not working.

render() {
    return (
        <View style={{flex: 1}}>
            <KeyboardAvoidingView style={{flex:1}}>
            <ScrollView keyboardShouldPersistTaps="always" 
                contentContainerStyle={{
                    paddingHorizontal: 10,
                    flexGrow : 1,
                    justifyContent : 'center',
                    alignItems:'center'}}>
                <View style={{backgroundColor:'green', width:'100%', borderRadius:8, overflow:'hidden'}}>
                    <TextInput style={{margin:10}}/>
                    <TouchableOpacity onPress={() => {alert('alert')}}>
                        <Text>Submit</Text>
                    </TouchableOpacity>
                </View>
            </ScrollView>
            </KeyboardAvoidingView>
        </View>
    )
}

How to fire on press event on single tap?

2 Answers

Use "handled" instead of "always". keyboardShouldPersistTaps="handled"

You have to write a onPress method of TouchableOpacity component something like this

 <TouchableOpacity
onPress={() => alert('Clicked)}>
      <Text>Submit</Text>
 </TouchableOpacity>
Related