ScrollView 中的 FlatList 错误“VirtualizedLists 永远不应嵌套在具有相同方向的普通 ScrollView 中”

问题描述 投票:0回答:1

我在其中使用 Flatlist 制作了一个组件 EventCards。我在 Home 组件中调用该组件,其中 EventCards 组件位于 ScrollView 中。

Const Home= () => { 
  return ( 
    othercomponents...
      <ScrollView>
        othercomponents...
        <EventCards />
        othercomponents...
      </ScrollView>
    othercomponents...
    )
  }

现在,它给出了一个错误:

VirtualizedLists should never be nested inside plain ScrollViews with the same orientation because it can break windowing and other functionality - use another VirtualizedList-backed container instead.

我尝试在 Scrollview 中使用 FlatList。但它抛出一个错误。我想解决这个错误。

react-native scrollview react-native-flatlist flatlist react-native-scrollview
1个回答
0
投票

正如明确指出的,你不应该将 FlatList 嵌套在 ScrollView 中。

现在,如果您希望当用户在视口内滚动时在 FlatList 之前或之后看到 ScrollView 内的其他组件,您可以分别使用 ListHeaderComponent 和 ListFooterComponent,然后从代码中删除 ScrollView。

如果这不是您正在寻找的答案,请提供有关您计划实现的 UI 的更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.