请检查小吃链接 https://snack.expo.io/@banid/textinput。
当我调用setState()更新TextInput的值时,筛选视图上的TextInput(按下按钮后显示)会隐藏键盘。由于这个问题,我不能在TextInput上连续输入。这是一个错误还是我的操作有误?谢谢。
<FlatList .... ListHeaderComponent={() => this.showHeader()} />
因此,它创建了一个新的TextInput而不是更新现有的TextInput。
解决方案:
将 ListHeaderComponent={() => this.showHeader()}
更改为 ListHeaderComponent={this.showHeader}
,因为ListHeaderComponent可以是一个函数。
https://facebook.github.io/react-native/docs/flatlist#listheadercomponent
类似的问题: https://github.com/react-native-training/react-native-elements/issues/559
看起来在每次setState之后,焦点都被从TextInput中移除了,这里有一个可以使用的解决方法:
更改
this.setState({
filterSearchText: text,
data: newData,
});
到
this.setState({
filterSearchText: text,
data: newData,
}, () => {
this.searchInput.focus();
});