React-native: how to wrap FlatList items

后端 未结 3 1378
情话喂你
情话喂你 2021-01-03 20:56

I have a list of Terms that are returned by a query. Each is a single word. Currently my FlatList renders each word into a button on the same row (horizontal={true}) I would

相关标签:
3条回答
  • 2021-01-03 21:13

    Unfortunately flexWrap is indeed unsupported in FlatLists. We are recommended to use a ScrollView instead of a FlatList to create this effect. This is the issue: https://github.com/facebook/react-native/issues/13939

    0 讨论(0)
  • 2021-01-03 21:20

    You can remove the horizontal prop to achieve the wrapping effect

    ................
    ..................
    
    <FlatList
        contentContainerStyle={{flexDirection : "row", flexWrap : "wrap"}} 
        data={this.state.dataSource} renderItem={({item}) =>
            <Button>
                <Text>{item.key}</Text>
            </Button>
        }
    />
    .................
    ..............
    
    0 讨论(0)
  • How I was able to wrap the components was like below

    flatlist: {
       flexDirection: 'column',
    },
    

    and in my FlatList component added this props

    numColumns={3}
    
    0 讨论(0)
提交回复
热议问题