如何在 React Native 中包装 Flatlist 项目

Muh*_*sin 6 flexbox reactjs react-native react-native-flexbox react-native-flatlist

我正在尝试呈现此图像中的项目列表。 在此处输入图片说明

每行中的项目将根据其文本大小而有所不同。Flatlist用于渲染项目。

标签视图.js

<View style={styles.tagView}>
    <FlatList 
        scrollEventThrottle={1900} 
        data={this.state.interests} 
        numColumns={5}
        renderItem={({ item }) => (
           <View style={styles.tag}>
               <Text>{item.tagName}</Text>
           </View>
        )}
        keyExtractor={(item, index) => index}
        contentContainerStyle={{ paddingBottom: 100 }}
    />
</View>
Run Code Online (Sandbox Code Playgroud)

风格

tagView: {
    flex: 1,
    flexDirection: "row",
    flexWrap: "wrap"
},
tag: {
    borderWidth: 1,
    borderRadius: 10,
    borderColor: "black",
    backgroundColor: "white",
    padding: 3,
    marginTop: 5
}
Run Code Online (Sandbox Code Playgroud)

结果

在此处输入图片说明

但是这里的项目没有用设备宽度包装。有没有包装内容?

Has*_* pk 5

带有 columnWrapperStyle 的 FlatList

<FlatList 
    columnWrapperStyle={styles.tagView}
    scrollEventThrottle={1900} 
    data={this.state.interests} 
    numColumns={5}
    renderItem={({ item }) => (
       <View style={styles.tag}>
           <Text>{item.tagName}</Text>
       </View>
    )}
    keyExtractor={(item, index) => index}
    contentContainerStyle={{ paddingBottom: 100 }}
/>
Run Code Online (Sandbox Code Playgroud)

风格

tagView: {
  flexWrap: "wrap"
},
Run Code Online (Sandbox Code Playgroud)


Yog*_*nan 4

添加水平支柱并尝试,

      <FlatList 
        scrollEventThrottle={1900} 
        data={this.state.interests} 
        numColumns={5}
        horizontal={false}
        renderItem={({ item }) => (
           <View style={styles.tag}>
               <Text>{item.tagName}</Text>
           </View>
        )}
        keyExtractor={(item, index) => index}
        contentContainerStyle={{ paddingBottom: 100 }}
    />
Run Code Online (Sandbox Code Playgroud)