我正在使用React Native和Native Base库.当键盘打开时,我需要一个onPress事件在Native Base的ListItem(相当于TouchableOpacity)上触发.

现在,我必须单击一次以关闭键盘,然后才能按ListItem.

下面的内容标签相当于ScrollableView:

<Content keyboardShouldPersistTaps='always' keyboardDismissMode='on-drag'>
  <List>
    <ListItem style={styles.inspectionsItemDivider} itemDivider>
      <TextInput
        autoFocus={true}
        ref={(input) => { this.titleSearch = input }}
        placeholder='Start typing...'
        multiline={true}
        onChangeText={this.setSearchText.bind(this)}
        value={this.getSearchValue()}/>
    </ListItem>
    <View style={styles.searchContainer}>
      <Text style={styles.recentText}>Recommended Descriptions</Text>
      <List dataArray={this.state.searchedDescriptions} 
        renderRow={(description) =>
        <ListItem button onPress={() => this.setInformationDescription(description)}>
          <Text>{description}</Text>
        </ListItem>
      </List>
    </View>
  </List>
</Content>

推荐答案

事实上,我刚刚发现了这一点.除了内容标签之外,我还在列表中添加了keyboardShouldPersistTaps='always'props :

<Content keyboardShouldPersistTaps='always' keyboardDismissMode='on-drag'>
  <List>
    <ListItem style={styles.inspectionsItemDivider} itemDivider>
      <TextInput
        autoFocus={true}
        ref={(input) => { this.titleSearch = input }}
        placeholder='Start typing...'
        multiline={true}
        onChangeText={this.setSearchText.bind(this)}
        value={this.getSearchValue()}/>
    </ListItem>
    <View style={styles.searchContainer}>
      <Text style={styles.recentText}>Recommended Descriptions</Text>
      <List keyboardShouldPersistTaps='always' dataArray={this.state.searchedDescriptions} 
        renderRow={(description) =>
        <ListItem button onPress={() => this.setInformationDescription(description)}>
          <Text>{description}</Text>
        </ListItem>
      </List>
    </View>
  </List>
</Content>

React-native相关问答推荐

'无法解析模块.安装react-native-pager-view后的实用程序/平台

React native React native下拉 Select 器下拉列表不透明问题

用图像 react native 动画进度条

ReactNative:在所有组件和操作之间共享 sqlite 实例的最佳方法

react-navigation中的React-native android后退按钮

redux-observable 您在预期流的地方提供了 undefined

如何在react-native android中打开应用程序设置页面?

用于部署后设置的 React 配置文件

如何清除react-native webview cookie?

Undefined 不是判断 this.state.* 的对象

如何判断 goBack() 函数在react-navigation 中是否可行?

在 UIManager 中找不到RNCSafeAreaView

React Native Navigation 组件路由问题

在 React Native 中使用小数

在 `../node_modules/react-native/React` 中找不到 `React-Core` 的 podspec

ExpoKit 和 React Native 元素的区别

将 setState 与 promise 一起使用后出现错误

在 componentWillUnmount 中清除超时的更好方法

React-Native 元素卡在 :app:installDebug

React Context:TypeError:render is not a function