首页 > 解决方案 > 键盘关闭时失去 TextInput 的焦点

问题描述

TextInputScrollView. 问题在于,如果我用 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在键盘关闭时失去焦点。这是我正在努力解决的问题。有人可以告诉我如何正确地做到这一点吗?

标签: react-native

解决方案


尝试keyboardShouldPersistTaps="handled"作为ScrollView属性。我在您给定的代码上尝试了相同的方法并且它有效。您可以在此处查看更多房产详情。

希望这会有所帮助!


推荐阅读