简体   繁体   English

在模态内反应原生 FlatList

[英]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.我试图将 FlatList 放在 Modal 中,但 List 只是从我给它的容器中溢出而不是滚动。 I have tried adding flex and such, but have had no luck getting the List to stay inside the bounds.我曾尝试添加 flex 等,但没有运气让 List 保持在边界内。 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> ); }

This worked good for me:这对我很有用:

Wrap Flatlist with a ScrollView and a View with onStartShouldSetResponder={(): boolean => true}使用 ScrollView 和带有onStartShouldSetResponder={(): boolean => true}的 View 包裹 Flatlist

full example:完整示例:

<Modal
   ....>
  <View style={{ height: 300 }}>
    <ScrollView>
      <View onStartShouldSetResponder={(): boolean => true}>
        <FlatList
         ....
          />
      </View>
    </ScrollView>
  </View>
</Modal>
<Modal
    animationType="slide"
    transparent={false}
    visible={this.state.modalVisible}
    onRequestClose={() => this.onRequestClose()}>
    <FlatList
        data={[{ key: 'a' }, { key: 'b' }]}
        renderItem={({ item }) => <Text>{item.key}</Text>}
     />
</Modal>

You can find an example as below link您可以在下面的链接中找到示例

https://snipsave.com/javawebline/#/snippet/ZYgnr5nu2hHPrM8atX https://snipsave.com/javawebline/#/snippet/ZYgnr5nu2hHPrM8atX

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM