Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native TextInput setState() hides keyboard

Tags:

react-native

Please check on the snack link, https://snack.expo.io/@banid/textinput The TextInput on the filter view(shows when the button is pressed) hides keyboard when ever I call setState(). I call setState to update the value of TextInput. Bcause of this I can't type continuously on the TextInput. Is this a bug or am I doing something wrong?? Thank you

like image 949
Banid Azin Avatar asked Jul 02 '26 10:07

Banid Azin


1 Answers

The problem is that you are creating a new (anonymous) function that renders the header of the FlatList on every update

<FlatList .... ListHeaderComponent={() => this.showHeader()} />

So a new TextInput is being created instead of updating the existing one.

Solution:

change ListHeaderComponent={() => this.showHeader()}

to ListHeaderComponent={this.showHeader} as ListHeaderComponent can be a function

https://facebook.github.io/react-native/docs/flatlist#listheadercomponent

Similar Issue: https://github.com/react-native-training/react-native-elements/issues/559

like image 72
Haythem Farhat Avatar answered Jul 05 '26 13:07

Haythem Farhat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!