我正在使用 React Native 并在 Android 上进行测试。我已将 onKeyPress 添加到我的 TextInput 中,但我在模拟器中单击键盘并没有触发它(是的,我使用鼠标单击按键)。有谁知道如何让 onKeyPress 工作或知道另一种方法来检测 Android 键盘上的 Enter(完成)键上的按键?
它甚至从未进入它应该调用的函数(searchProducts)。
searchProducts = () => {
if (e.nativeEvent.key == "Enter"){
this.props.searchFunc(this.state.term);
}
}
searchSuggestions = searchTerm => {
if (this.timeoutId)
clearTimeout(this.timeoutId);
this.timeoutId = setTimeout(() => this.props.autofillFunc(searchTerm), 500);
this.setState({
term: searchTerm
});
}
componentDidMount() {
if (this.props.autoFocus) {
this.refs.searchBar.focus();
}
}
render() {
const {placeholder} = this.props;
const autoFocus = this.props.autoFocus;
return (
<View style={styles.searchBar}>
<TouchableHighlight style={{width: '100%'}}>
<View style={styles.searchBar}>
<MBIcon name='ico-24-search' style={styles.searchIcon} />
<TextInput
ref='searchBar'
style={styles.searchInput}
placeholder={placeholder}
onChangeText={this.searchSuggestions}
onKeyPress={this.searchProducts.bind(this)}
underlineColorAndroid="transparent"
/>
</View>
</TouchableHighlight>
</View>
);
}
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)