react-nativescrollviewtextinputreact-native-flatlistreact-native-scrollview

React Native "keyboardDismissMode" at FlatList


Is there any possibility to prevent the keyboard from dismissing when scrolling a FlatList?

When using a ScrollView setting the prop "keyboardDismissMode" to "none" is the solution to this problem, but this doesn't work for me at a FlatList...

I use the FlatList inside a self-made component, that is in a Stack-Navigator, while there is a focussed TextInput in its header. I render the FlatList like this:

<View style={{flex: 1}}>
  <FlatList 
    style={{flex: 1}}
    data={this.props.data}
    keyExtractor={(item, index) => item.id}
    renderItem={this.renderItem}
  />
</View>

The renderItem() function:

renderItem = ({item, index}) => (
  <TouchableHighlight
    style={{paddingVertical: 10}}
    onPress={() => {
      this.props.onChooseItem(item);
    }}
  >
    <Text numberOfLines={1} >
      {item.text}
    </Text>
  </TouchableHighlight>
)

Solution

  • You might think about to encapsulate your FlatList in a ScrollView?

    Even if this seems to solve the issue, it's NOT a recommended way!

    That's because if it force rerendering the whole flatlist, each time you scroll the screen.

    You might better try a component like react-native-keyboard-aware-scroll-view

    I've found this article with some alternate Ideas to fix it:
    How to use KeyboardAvoidingView with FlatList?

    Check: https://facebook.github.io/react-native/docs/scrollview#keyboarddismissmode