react-native - 键盘关闭时失去 TextInput 的焦点
问题描述
我TextInput
在ScrollView
. 问题在于,如果我用 return 或 android back 按钮关闭键盘,则TextInput
所选内容仍然是焦点,我必须点击两次才能聚焦另一个TextInput
。
以下是我正在使用的组件:
<ScrollView style = {styles.scroll}>
<KeyboardAvoidingView styles={styles.container} behavior = 'padding' enabled>
<View style={styles.header1}><Text style={styles.title}>Blue Line Notes</Text></View>
<View style={styles.headerDesign}></View>
<View style={styles.header2}></View>
<View style = {styles.items}>
<TextInput
style = {styles.subject}
onChangeText={(noteTitle)=> this.setState({noteTitle})}
value={this.state.noteTitle}
placeholder='Raport Number/Note Indentifier'
placeholderTextColor='grey'
underlineColorAndroid='transparent'>
</TextInput>
</View>
<View style = {styles.items}>
<TextInput
style = {styles.calltype}
multiline = {true}
numberOfLines = {3}
onChangeText={(callType)=> this.setState({callType})}
value={this.state.callType}
placeholder='Call Type/Other Information'
placeholderTextColor='grey'
underlineColorAndroid='transparent'>
</TextInput>
</View>
<View style = {styles.items}>
<TextInput
multiline = {true}
numberOfLines = {8}
style={styles.textInput}
placeholder='Notes'
onChangeText={(noteText)=> this.setState({noteText})}
value={this.state.noteText}
placeholderTextColor='grey'
underlineColorAndroid='transparent'>
</TextInput>
</View>
<View style = {styles.items}>
<TouchableOpacity onPress = { this.saveNote.bind(this)} style={styles.addButton}>
<Text style={styles.addButtonText}>SAVE</Text>
</TouchableOpacity>
</View>
</KeyboardAvoidingView>
</ScrollView>
我认为我需要做的是TextInput
在键盘关闭时失去焦点。这是我正在努力解决的问题。有人可以告诉我如何正确地做到这一点吗?
解决方案
尝试keyboardShouldPersistTaps="handled"
作为ScrollView
属性。我在您给定的代码上尝试了相同的方法并且它有效。您可以在此处查看更多房产详情。
希望这会有所帮助!
推荐阅读
- reactjs - 在 Next.js 中禁用开发时缓存
- css - 如何使用 Dart Sass 在选择器中导入外部文件
- angular - 如何插入可拖动和可调整大小的输入文本框和图像
- function - 没有固定标准的 MAXIFS
- node.js - 如何在 swagger 表单数据字段中传递字符串数组
- scala - `sbt run` 添加依赖后编译时出错
- drools - LHS 清空列表触发规则
- npm - 来自 security-wg git repo json 文件的漏洞数据与来自注册表 apis 的漏洞数据之间的关系
- visual-studio-code - vscode中VSCODE_NLS_CONFIG得到的值不对
- macos - 我收到“文字中的无效转义序列”错误