user2028
user2028

Reputation: 183

Double Tap Button issue when keyBoard opens React native

I know there are already so many queries on this topic, I have tried every step but still won't be able to fix the issue.

Here is the code :

    render() {
    const {sContainer, sSearchBar} = styles;

    if (this.props.InviteState.objectForDeleteList){
      this.updateList(this.props.InviteState.objectForDeleteList);
    }
    return (
      <View style={styles.mainContainer}>
        <CustomNavBar
          onBackPress={() => this.props.navigation.goBack()}
        />
        <View
          style={sContainer}
        >
          <ScrollView keyboardShouldPersistTaps="always">
            <TextInput
              underlineColorAndroid={'transparent'}
              placeholder={'Search'}
              placeholderTextColor={'white'}
              selectionColor={Color.colorPrimaryDark}
              style={sSearchBar}
              onChangeText={(searchTerm) => this.setState({searchTerm})}
            />
          </ScrollView>
          {this.renderInviteUserList()}
        </View>
      </View>
    );
  }

renderInviteUserList() {
    if (this.props.InviteState.inviteUsers.length > 0) {
      return (
        <SearchableFlatlist
          searchProperty={'fullName'}
          searchTerm={this.state.searchTerm}
          data={this.props.InviteState.inviteUsers}
          containerStyle={styles.listStyle}
          renderItem={({item}) => this.renderItem(item)}
          keyExtractor={(item) => item.id}
        />
      );
    }
    return (
      <View style={styles.emptyListContainer}>
        <Text style={styles.noUserFoundText}>
          {this.props.InviteState.noInviteUserFound}
        </Text>
      </View>
    );
  }


renderItem(item) {
    return (
      this.state.userData && this.state.userData.id !== item.id
        ?
        <TouchableOpacity
          style={styles.itemContainer}
          onPress={() => this.onSelectUser(item)}>
          <View style={styles.itemSubContainer}>
            <Avatar
              medium
              rounded
              source={
                item.imageUrl === ''
                  ? require('../../assets/user_image.png')
                  : {uri: item.imageUrl}
              }
              onPress={() => console.log('Works!')}
              activeOpacity={0.7}
            />
            <View style={styles.userNameContainer}>
              <Text style={styles.userNameText} numberOfLines={1}>
                {item.fullName}
              </Text>
            </View>
            <CustomButton
              style={{
                flexWrap: 'wrap',
                alignSelf: 'flex-end',
                marginTop: 10,
                marginBottom: 10,
                width: 90,
              }}
              showIcon={false}
              btnText={'Add'}
              onPress={() => this.onClickSendInvitation(item)}
            />
          </View>
        </TouchableOpacity> : null
    );

  }

**I even tried with bellow code as suggested by @Nirmalsinh **:

<ScrollView keyboardShouldPersistTaps="always" style={sContainer}>
        <CustomNavBar
          onBackPress={() => this.props.navigation.goBack()}
        />
        <TextInput underlineColorAndroid={'transparent'}
          placeholder={'Search'}
          placeholderTextColor={'white'}
          selectionColor={Color.colorPrimaryDark}
          style={sSearchBar}
          onChangeText={(searchTerm) => this.setState({searchTerm})} />
        {this.renderInviteUserList()}
      </ScrollView>

I have followed this article:

https://medium.com/react-native-training/todays-react-native-tip-keyboard-issues-in-scrollview-8cfbeb92995b

I have tried with keyboardShouldPersistTaps=handled also but still, I have to tap twice on my Custom Button to perform an action. Can anybody tell me what I am doing wrong inside the code?

Thanks.

Upvotes: 14

Views: 9637

Answers (3)

pramod J B
pramod J B

Reputation: 77

enter image description here

Please try this, It's working for me, it will works you also, i hope it helps...

Upvotes: 0

Haseeb A
Haseeb A

Reputation: 6122

You can use keyboardShouldPersistTaps='handled' in a ScrollView or Scrollables like FlatList SectionList etc. and embed a TouchableWithoutFeedBack to handle the case for dismiss on outside clicks.

<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
 <ScrollView keyboardShouldPersistTaps='handled'>
   // Rest of the content.
 </ScrollView/>
</TouchableWithoutFeedback>

For FlatList and SectionList you will have to handle KeyBoard.dismiss separately.

Upvotes: 13

Nirmalsinh Rathod
Nirmalsinh Rathod

Reputation: 5186

You need to add give value always in keyboardShouldPersistTaps to allow user tap without closing the keyboard.

keyboardShouldPersistTaps='always'

For example:

<ScrollView keyboardShouldPersistTaps='always'>
 // Put your component
</ScrollView>

NOTE: Kindly put your tappable component inside the ScrollView. Otherwise it won't work.

Upvotes: 11

Related Questions