How to get React Native TextInput to maintain focus after submit?

I could explain what I'm trying to do, but this ReactJS example is a step-by-step guide on exactly what I want. The problem is that I can’t understand what the equivalent of responding to my native language is.

Basically, when I press return in TextInput, I want the text to be cleared and saved.

Any thoughts?

+6
source share
2 answers

I sent a PR with the blurOnSubmit property.

Set to false and TextInput never erased, onSubmitEditing still fires.

Hope it will be merged. :)

https://github.com/facebook/react-native/pull/2149

+15
source

I came out with the following (working) solution:

 var NameInput = React.createClass({ getInitialState() { return { textValue: '' } }, clearAndRetainFocus: function(evt, elem) { this.setState({textValue: elem.text}); setTimeout(function() { this.setState({textValue: this.getInitialState().textValue}); this.refs.Name.focus(); }.bind(this), 0); }, render() { return( <TextInput ref='Name' value={this.state.textValue} onEndEditing={this.clearAndRetainFocus} /> ) } }); 

So, basically, when we finish editing, we set the textValue state to TextInput and right after that (in setTimeout ), we return it back to the default (empty) and keep focus on the element.

+6
source

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


All Articles