ListView中的TouchableOpacity需要两次点击onPress

时间:2019-02-14 16:27:16

标签: reactjs react-native

我有一个TextInput,它将呈现一个ListView提示文本以自动完成,但是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>
);

1 个答案:

答案 0 :(得分:2)

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

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