Define return key action in React Native

I have a TextInput which I have included multiline as true. Thing is a keyboard that will not hide after pressing Return. He moves to a new line. So I was hoping to use react-native-dismiss-keyboard . To take advantage of this, I need to determine the effect of the return key. How to do it?

 <TextInput style={styles.additionalTextInput} multiline={true} autoCapitalize="sentences" autoCorrect={true} onChangeText={(text) => this.setState({text})} keyboardType="default" returnKeyType="done" onKeyPress={(keyPress) => console.log(keyPress)} placeholder="Enter text here..." /> 
+5
source share
2 answers

I used onSubmitEditing details. eg.

 <TextInput style={[styles.textInput]} placeholder='ๆœ็ดข' placeholderTextColor='#bbb' onChange={(event) => { this.searchChange(event.nativeEvent.text) }} returnKeyType='search' autoFocus={true} value={ this.props.searchName } selectionColor={colors.orangeColor} onSubmitEditing={this.searchSubmit} clearButtonMode="while-editing" /> 
+14
source

Ok, found a solution.

 <TextInput style={styles.additionalTextInput} multiline={true} autoCapitalize="sentences" autoCorrect={true} onChangeText={(orderInstructions) => this.setState({orderInstructions})} keyboardType="default" returnKeyType="done" onKeyPress={this.handleKeyDown} placeholder="Enter text here..." /> handleKeyDown: function(e) { if(e.nativeEvent.key == "Enter"){ dismissKeyboard(); } }, 

The rejectKeyboard method is react-native-dismiss-keyboard .

This works great for me.

+13
source

Source: https://habr.com/ru/post/1244332/


All Articles