首页 > 解决方案 > ListView 中的 TouchableOpacity 需要点击 2 次才能实现 onPress

问题描述

我有一个 TextInput,它将呈现一个 ListView 提示文本到 AutoComplete 但是 TouchableOpacity 需要 2 次点击才能触发(首先关闭键盘)

添加keyboardShouldPersistTaps="always"ListView不能解决问题。

代码:

render() {
    const { selected, searched } = this.state;
    return (
        <View>
            <TextInput
                onChangeText={this.searchedText}
                underlineColorAndroid="transparent"
                onBlur={this.blurInput}
            />
            <ListView
                keyboardShouldPersistTaps="handled"
                style={styles.autoCompleteListView}
                dataSource={ds.cloneWithRows(searched)}
                renderRow={this.renderRow.bind(this)}
            />
        </View>
    );
}

...

renderRow = (rowData) => (
    <TouchableOpacity
        onPress={this._onPressRow.bind(this, rowData)}
    >
        <Text>{ rowData }</Text>
    </TouchableOpacity>
);

标签: reactjsreact-native

解决方案


https://github.com/facebook/react-native/issues/10138#issuecomment-304344283

所有嵌套组件都需要该keyboardShouldPersistTaps属性


推荐阅读