用户需要在FlatList项上单击两次,因为autoFocus={true}用于<TextInput。在第一次单击时,键盘正在隐藏,然后单击调用onPress={this.GetItem.bind(this, item)}。是否有任何选项可以在第一次单击时调用GetItem()而不是单击两次。
演示:yWehM
export default class App extends Component {
GetItem (item) {
console.log(item);
Alert.alert(item);
}
render() {
return (
<View style={styles.container}>
<TextInput
autoFocus={true}
style={styles.paragraph}
keyboardType='web-search'
>
Change code in the editor and watch it change on your phone!
Save to get a shareable url.
</TextInput>
<Card title="Local Modules">
<View>
<TextInput
style={styles.searchField}
placeholder="Type here to translate!"
onChangeText={(text) => this.setState({text})}
/>
<FlatList
data={["akin","alike","close","comparable","like","similar","uniform","Allied","Analogous","Co-ordinate","Commensurate","akin","alike","close","comparable","like","similar","uniform","Allied","Analogous","Co-ordinate","Commensurate"]}
renderItem={({item}) => (
<Text
style={styles.listField}
onPress={this.GetItem.bind(this, item)}
>{item}</Text>
)}
/>
</View>
</Card>
</View>
);
}
}该组件的目的是在<FlatList>中用户搜索时给出<TextInput>中的自动建议。
发布于 2018-04-14 22:25:52
将keyboardShouldPersistTaps='handled'添加到FlatList中将防止键盘被排除onPress。
<FlatList
keyboardShouldPersistTaps='handled'
data={["akin","alike","close","comparable","like","similar","uniform","Allied","Analogous","Co-ordinate","Commensurate","akin","alike","close","comparable","like","similar","uniform","Allied","Analogous","Co-ordinate","Commensurate"]}
renderItem={({item}) => (
<Text
onPress={this.GetItem.bind(this, item)}
>{item}</Text>
)}
/>always也用作keyboardShouldPersistTaps值。
https://stackoverflow.com/questions/49836648
复制相似问题