You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FlashList首次渲染耗时远超FlatList 求助优化方案

当前表现

FlashList首次渲染耗时远高于FlatList:

  • FlashList耗时约3秒
  • FlatList仅耗时300毫秒

预期表现

FlashList首次渲染耗时应与FlatList相近。切换为FlatList时仅需将FlashList替换为FlatList,并移除estimatedItemSize和estimatedListSize属性。

复现步骤

以下为复现代码:

import React from 'react';
import { Dimensions, FlatList } from 'react-native';
import { NewCarCard } from 'features/cars/new-cars/new-car-card';
import { Line } from 'ui/dividers/line';
import { useNewCars } from 'features/cars/new-cars/hooks/use-new-cars';
import { NewCarsVerticalListShimmer } from 'features/cars/new-cars/shimmers/new-cars-vertical-list.shimmer';

const deviceWidth = Dimensions.get('window').width;
const deviceHeight = Dimensions.get('window').height;

interface Props {
  onPress: () => void;
  scrollEnabled: boolean;
}

export function NewCarsVerticalList(props: Props) {
  const { data, hasNextPage, fetchNextPage, isFetchingNextPage } = useNewCars();
  const newCarsFlatted = data?.pages.map(page => page.data.data.items).flat();
  const loadNext = React.useCallback(() => {
    if (hasNextPage && !isFetchingNextPage) {
      fetchNextPage();
    }
  }, [hasNextPage, isFetchingNextPage, fetchNextPage]);

  const renderItem = ({ item }) => {
    return (
      <React.Fragment>
        <NewCarCard newCar={item} onPress={props.onPress} />
        <Line />
      </React.Fragment>
    );
  };
  const renderListFooter = () => {
    if (isFetchingNextPage) {
      return (
        // Show shimmer when isFetchingNextPage is true
        <>
          <NewCarsVerticalListShimmer />
          <NewCarsVerticalListShimmer />
        </>
      );
    }
    return null;
  };

  return (
    <FlashList
      scrollEnabled={props.scrollEnabled || false}
      data={newCarsFlatted}
      showsVerticalScrollIndicator={false}
      estimatedItemSize={deviceHeight * 0.45}
      estimatedListSize={{
        height: deviceHeight * 0.45 * newCarsFlatted.length,
        width: Dimensions.get('screen').width,
      }}
      renderItem={({ item }) => renderItem({ item })}
      keyExtractor={item => item?.id} // Make sure to use a string for the key
      onEndReached={loadNext}
      onEndReachedThreshold={0.7}
      ListFooterComponent={renderListFooter}
    />
  );
}

export default React.memo(NewCarsVerticalList);

平台

  • iOS
  • Android

环境

  • "react-native": "0.72.3"
  • "@shopify/flash-list": "^1.6.1"

内容的提问来源于stack exchange,提问作者Zero0

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 16:13:13