键盘关闭时丢失TextInput的焦点

时间:2018-05-30 09:51:07

标签: react-native

我在TextInput中有一些ScrollView个组件。问题是,如果我使用return或android后退按钮关闭键盘,所选的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的焦点。这是我正在努力的事情。有人能告诉我如何正确地做到这一点吗?

1 个答案:

答案 0 :(得分:2)

尝试keyboardShouldPersistTaps="handled"作为ScrollView属性。我在你给定的代码上尝试了同样的方法并且它有效。您可以查看详细信息here

希望这会有所帮助!