react-native - 如何修复此警告 : VirtualizedLists should never be nested inside plain ScrollViews with the same orientation

标签 react-native react-native-flatlist react-native-scrollview safeareaview

当我使用 FlatList内部组件 ScrollView我看到一个警告:

VirtualizedLists should never be nested inside plain ScrollViews with the same orientation - use another VirtualizedList-backed container instead.


前后FlatList我使用了很多其他组件,而且我的屏幕很长。
我试图用 SafeAreaView 包装内容它对我没有帮助,因为在这种情况下我无法滚动内容。我也尝试使用 ListHeaderComponent={SafeAreaView}ListFooterComponent={SafeAreaView}<FlatList> .
我用:
  • “ react ”:“16.9.0”,
  • “ react 原生”:“0.61.5”,
  • 最佳答案

    这是一个使用 FlatList 的 VirutalizedList 支持的容器实现:

    import React from 'react';
    import { FlatList } from 'react-native';
    
    export default function VirtualizedView(props: any) {
      return (
        <FlatList
          data={[]}
          ListEmptyComponent={null}
          keyExtractor={() => "dummy"}
          renderItem={null}
          ListHeaderComponent={() => (
            <React.Fragment>{props.children}</React.Fragment>
          )}
        />
      );
    }
    
    用法:
    
      <VirtualizedView>
        <Text>Anything goes here, even FlatList works good</Text>
        <View style={{minHeight: 480}}> // leave enough space for better user experience
          <FlatList 
            data={data}
            keyExtractor={keyExtractor}
            renderItem={({item}) => <Item data={item} />}
            onRefresh={refetch}
            refreshing={loading}
            onEndReached={concatData}
          />
        </View>
      </VirtualizedView>
    
    
    当您的屏幕太长时,这将显示滚动条,并删除讨厌的警告消息,性能将毫无问题地得到保存。

    关于react-native - 如何修复此警告 : VirtualizedLists should never be nested inside plain ScrollViews with the same orientation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59359129/

    相关文章:

    react-native - 将 Expo Bare 转变为托管项目

    android - react native : undefined is not an object (evaluating 'r.default.manifest.env' )

    react-native - 在水平平面列表上方垂直对齐 ListHeaderComponent

    react-native - 如何创建具有多行和具有动态宽度的项目的水平 FlatList?

    reactjs - 当我滚动 Flatlist 时内存使用量越来越高,并且当我停止滚动时内存不会释放(React Native)

    react-native - React Native - 如何在水平可滚动列表中模拟 RefreshControl

    react-native - react 原生 NavigatorIOS 错误 : Element type is invalid expected a string or a class/function

    ios - 在 Docker 中使用 FaSTLane 构建 iOS 应用

    react-native - ScrollView 和带有 flex : 1 的子项

    android - react-native-keyboard-aware-scroll-view 在 Android 上不滚动