Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native FlatList Inside of a Modal

I am trying to put a FlatList inside of a Modal but the List just spills out of the containers I have given it rather than scrolling. I have tried adding flex and such, but have had no luck getting the List to stay inside the bounds. Any suggestions?

Here is the Modal

const modalContainer = {
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
flex: 1,
  };

  const innerContainer = {
alignItems: 'center',
// flex: 1,
height: 130,
backgroundColor: colors.white.white,
borderRadius: borderRadius.sm,
width: 450,
  };

  render() {
    const styles = styleMaker();

    return (
      <View>
        <Modal visible = {this.props.visible}>
          <View style={styles.overlay} />
          <View style = {styles.modalContainer}>
          <View style = {styles.innerContainer}>
            {this.props.children}
          </View>
          </View>
        </Modal>
      </View>
    );
  }
like image 723
StuffedPoblano Avatar asked Oct 27 '25 10:10

StuffedPoblano


1 Answers

This worked good for me:

Wrap Flatlist with a ScrollView and a View with onStartShouldSetResponder={(): boolean => true}

full example:

<Modal
   ....>
  <View style={{ height: 300 }}>
    <ScrollView>
      <View onStartShouldSetResponder={(): boolean => true}>
        <FlatList
         ....
          />
      </View>
    </ScrollView>
  </View>
</Modal>
like image 137
Davide Carpini Avatar answered Oct 28 '25 23:10

Davide Carpini