【发布时间】:2018-09-24 23:21:53
【问题描述】:
用户需要在FlatList 项目上单击两次,因为autoFocus={true} 是<TextInput。第一次单击键盘隐藏,然后单击调用onPress={this.GetItem.bind(this, item)}。是否有任何选项可以在第一次单击时调用 GetItem() 而不是单击两次。
演示:https://snack.expo.io/ByJ_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>
);
}
}
该组件的目的是当用户在<TextInput> 中搜索时在<FlatList> 中给出自动建议
【问题讨论】:
-
不完全是您正在寻找的答案,但是,keyboad events 对您有帮助吗?
-
@bennygenel 该组件的目的是当用户在
<TextInput>中搜索时,在<FlatList>中给出自动建议
标签: javascript reactjs react-native react-native-ios react-native-flatlist