ios - 如何在某些数据部分之后将分隔符添加到 FlatList 中?

标签 ios react-native react-native-flatlist

如何在渲染数据后在 React-Native FlatList 中添加分隔符?

我尝试使用 React-Native SectionList,但我无法像在 FlatList 中那样添加 fetchNext 函数。

这是我当前的代码

<FlatList
  data={data}
  keyExtractor={keyExtractor}
  renderItem={renderItem}
  fetchNext={fetchNextPage}
  numColumns={2}
  ItemSeparatorComponent={<View style={this.separatorStyles} />}
  ListFooterComponent={isFetching && <LoaderView notExpand />}
/>

|####| |####|
|####| |####|
|####| |####|

|####| |####|
|####| |####|
|####| |####|
------------- (need add some separator)
|####| |####|
|####| |####|
|####| |####|

|####| |####|
|####| |####|
|####| |####|

最佳答案

出于文档目的,我将发布更详细的答案。这是重要的代码:

const data = [{ id: 1 }, { id: 2 }, { separator: true, id: 3 }, { id: 4 }, { id: 5 }, { id: 6 }];

renderItem = ({ item }) => item.separator ? (
  <Text>-------- separator -------</Text>
) : (
  <Text>{`------${item.id}------`}</Text>
);

<FlatList
  renderItem={this.renderItem}
  data={data}
  numColumns={2}
/>

请注意,如果分隔符占据整个屏幕宽度,则项目 4 将呈现在屏幕之外。例如,您可以在分隔符之后呈现一个空 View 。

关于ios - 如何在某些数据部分之后将分隔符添加到 FlatList 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56171494/

相关文章:

ios - 避免 nil slider 值?

python - 安装核心 ML 工具时出错

reactjs - 无法在 Jenkins 管道中构建 reactjs

javascript - 错误 : Youtube link inside html text inside react native app

react-native - 如何使用来自网络的数据填充 FlatList 的 header ?

ios - 获得第一个Google Image Web服务

ios - 自动布局:标题 View 逐渐包含 UILabel + UIButton

Xcode、React Native 和 redux 记录器 : [TOO BIG formatValueCalls XXX exceeded limit of 200]

javascript - React-Native:Modal 中的 Flatlist 无法滚动

javascript - 为什么 FlatList 在 React Native 中没有动态更新