@react-native-ohos/flash-list 1.6.4-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.OpenSource +11 -0
- package/README.md +9 -0
- package/dist/AnimatedFlashList.d.ts +6 -0
- package/dist/AnimatedFlashList.d.ts.map +1 -0
- package/dist/AnimatedFlashList.js +8 -0
- package/dist/AnimatedFlashList.js.map +1 -0
- package/dist/FlashList.d.ts +126 -0
- package/dist/FlashList.d.ts.map +1 -0
- package/dist/FlashList.js +524 -0
- package/dist/FlashList.js.map +1 -0
- package/dist/FlashListProps.d.ts +256 -0
- package/dist/FlashListProps.d.ts.map +1 -0
- package/dist/FlashListProps.js +9 -0
- package/dist/FlashListProps.js.map +1 -0
- package/dist/GridLayoutProviderWithProps.d.ts +42 -0
- package/dist/GridLayoutProviderWithProps.d.ts.map +1 -0
- package/dist/GridLayoutProviderWithProps.js +115 -0
- package/dist/GridLayoutProviderWithProps.js.map +1 -0
- package/dist/MasonryFlashList.d.ts +51 -0
- package/dist/MasonryFlashList.d.ts.map +1 -0
- package/dist/MasonryFlashList.js +252 -0
- package/dist/MasonryFlashList.js.map +1 -0
- package/dist/PureComponentWrapper.d.ts +22 -0
- package/dist/PureComponentWrapper.d.ts.map +1 -0
- package/dist/PureComponentWrapper.js +37 -0
- package/dist/PureComponentWrapper.js.map +1 -0
- package/dist/__tests__/AverageWindow.test.d.ts +2 -0
- package/dist/__tests__/AverageWindow.test.d.ts.map +1 -0
- package/dist/__tests__/AverageWindow.test.js +69 -0
- package/dist/__tests__/AverageWindow.test.js.map +1 -0
- package/dist/__tests__/ContentContainerUtils.test.d.ts +2 -0
- package/dist/__tests__/ContentContainerUtils.test.d.ts.map +1 -0
- package/dist/__tests__/ContentContainerUtils.test.js +85 -0
- package/dist/__tests__/ContentContainerUtils.test.js.map +1 -0
- package/dist/__tests__/FlashList.test.d.ts +2 -0
- package/dist/__tests__/FlashList.test.d.ts.map +1 -0
- package/dist/__tests__/FlashList.test.js +792 -0
- package/dist/__tests__/FlashList.test.js.map +1 -0
- package/dist/__tests__/GridLayoutProviderWithProps.test.d.ts +2 -0
- package/dist/__tests__/GridLayoutProviderWithProps.test.d.ts.map +1 -0
- package/dist/__tests__/GridLayoutProviderWithProps.test.js +143 -0
- package/dist/__tests__/GridLayoutProviderWithProps.test.js.map +1 -0
- package/dist/__tests__/MasonryFlashList.test.d.ts +2 -0
- package/dist/__tests__/MasonryFlashList.test.d.ts.map +1 -0
- package/dist/__tests__/MasonryFlashList.test.js +254 -0
- package/dist/__tests__/MasonryFlashList.test.js.map +1 -0
- package/dist/__tests__/PlatformHelper.web.test.d.ts +2 -0
- package/dist/__tests__/PlatformHelper.web.test.d.ts.map +1 -0
- package/dist/__tests__/PlatformHelper.web.test.js +33 -0
- package/dist/__tests__/PlatformHelper.web.test.js.map +1 -0
- package/dist/__tests__/ViewabilityHelper.test.d.ts +2 -0
- package/dist/__tests__/ViewabilityHelper.test.d.ts.map +1 -0
- package/dist/__tests__/ViewabilityHelper.test.js +187 -0
- package/dist/__tests__/ViewabilityHelper.test.js.map +1 -0
- package/dist/__tests__/helpers/mountFlashList.d.ts +19 -0
- package/dist/__tests__/helpers/mountFlashList.d.ts.map +1 -0
- package/dist/__tests__/helpers/mountFlashList.js +44 -0
- package/dist/__tests__/helpers/mountFlashList.js.map +1 -0
- package/dist/__tests__/helpers/mountMasonryFlashList.d.ts +18 -0
- package/dist/__tests__/helpers/mountMasonryFlashList.d.ts.map +1 -0
- package/dist/__tests__/helpers/mountMasonryFlashList.js +49 -0
- package/dist/__tests__/helpers/mountMasonryFlashList.js.map +1 -0
- package/dist/__tests__/useBlankAreaTracker.test.d.ts +2 -0
- package/dist/__tests__/useBlankAreaTracker.test.d.ts.map +1 -0
- package/dist/__tests__/useBlankAreaTracker.test.js +177 -0
- package/dist/__tests__/useBlankAreaTracker.test.js.map +1 -0
- package/dist/benchmark/AutoScrollHelper.d.ts +18 -0
- package/dist/benchmark/AutoScrollHelper.d.ts.map +1 -0
- package/dist/benchmark/AutoScrollHelper.js +68 -0
- package/dist/benchmark/AutoScrollHelper.js.map +1 -0
- package/dist/benchmark/JSFPSMonitor.d.ts +23 -0
- package/dist/benchmark/JSFPSMonitor.d.ts.map +1 -0
- package/dist/benchmark/JSFPSMonitor.js +65 -0
- package/dist/benchmark/JSFPSMonitor.js.map +1 -0
- package/dist/benchmark/roundToDecimalPlaces.d.ts +2 -0
- package/dist/benchmark/roundToDecimalPlaces.d.ts.map +1 -0
- package/dist/benchmark/roundToDecimalPlaces.js +9 -0
- package/dist/benchmark/roundToDecimalPlaces.js.map +1 -0
- package/dist/benchmark/useBenchmark.d.ts +35 -0
- package/dist/benchmark/useBenchmark.d.ts.map +1 -0
- package/dist/benchmark/useBenchmark.js +167 -0
- package/dist/benchmark/useBenchmark.js.map +1 -0
- package/dist/benchmark/useBlankAreaTracker.d.ts +34 -0
- package/dist/benchmark/useBlankAreaTracker.d.ts.map +1 -0
- package/dist/benchmark/useBlankAreaTracker.js +67 -0
- package/dist/benchmark/useBlankAreaTracker.js.map +1 -0
- package/dist/benchmark/useDataMultiplier.d.ts +9 -0
- package/dist/benchmark/useDataMultiplier.d.ts.map +1 -0
- package/dist/benchmark/useDataMultiplier.js +25 -0
- package/dist/benchmark/useDataMultiplier.js.map +1 -0
- package/dist/benchmark/useFlatListBenchmark.d.ts +13 -0
- package/dist/benchmark/useFlatListBenchmark.d.ts.map +1 -0
- package/dist/benchmark/useFlatListBenchmark.js +100 -0
- package/dist/benchmark/useFlatListBenchmark.js.map +1 -0
- package/dist/errors/CustomError.d.ts +8 -0
- package/dist/errors/CustomError.d.ts.map +1 -0
- package/dist/errors/CustomError.js +14 -0
- package/dist/errors/CustomError.js.map +1 -0
- package/dist/errors/ExceptionList.d.ts +24 -0
- package/dist/errors/ExceptionList.d.ts.map +1 -0
- package/dist/errors/ExceptionList.js +26 -0
- package/dist/errors/ExceptionList.js.map +1 -0
- package/dist/errors/Warnings.d.ts +9 -0
- package/dist/errors/Warnings.d.ts.map +1 -0
- package/dist/errors/Warnings.js +13 -0
- package/dist/errors/Warnings.js.map +1 -0
- package/dist/fabric/AutoLayoutNativeComponent.d.ts +19 -0
- package/dist/fabric/AutoLayoutNativeComponent.d.ts.map +1 -0
- package/dist/fabric/AutoLayoutNativeComponent.js +29 -0
- package/dist/fabric/AutoLayoutNativeComponent.js.map +1 -0
- package/dist/fabric/CellContainerNativeComponent.d.ts +8 -0
- package/dist/fabric/CellContainerNativeComponent.d.ts.map +1 -0
- package/dist/fabric/CellContainerNativeComponent.js +29 -0
- package/dist/fabric/CellContainerNativeComponent.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/native/auto-layout/AutoLayoutView.d.ts +22 -0
- package/dist/native/auto-layout/AutoLayoutView.d.ts.map +1 -0
- package/dist/native/auto-layout/AutoLayoutView.js +48 -0
- package/dist/native/auto-layout/AutoLayoutView.js.map +1 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.android.d.ts +4 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.android.d.ts.map +1 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.android.js +6 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.android.js.map +1 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.d.ts +5 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.d.ts.map +1 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.harmony.d.ts +4 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.harmony.d.ts.map +1 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.harmony.js +29 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.harmony.js.map +1 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.ios.d.ts +4 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.ios.d.ts.map +1 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.ios.js +6 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.ios.js.map +1 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.js +6 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.js.map +1 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.d.ts +16 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.d.ts.map +1 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.js +3 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.js.map +1 -0
- package/dist/native/cell-container/CellContainer.android.d.ts +6 -0
- package/dist/native/cell-container/CellContainer.android.d.ts.map +1 -0
- package/dist/native/cell-container/CellContainer.android.js +9 -0
- package/dist/native/cell-container/CellContainer.android.js.map +1 -0
- package/dist/native/cell-container/CellContainer.d.ts +8 -0
- package/dist/native/cell-container/CellContainer.d.ts.map +1 -0
- package/dist/native/cell-container/CellContainer.harmony.d.ts +6 -0
- package/dist/native/cell-container/CellContainer.harmony.d.ts.map +1 -0
- package/dist/native/cell-container/CellContainer.harmony.js +32 -0
- package/dist/native/cell-container/CellContainer.harmony.js.map +1 -0
- package/dist/native/cell-container/CellContainer.ios.d.ts +6 -0
- package/dist/native/cell-container/CellContainer.ios.d.ts.map +1 -0
- package/dist/native/cell-container/CellContainer.ios.js +9 -0
- package/dist/native/cell-container/CellContainer.ios.js.map +1 -0
- package/dist/native/cell-container/CellContainer.js +11 -0
- package/dist/native/cell-container/CellContainer.js.map +1 -0
- package/dist/native/cell-container/CellContainer.web.d.ts +7 -0
- package/dist/native/cell-container/CellContainer.web.d.ts.map +1 -0
- package/dist/native/cell-container/CellContainer.web.js +13 -0
- package/dist/native/cell-container/CellContainer.web.js.map +1 -0
- package/dist/native/config/PlatformHelper.android.d.ts +26 -0
- package/dist/native/config/PlatformHelper.android.d.ts.map +1 -0
- package/dist/native/config/PlatformHelper.android.js +23 -0
- package/dist/native/config/PlatformHelper.android.js.map +1 -0
- package/dist/native/config/PlatformHelper.d.ts +26 -0
- package/dist/native/config/PlatformHelper.d.ts.map +1 -0
- package/dist/native/config/PlatformHelper.harmony.d.ts +26 -0
- package/dist/native/config/PlatformHelper.harmony.d.ts.map +1 -0
- package/dist/native/config/PlatformHelper.harmony.js +22 -0
- package/dist/native/config/PlatformHelper.harmony.js.map +1 -0
- package/dist/native/config/PlatformHelper.ios.d.ts +26 -0
- package/dist/native/config/PlatformHelper.ios.d.ts.map +1 -0
- package/dist/native/config/PlatformHelper.ios.js +22 -0
- package/dist/native/config/PlatformHelper.ios.js.map +1 -0
- package/dist/native/config/PlatformHelper.js +23 -0
- package/dist/native/config/PlatformHelper.js.map +1 -0
- package/dist/native/config/PlatformHelper.web.d.ts +27 -0
- package/dist/native/config/PlatformHelper.web.d.ts.map +1 -0
- package/dist/native/config/PlatformHelper.web.js +25 -0
- package/dist/native/config/PlatformHelper.web.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils/AverageWindow.d.ts +21 -0
- package/dist/utils/AverageWindow.d.ts.map +1 -0
- package/dist/utils/AverageWindow.js +49 -0
- package/dist/utils/AverageWindow.js.map +1 -0
- package/dist/utils/ContentContainerUtils.d.ts +27 -0
- package/dist/utils/ContentContainerUtils.d.ts.map +1 -0
- package/dist/utils/ContentContainerUtils.js +48 -0
- package/dist/utils/ContentContainerUtils.js.map +1 -0
- package/dist/viewability/ViewToken.d.ts +8 -0
- package/dist/viewability/ViewToken.d.ts.map +1 -0
- package/dist/viewability/ViewToken.js +3 -0
- package/dist/viewability/ViewToken.js.map +1 -0
- package/dist/viewability/ViewabilityHelper.d.ts +25 -0
- package/dist/viewability/ViewabilityHelper.d.ts.map +1 -0
- package/dist/viewability/ViewabilityHelper.js +104 -0
- package/dist/viewability/ViewabilityHelper.js.map +1 -0
- package/dist/viewability/ViewabilityManager.d.ts +24 -0
- package/dist/viewability/ViewabilityManager.d.ts.map +1 -0
- package/dist/viewability/ViewabilityManager.js +94 -0
- package/dist/viewability/ViewabilityManager.js.map +1 -0
- package/harmony/flash_list/BuildProfile.ets +5 -0
- package/harmony/flash_list/LICENSE +7 -0
- package/harmony/flash_list/build-profile.json5 +8 -0
- package/harmony/flash_list/hvigorfile.ts +1 -0
- package/harmony/flash_list/index.ets +29 -0
- package/harmony/flash_list/obfuscation-rules.txt +18 -0
- package/harmony/flash_list/oh-package-lock.json5 +17 -0
- package/harmony/flash_list/oh-package.json5 +13 -0
- package/harmony/flash_list/src/main/cpp/AutoLayoutNode.cpp +63 -0
- package/harmony/flash_list/src/main/cpp/AutoLayoutNode.h +57 -0
- package/harmony/flash_list/src/main/cpp/AutoLayoutShadow.cpp +140 -0
- package/harmony/flash_list/src/main/cpp/AutoLayoutShadow.h +66 -0
- package/harmony/flash_list/src/main/cpp/AutoLayoutViewComponentInstance.cpp +208 -0
- package/harmony/flash_list/src/main/cpp/AutoLayoutViewComponentInstance.h +78 -0
- package/harmony/flash_list/src/main/cpp/AutoLayoutViewEventEmitRequestHandler.h +53 -0
- package/harmony/flash_list/src/main/cpp/AutoLayoutViewJSIBinder.h +50 -0
- package/harmony/flash_list/src/main/cpp/CMakeLists.txt +7 -0
- package/harmony/flash_list/src/main/cpp/CellContainerComponentInstance.cpp +80 -0
- package/harmony/flash_list/src/main/cpp/CellContainerComponentInstance.h +67 -0
- package/harmony/flash_list/src/main/cpp/CellContainerJSIBinder.h +39 -0
- package/harmony/flash_list/src/main/cpp/ComponentDescriptors.h +40 -0
- package/harmony/flash_list/src/main/cpp/EventEmitters.cpp +40 -0
- package/harmony/flash_list/src/main/cpp/EventEmitters.h +48 -0
- package/harmony/flash_list/src/main/cpp/FlashListPackage.h +78 -0
- package/harmony/flash_list/src/main/cpp/FlashListStackNode.cpp +89 -0
- package/harmony/flash_list/src/main/cpp/FlashListStackNode.h +59 -0
- package/harmony/flash_list/src/main/cpp/Props.cpp +52 -0
- package/harmony/flash_list/src/main/cpp/Props.h +64 -0
- package/harmony/flash_list/src/main/cpp/ShadowNodes.cpp +34 -0
- package/harmony/flash_list/src/main/cpp/ShadowNodes.h +48 -0
- package/harmony/flash_list/src/main/ets/Logger.ets +64 -0
- package/harmony/flash_list/src/main/ets/RNAutoLayoutShadow.ets +154 -0
- package/harmony/flash_list/src/main/ets/RNAutoLayoutView.ets +252 -0
- package/harmony/flash_list/src/main/ets/RNCellContainer.ets +113 -0
- package/harmony/flash_list/src/main/module.json5 +7 -0
- package/harmony/flash_list/src/main/resources/base/element/color.json +8 -0
- package/harmony/flash_list/src/main/resources/base/element/string.json +16 -0
- package/harmony/flash_list/src/main/resources/base/media/icon.png +0 -0
- package/harmony/flash_list/src/main/resources/base/profile/main_pages.json +5 -0
- package/harmony/flash_list/src/main/resources/en_US/element/string.json +16 -0
- package/harmony/flash_list/src/main/resources/zh_CN/element/string.json +16 -0
- package/harmony/flash_list.har +0 -0
- package/jestSetup.js +16 -0
- package/package.json +88 -0
- package/src/AnimatedFlashList.ts +11 -0
- package/src/FlashList.tsx +870 -0
- package/src/FlashListProps.ts +335 -0
- package/src/GridLayoutProviderWithProps.ts +180 -0
- package/src/MasonryFlashList.tsx +476 -0
- package/src/PureComponentWrapper.tsx +42 -0
- package/src/__tests__/AverageWindow.test.ts +80 -0
- package/src/__tests__/ContentContainerUtils.test.ts +130 -0
- package/src/__tests__/FlashList.test.tsx +886 -0
- package/src/__tests__/GridLayoutProviderWithProps.test.ts +179 -0
- package/src/__tests__/MasonryFlashList.test.ts +292 -0
- package/src/__tests__/PlatformHelper.web.test.ts +45 -0
- package/src/__tests__/ViewabilityHelper.test.ts +283 -0
- package/src/__tests__/helpers/mountFlashList.tsx +62 -0
- package/src/__tests__/helpers/mountMasonryFlashList.tsx +70 -0
- package/src/__tests__/useBlankAreaTracker.test.tsx +204 -0
- package/src/benchmark/AutoScrollHelper.ts +70 -0
- package/src/benchmark/JSFPSMonitor.ts +74 -0
- package/src/benchmark/roundToDecimalPlaces.ts +4 -0
- package/src/benchmark/useBenchmark.ts +240 -0
- package/src/benchmark/useBlankAreaTracker.ts +117 -0
- package/src/benchmark/useDataMultiplier.ts +19 -0
- package/src/benchmark/useFlatListBenchmark.ts +107 -0
- package/src/errors/CustomError.ts +10 -0
- package/src/errors/ExceptionList.ts +28 -0
- package/src/errors/Warnings.ts +15 -0
- package/src/fabric/AutoLayoutNativeComponent.ts +51 -0
- package/src/fabric/CellContainerNativeComponent.ts +34 -0
- package/src/index.ts +43 -0
- package/src/native/auto-layout/AutoLayoutView.tsx +73 -0
- package/src/native/auto-layout/AutoLayoutViewNativeComponent.android.ts +7 -0
- package/src/native/auto-layout/AutoLayoutViewNativeComponent.harmony.ts +30 -0
- package/src/native/auto-layout/AutoLayoutViewNativeComponent.ios.ts +7 -0
- package/src/native/auto-layout/AutoLayoutViewNativeComponent.ts +7 -0
- package/src/native/auto-layout/AutoLayoutViewNativeComponentProps.ts +17 -0
- package/src/native/cell-container/CellContainer.android.ts +7 -0
- package/src/native/cell-container/CellContainer.harmony.ts +30 -0
- package/src/native/cell-container/CellContainer.ios.ts +6 -0
- package/src/native/cell-container/CellContainer.tsx +14 -0
- package/src/native/cell-container/CellContainer.web.tsx +9 -0
- package/src/native/config/PlatformHelper.android.ts +29 -0
- package/src/native/config/PlatformHelper.harmony.ts +51 -0
- package/src/native/config/PlatformHelper.ios.ts +28 -0
- package/src/native/config/PlatformHelper.ts +29 -0
- package/src/native/config/PlatformHelper.web.ts +34 -0
- package/src/utils/AverageWindow.ts +49 -0
- package/src/utils/ContentContainerUtils.ts +92 -0
- package/src/viewability/ViewToken.ts +7 -0
- package/src/viewability/ViewabilityHelper.ts +162 -0
- package/src/viewability/ViewabilityManager.ts +134 -0
|
@@ -0,0 +1,870 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
RefreshControl,
|
|
5
|
+
LayoutChangeEvent,
|
|
6
|
+
NativeSyntheticEvent,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
NativeScrollEvent,
|
|
9
|
+
} from "react-native";
|
|
10
|
+
import {
|
|
11
|
+
BaseItemAnimator,
|
|
12
|
+
DataProvider,
|
|
13
|
+
ProgressiveListView,
|
|
14
|
+
RecyclerListView,
|
|
15
|
+
RecyclerListViewProps,
|
|
16
|
+
WindowCorrectionConfig,
|
|
17
|
+
} from "recyclerlistview";
|
|
18
|
+
import StickyContainer, { StickyContainerProps } from "recyclerlistview/sticky";
|
|
19
|
+
|
|
20
|
+
import AutoLayoutView from "./native/auto-layout/AutoLayoutView";
|
|
21
|
+
import CellContainer from "./native/cell-container/CellContainer";
|
|
22
|
+
import { PureComponentWrapper } from "./PureComponentWrapper";
|
|
23
|
+
import GridLayoutProviderWithProps from "./GridLayoutProviderWithProps";
|
|
24
|
+
import CustomError from "./errors/CustomError";
|
|
25
|
+
import ExceptionList from "./errors/ExceptionList";
|
|
26
|
+
import WarningList from "./errors/Warnings";
|
|
27
|
+
import ViewabilityManager from "./viewability/ViewabilityManager";
|
|
28
|
+
import {
|
|
29
|
+
FlashListProps,
|
|
30
|
+
RenderTarget,
|
|
31
|
+
RenderTargetOptions,
|
|
32
|
+
} from "./FlashListProps";
|
|
33
|
+
import {
|
|
34
|
+
getCellContainerPlatformStyles,
|
|
35
|
+
getFooterContainer,
|
|
36
|
+
getItemAnimator,
|
|
37
|
+
PlatformConfig,
|
|
38
|
+
} from "./native/config/PlatformHelper";
|
|
39
|
+
import {
|
|
40
|
+
ContentStyleExplicit,
|
|
41
|
+
getContentContainerPadding,
|
|
42
|
+
hasUnsupportedKeysInContentContainerStyle,
|
|
43
|
+
updateContentStyle,
|
|
44
|
+
} from "./utils/ContentContainerUtils";
|
|
45
|
+
|
|
46
|
+
interface StickyProps extends StickyContainerProps {
|
|
47
|
+
children: any;
|
|
48
|
+
}
|
|
49
|
+
const StickyHeaderContainer =
|
|
50
|
+
StickyContainer as React.ComponentClass<StickyProps>;
|
|
51
|
+
|
|
52
|
+
export interface FlashListState<T> {
|
|
53
|
+
dataProvider: DataProvider;
|
|
54
|
+
numColumns: number;
|
|
55
|
+
layoutProvider: GridLayoutProviderWithProps<T>;
|
|
56
|
+
data?: ReadonlyArray<T> | null;
|
|
57
|
+
extraData?: ExtraData<unknown>;
|
|
58
|
+
renderItem?: FlashListProps<T>["renderItem"];
|
|
59
|
+
lastInverted?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface ExtraData<T> {
|
|
63
|
+
value?: T;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
class FlashList<T> extends React.PureComponent<
|
|
67
|
+
FlashListProps<T>,
|
|
68
|
+
FlashListState<T>
|
|
69
|
+
> {
|
|
70
|
+
private rlvRef?: RecyclerListView<RecyclerListViewProps, any>;
|
|
71
|
+
private stickyContentContainerRef?: PureComponentWrapper;
|
|
72
|
+
private listFixedDimensionSize = 0;
|
|
73
|
+
private distanceFromWindow = 0;
|
|
74
|
+
private contentStyle: ContentStyleExplicit = {
|
|
75
|
+
paddingBottom: 0,
|
|
76
|
+
paddingTop: 0,
|
|
77
|
+
paddingLeft: 0,
|
|
78
|
+
paddingRight: 0,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
private loadStartTime = 0;
|
|
82
|
+
private isListLoaded = false;
|
|
83
|
+
private windowCorrectionConfig: WindowCorrectionConfig = {
|
|
84
|
+
value: {
|
|
85
|
+
windowShift: 0,
|
|
86
|
+
startCorrection: 0,
|
|
87
|
+
endCorrection: 0,
|
|
88
|
+
},
|
|
89
|
+
applyToItemScroll: true,
|
|
90
|
+
applyToInitialOffset: true,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
private postLoadTimeoutId?: ReturnType<typeof setTimeout>;
|
|
94
|
+
private itemSizeWarningTimeoutId?: ReturnType<typeof setTimeout>;
|
|
95
|
+
private renderedSizeWarningTimeoutId?: ReturnType<typeof setTimeout>;
|
|
96
|
+
|
|
97
|
+
private isEmptyList = false;
|
|
98
|
+
private viewabilityManager: ViewabilityManager<T>;
|
|
99
|
+
|
|
100
|
+
private itemAnimator?: BaseItemAnimator;
|
|
101
|
+
|
|
102
|
+
static defaultProps = {
|
|
103
|
+
data: [],
|
|
104
|
+
numColumns: 1,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
constructor(props: FlashListProps<T>) {
|
|
108
|
+
super(props);
|
|
109
|
+
this.loadStartTime = Date.now();
|
|
110
|
+
this.validateProps();
|
|
111
|
+
if (props.estimatedListSize) {
|
|
112
|
+
if (props.horizontal) {
|
|
113
|
+
this.listFixedDimensionSize = props.estimatedListSize.height;
|
|
114
|
+
} else {
|
|
115
|
+
this.listFixedDimensionSize = props.estimatedListSize.width;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
this.distanceFromWindow =
|
|
119
|
+
props.estimatedFirstItemOffset ?? ((props.ListHeaderComponent && 1) || 0);
|
|
120
|
+
// eslint-disable-next-line react/state-in-constructor
|
|
121
|
+
this.state = FlashList.getInitialMutableState(this);
|
|
122
|
+
this.viewabilityManager = new ViewabilityManager(this);
|
|
123
|
+
this.itemAnimator = getItemAnimator();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private validateProps() {
|
|
127
|
+
if (this.props.onRefresh && typeof this.props.refreshing !== "boolean") {
|
|
128
|
+
throw new CustomError(ExceptionList.refreshBooleanMissing);
|
|
129
|
+
}
|
|
130
|
+
if (
|
|
131
|
+
Number(this.props.stickyHeaderIndices?.length) > 0 &&
|
|
132
|
+
this.props.horizontal
|
|
133
|
+
) {
|
|
134
|
+
throw new CustomError(ExceptionList.stickyWhileHorizontalNotSupported);
|
|
135
|
+
}
|
|
136
|
+
if (Number(this.props.numColumns) > 1 && this.props.horizontal) {
|
|
137
|
+
throw new CustomError(ExceptionList.columnsWhileHorizontalNotSupported);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// `createAnimatedComponent` always passes a blank style object. To avoid warning while using AnimatedFlashList we've modified the check
|
|
141
|
+
// `style` prop can be an array. So we need to validate every object in array. Check: https://github.com/Shopify/flash-list/issues/651
|
|
142
|
+
if (
|
|
143
|
+
__DEV__ &&
|
|
144
|
+
Object.keys(StyleSheet.flatten(this.props.style ?? {})).length > 0
|
|
145
|
+
) {
|
|
146
|
+
console.warn(WarningList.styleUnsupported);
|
|
147
|
+
}
|
|
148
|
+
if (
|
|
149
|
+
hasUnsupportedKeysInContentContainerStyle(
|
|
150
|
+
this.props.contentContainerStyle
|
|
151
|
+
)
|
|
152
|
+
) {
|
|
153
|
+
console.warn(WarningList.styleContentContainerUnsupported);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Some of the state variables need to update when props change
|
|
158
|
+
static getDerivedStateFromProps<T>(
|
|
159
|
+
nextProps: Readonly<FlashListProps<T>>,
|
|
160
|
+
prevState: FlashListState<T>
|
|
161
|
+
): FlashListState<T> {
|
|
162
|
+
const newState = { ...prevState };
|
|
163
|
+
if (prevState.numColumns !== nextProps.numColumns) {
|
|
164
|
+
newState.numColumns = nextProps.numColumns || 1;
|
|
165
|
+
newState.layoutProvider = FlashList.getLayoutProvider<T>(
|
|
166
|
+
newState.numColumns,
|
|
167
|
+
nextProps
|
|
168
|
+
);
|
|
169
|
+
} else if (prevState.layoutProvider.updateProps(nextProps).hasExpired) {
|
|
170
|
+
newState.layoutProvider = FlashList.getLayoutProvider<T>(
|
|
171
|
+
newState.numColumns,
|
|
172
|
+
nextProps
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// RLV retries to reposition the first visible item on layout provider change.
|
|
177
|
+
// It's not required in our case so we're disabling it
|
|
178
|
+
newState.layoutProvider.shouldRefreshWithAnchoring = Boolean(
|
|
179
|
+
!prevState.layoutProvider?.hasExpired
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
if (nextProps.data !== prevState.data || prevState.lastInverted !== nextProps.inverted) {
|
|
183
|
+
const processedData = nextProps.inverted
|
|
184
|
+
? (nextProps.data ? [...nextProps.data].reverse() : nextProps.data)
|
|
185
|
+
: nextProps.data;
|
|
186
|
+
newState.data = processedData;
|
|
187
|
+
newState.dataProvider = prevState.dataProvider.cloneWithRows(
|
|
188
|
+
processedData as any[]
|
|
189
|
+
);
|
|
190
|
+
if (nextProps.renderItem !== prevState.renderItem) {
|
|
191
|
+
newState.extraData = { ...prevState.extraData };
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (nextProps.extraData !== prevState.extraData?.value) {
|
|
195
|
+
newState.extraData = { value: nextProps.extraData };
|
|
196
|
+
}
|
|
197
|
+
newState.renderItem = nextProps.renderItem;
|
|
198
|
+
newState.lastInverted = nextProps.inverted ?? undefined;
|
|
199
|
+
return newState;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private static getInitialMutableState<T>(
|
|
203
|
+
flashList: FlashList<T>
|
|
204
|
+
): FlashListState<T> {
|
|
205
|
+
let getStableId: ((index: number) => string) | undefined;
|
|
206
|
+
if (
|
|
207
|
+
flashList.props.keyExtractor !== null &&
|
|
208
|
+
flashList.props.keyExtractor !== undefined
|
|
209
|
+
) {
|
|
210
|
+
getStableId = (index) =>
|
|
211
|
+
// We assume `keyExtractor` function will never change from being `null | undefined` to defined and vice versa.
|
|
212
|
+
// Similarly, data should never be `null | undefined` when `getStableId` is called.
|
|
213
|
+
flashList.props.keyExtractor!(
|
|
214
|
+
flashList.props.data![index],
|
|
215
|
+
index
|
|
216
|
+
).toString();
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
data: null,
|
|
220
|
+
layoutProvider: null!!,
|
|
221
|
+
dataProvider: new DataProvider((r1, r2) => {
|
|
222
|
+
return r1 !== r2;
|
|
223
|
+
}, getStableId),
|
|
224
|
+
numColumns: 0,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Using only grid layout provider as it can also act as a listview, sizeProvider is a function to support future overrides
|
|
229
|
+
private static getLayoutProvider<T>(
|
|
230
|
+
numColumns: number,
|
|
231
|
+
flashListProps: FlashListProps<T>
|
|
232
|
+
) {
|
|
233
|
+
return new GridLayoutProviderWithProps<T>(
|
|
234
|
+
// max span or, total columns
|
|
235
|
+
numColumns,
|
|
236
|
+
(index, props) => {
|
|
237
|
+
// type of the item for given index
|
|
238
|
+
const type = props.getItemType?.(
|
|
239
|
+
props.data!![index],
|
|
240
|
+
index,
|
|
241
|
+
props.extraData
|
|
242
|
+
);
|
|
243
|
+
return type || 0;
|
|
244
|
+
},
|
|
245
|
+
(index, props, mutableLayout) => {
|
|
246
|
+
// span of the item at given index, item can choose to span more than one column
|
|
247
|
+
props.overrideItemLayout?.(
|
|
248
|
+
mutableLayout,
|
|
249
|
+
props.data!![index],
|
|
250
|
+
index,
|
|
251
|
+
numColumns,
|
|
252
|
+
props.extraData
|
|
253
|
+
);
|
|
254
|
+
return mutableLayout?.span ?? 1;
|
|
255
|
+
},
|
|
256
|
+
(index, props, mutableLayout) => {
|
|
257
|
+
// estimated size of the item an given index
|
|
258
|
+
props.overrideItemLayout?.(
|
|
259
|
+
mutableLayout,
|
|
260
|
+
props.data!![index],
|
|
261
|
+
index,
|
|
262
|
+
numColumns,
|
|
263
|
+
props.extraData
|
|
264
|
+
);
|
|
265
|
+
return mutableLayout?.size;
|
|
266
|
+
},
|
|
267
|
+
flashListProps
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
private onEndReached = () => {
|
|
272
|
+
this.props.onEndReached?.();
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
private getRefreshControl = () => {
|
|
276
|
+
if (this.props.onRefresh) {
|
|
277
|
+
return (
|
|
278
|
+
<RefreshControl
|
|
279
|
+
refreshing={Boolean(this.props.refreshing)}
|
|
280
|
+
progressViewOffset={this.props.progressViewOffset}
|
|
281
|
+
onRefresh={this.props.onRefresh}
|
|
282
|
+
/>
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
componentDidMount() {
|
|
288
|
+
if (this.props.data?.length === 0) {
|
|
289
|
+
this.raiseOnLoadEventIfNeeded();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
componentWillUnmount() {
|
|
294
|
+
this.viewabilityManager.dispose();
|
|
295
|
+
this.clearPostLoadTimeout();
|
|
296
|
+
this.clearRenderSizeWarningTimeout();
|
|
297
|
+
if (this.itemSizeWarningTimeoutId !== undefined) {
|
|
298
|
+
clearTimeout(this.itemSizeWarningTimeoutId);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
render() {
|
|
303
|
+
this.isEmptyList = this.state.dataProvider.getSize() === 0;
|
|
304
|
+
updateContentStyle(this.contentStyle, this.props.contentContainerStyle);
|
|
305
|
+
|
|
306
|
+
const {
|
|
307
|
+
drawDistance,
|
|
308
|
+
removeClippedSubviews,
|
|
309
|
+
stickyHeaderIndices,
|
|
310
|
+
horizontal,
|
|
311
|
+
onEndReachedThreshold,
|
|
312
|
+
estimatedListSize,
|
|
313
|
+
initialScrollIndex,
|
|
314
|
+
style,
|
|
315
|
+
contentContainerStyle,
|
|
316
|
+
renderScrollComponent,
|
|
317
|
+
...restProps
|
|
318
|
+
} = this.props;
|
|
319
|
+
|
|
320
|
+
// RecyclerListView simply ignores if initialScrollIndex is set to 0 because it doesn't understand headers
|
|
321
|
+
// Using initialOffset to force RLV to scroll to the right place
|
|
322
|
+
const initialOffset =
|
|
323
|
+
(this.isInitialScrollIndexInFirstRow() && this.distanceFromWindow) ||
|
|
324
|
+
undefined;
|
|
325
|
+
const finalDrawDistance =
|
|
326
|
+
drawDistance === undefined
|
|
327
|
+
? PlatformConfig.defaultDrawDistance
|
|
328
|
+
: drawDistance;
|
|
329
|
+
|
|
330
|
+
return (
|
|
331
|
+
<StickyHeaderContainer
|
|
332
|
+
overrideRowRenderer={this.stickyOverrideRowRenderer}
|
|
333
|
+
applyWindowCorrection={this.applyWindowCorrection}
|
|
334
|
+
stickyHeaderIndices={stickyHeaderIndices}
|
|
335
|
+
style={
|
|
336
|
+
this.props.horizontal
|
|
337
|
+
? { }
|
|
338
|
+
: { flex: 1, overflow: "hidden" }
|
|
339
|
+
}
|
|
340
|
+
>
|
|
341
|
+
<ProgressiveListView
|
|
342
|
+
{...restProps}
|
|
343
|
+
ref={this.recyclerRef}
|
|
344
|
+
layoutProvider={this.state.layoutProvider}
|
|
345
|
+
dataProvider={this.state.dataProvider}
|
|
346
|
+
rowRenderer={this.emptyRowRenderer}
|
|
347
|
+
canChangeSize
|
|
348
|
+
isHorizontal={Boolean(horizontal)}
|
|
349
|
+
scrollViewProps={{
|
|
350
|
+
onScrollBeginDrag: this.onScrollBeginDrag,
|
|
351
|
+
onLayout: this.handleSizeChange,
|
|
352
|
+
refreshControl:
|
|
353
|
+
this.props.refreshControl || this.getRefreshControl(),
|
|
354
|
+
|
|
355
|
+
// Min values are being used to suppress RLV's bounded exception
|
|
356
|
+
style: { minHeight: 1, minWidth: 1 },
|
|
357
|
+
contentContainerStyle: {
|
|
358
|
+
backgroundColor: this.contentStyle.backgroundColor,
|
|
359
|
+
|
|
360
|
+
// Required to handle a scrollview bug. Check: https://github.com/Shopify/flash-list/pull/187
|
|
361
|
+
minHeight: 1,
|
|
362
|
+
minWidth: 1,
|
|
363
|
+
|
|
364
|
+
...getContentContainerPadding(this.contentStyle, horizontal),
|
|
365
|
+
},
|
|
366
|
+
...this.props.overrideProps,
|
|
367
|
+
}}
|
|
368
|
+
forceNonDeterministicRendering
|
|
369
|
+
renderItemContainer={this.itemContainer}
|
|
370
|
+
renderContentContainer={this.container}
|
|
371
|
+
onEndReached={this.onEndReached}
|
|
372
|
+
onEndReachedThresholdRelative={onEndReachedThreshold || undefined}
|
|
373
|
+
extendedState={this.state.extraData}
|
|
374
|
+
layoutSize={estimatedListSize}
|
|
375
|
+
maxRenderAhead={3 * finalDrawDistance}
|
|
376
|
+
finalRenderAheadOffset={finalDrawDistance}
|
|
377
|
+
renderAheadStep={finalDrawDistance}
|
|
378
|
+
initialRenderIndex={
|
|
379
|
+
(!this.isInitialScrollIndexInFirstRow() && initialScrollIndex) ||
|
|
380
|
+
undefined
|
|
381
|
+
}
|
|
382
|
+
initialOffset={initialOffset}
|
|
383
|
+
onItemLayout={this.onItemLayout}
|
|
384
|
+
onScroll={this.onScroll}
|
|
385
|
+
onVisibleIndicesChanged={
|
|
386
|
+
this.viewabilityManager.shouldListenToVisibleIndices
|
|
387
|
+
? this.viewabilityManager.onVisibleIndicesChanged
|
|
388
|
+
: undefined
|
|
389
|
+
}
|
|
390
|
+
windowCorrectionConfig={this.getUpdatedWindowCorrectionConfig()}
|
|
391
|
+
itemAnimator={this.itemAnimator}
|
|
392
|
+
suppressBoundedSizeException
|
|
393
|
+
externalScrollView={
|
|
394
|
+
renderScrollComponent as RecyclerListViewProps["externalScrollView"]
|
|
395
|
+
}
|
|
396
|
+
/>
|
|
397
|
+
</StickyHeaderContainer>
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
private onScrollBeginDrag = (
|
|
402
|
+
event: NativeSyntheticEvent<NativeScrollEvent>
|
|
403
|
+
) => {
|
|
404
|
+
this.recordInteraction();
|
|
405
|
+
this.props.onScrollBeginDrag?.(event);
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
private onScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
409
|
+
this.recordInteraction();
|
|
410
|
+
this.viewabilityManager.updateViewableItems();
|
|
411
|
+
this.props.onScroll?.(event);
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
private getUpdatedWindowCorrectionConfig() {
|
|
415
|
+
// If the initial scroll index is in the first row then we're forcing RLV to use initialOffset and thus we need to disable window correction
|
|
416
|
+
// This isn't clean but it's the only way to get RLV to scroll to the right place
|
|
417
|
+
// TODO: Remove this when RLV fixes this. Current implementation will also fail if column span is overridden in the first row.
|
|
418
|
+
if (this.isInitialScrollIndexInFirstRow()) {
|
|
419
|
+
this.windowCorrectionConfig.applyToInitialOffset = false;
|
|
420
|
+
} else {
|
|
421
|
+
this.windowCorrectionConfig.applyToInitialOffset = true;
|
|
422
|
+
}
|
|
423
|
+
this.windowCorrectionConfig.value.windowShift = -this.distanceFromWindow;
|
|
424
|
+
return this.windowCorrectionConfig;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
private isInitialScrollIndexInFirstRow() {
|
|
428
|
+
return (
|
|
429
|
+
(this.props.initialScrollIndex ?? this.state.numColumns) <
|
|
430
|
+
this.state.numColumns
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
private validateListSize(event: LayoutChangeEvent) {
|
|
435
|
+
const { height, width } = event.nativeEvent.layout;
|
|
436
|
+
this.clearRenderSizeWarningTimeout();
|
|
437
|
+
if (Math.floor(height) <= 1 || Math.floor(width) <= 1) {
|
|
438
|
+
this.renderedSizeWarningTimeoutId = setTimeout(() => {
|
|
439
|
+
console.warn(WarningList.unusableRenderedSize);
|
|
440
|
+
}, 1000);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
private handleSizeChange = (event: LayoutChangeEvent) => {
|
|
445
|
+
this.validateListSize(event);
|
|
446
|
+
const newSize = this.props.horizontal
|
|
447
|
+
? event.nativeEvent.layout.height
|
|
448
|
+
: event.nativeEvent.layout.width;
|
|
449
|
+
const oldSize = this.listFixedDimensionSize;
|
|
450
|
+
this.listFixedDimensionSize = newSize;
|
|
451
|
+
|
|
452
|
+
// >0 check is to avoid rerender on mount where it would be redundant
|
|
453
|
+
if (oldSize > 0 && oldSize !== newSize) {
|
|
454
|
+
this.rlvRef?.forceRerender();
|
|
455
|
+
}
|
|
456
|
+
if (this.props.onLayout) {
|
|
457
|
+
this.props.onLayout(event);
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
private container = (props: object, children: React.ReactNode[]) => {
|
|
462
|
+
this.clearPostLoadTimeout();
|
|
463
|
+
return (
|
|
464
|
+
<>
|
|
465
|
+
<PureComponentWrapper
|
|
466
|
+
enabled={this.isListLoaded || children.length > 0 || this.isEmptyList}
|
|
467
|
+
contentStyle={this.props.contentContainerStyle}
|
|
468
|
+
horizontal={this.props.horizontal}
|
|
469
|
+
header={this.props.ListHeaderComponent}
|
|
470
|
+
extraData={this.state.extraData}
|
|
471
|
+
headerStyle={this.props.ListHeaderComponentStyle}
|
|
472
|
+
inverted={this.props.inverted}
|
|
473
|
+
renderer={this.header}
|
|
474
|
+
/>
|
|
475
|
+
<AutoLayoutView
|
|
476
|
+
{...props}
|
|
477
|
+
onBlankAreaEvent={this.props.onBlankArea}
|
|
478
|
+
onLayout={this.updateDistanceFromWindow}
|
|
479
|
+
disableAutoLayout={this.props.disableAutoLayout}
|
|
480
|
+
>
|
|
481
|
+
{children}
|
|
482
|
+
</AutoLayoutView>
|
|
483
|
+
{this.isEmptyList
|
|
484
|
+
? this.getValidComponent(this.props.ListEmptyComponent)
|
|
485
|
+
: null}
|
|
486
|
+
<PureComponentWrapper
|
|
487
|
+
enabled={this.isListLoaded || children.length > 0 || this.isEmptyList}
|
|
488
|
+
contentStyle={this.props.contentContainerStyle}
|
|
489
|
+
horizontal={this.props.horizontal}
|
|
490
|
+
header={this.props.ListFooterComponent}
|
|
491
|
+
extraData={this.state.extraData}
|
|
492
|
+
headerStyle={this.props.ListFooterComponentStyle}
|
|
493
|
+
inverted={this.props.inverted}
|
|
494
|
+
renderer={this.footer}
|
|
495
|
+
/>
|
|
496
|
+
{this.getComponentForHeightMeasurement()}
|
|
497
|
+
</>
|
|
498
|
+
);
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
private itemContainer = (props: any, parentProps: any) => {
|
|
502
|
+
const CellRendererComponent =
|
|
503
|
+
this.props.CellRendererComponent ?? CellContainer;
|
|
504
|
+
return (
|
|
505
|
+
<CellRendererComponent
|
|
506
|
+
{...props}
|
|
507
|
+
style={{
|
|
508
|
+
...props.style,
|
|
509
|
+
flexDirection: this.props.horizontal ? "row" : "column",
|
|
510
|
+
alignItems: "stretch",
|
|
511
|
+
...getCellContainerPlatformStyles(this.props.inverted!!, parentProps),
|
|
512
|
+
}}
|
|
513
|
+
index={parentProps.index}
|
|
514
|
+
>
|
|
515
|
+
<PureComponentWrapper
|
|
516
|
+
extendedState={parentProps.extendedState}
|
|
517
|
+
internalSnapshot={parentProps.internalSnapshot}
|
|
518
|
+
data={parentProps.data}
|
|
519
|
+
arg={parentProps.index}
|
|
520
|
+
renderer={this.getCellContainerChild}
|
|
521
|
+
/>
|
|
522
|
+
</CellRendererComponent>
|
|
523
|
+
);
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
private updateDistanceFromWindow = (event: LayoutChangeEvent) => {
|
|
527
|
+
const newDistanceFromWindow = this.props.horizontal
|
|
528
|
+
? event.nativeEvent.layout.x
|
|
529
|
+
: event.nativeEvent.layout.y;
|
|
530
|
+
|
|
531
|
+
if (this.distanceFromWindow !== newDistanceFromWindow) {
|
|
532
|
+
this.distanceFromWindow = newDistanceFromWindow;
|
|
533
|
+
this.windowCorrectionConfig.value.windowShift = -this.distanceFromWindow;
|
|
534
|
+
this.viewabilityManager.updateViewableItems();
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
private separator = (index: number) => {
|
|
541
|
+
// Make sure we have data and don't read out of bounds
|
|
542
|
+
if (
|
|
543
|
+
this.props.data === null ||
|
|
544
|
+
this.props.data === undefined ||
|
|
545
|
+
index + 1 >= this.props.data.length
|
|
546
|
+
) {
|
|
547
|
+
return null;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
const leadingItem = this.props.data[index];
|
|
551
|
+
const trailingItem = this.props.data[index + 1];
|
|
552
|
+
|
|
553
|
+
const props = {
|
|
554
|
+
leadingItem,
|
|
555
|
+
trailingItem,
|
|
556
|
+
// TODO: Missing sections as we don't have this feature implemented yet. Implement section, leadingSection and trailingSection.
|
|
557
|
+
// https://github.com/facebook/react-native/blob/8bd3edec88148d0ab1f225d2119435681fbbba33/Libraries/Lists/VirtualizedSectionList.js#L285-L294
|
|
558
|
+
};
|
|
559
|
+
const Separator = this.props.ItemSeparatorComponent;
|
|
560
|
+
return Separator && <Separator {...props} />;
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
private header = () => {
|
|
564
|
+
return (
|
|
565
|
+
<>
|
|
566
|
+
<View
|
|
567
|
+
style={{
|
|
568
|
+
paddingTop: this.contentStyle.paddingTop,
|
|
569
|
+
paddingLeft: this.contentStyle.paddingLeft,
|
|
570
|
+
}}
|
|
571
|
+
/>
|
|
572
|
+
|
|
573
|
+
<View
|
|
574
|
+
style={[this.props.ListHeaderComponentStyle]}
|
|
575
|
+
>
|
|
576
|
+
{this.getValidComponent(this.props.ListHeaderComponent)}
|
|
577
|
+
</View>
|
|
578
|
+
</>
|
|
579
|
+
);
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
private footer = () => {
|
|
583
|
+
/** The web version of CellContainer uses a div directly which doesn't compose styles the way a View does.
|
|
584
|
+
* We will skip using CellContainer on web to avoid this issue. `getFooterContainer` on web will
|
|
585
|
+
* return a View. */
|
|
586
|
+
const FooterContainer = getFooterContainer() ?? CellContainer;
|
|
587
|
+
return (
|
|
588
|
+
<>
|
|
589
|
+
<FooterContainer
|
|
590
|
+
index={-1}
|
|
591
|
+
style={[this.props.ListFooterComponentStyle]}
|
|
592
|
+
>
|
|
593
|
+
{this.getValidComponent(this.props.ListFooterComponent)}
|
|
594
|
+
</FooterContainer>
|
|
595
|
+
<View
|
|
596
|
+
style={{
|
|
597
|
+
paddingBottom: this.contentStyle.paddingBottom,
|
|
598
|
+
paddingRight: this.contentStyle.paddingRight,
|
|
599
|
+
}}
|
|
600
|
+
/>
|
|
601
|
+
</>
|
|
602
|
+
);
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
private getComponentForHeightMeasurement = () => {
|
|
606
|
+
return this.props.horizontal &&
|
|
607
|
+
!this.props.disableHorizontalListHeightMeasurement &&
|
|
608
|
+
!this.isListLoaded &&
|
|
609
|
+
this.state.dataProvider.getSize() > 0 ? (
|
|
610
|
+
<View style={{ opacity: 0 }} pointerEvents="none">
|
|
611
|
+
{this.rowRendererWithIndex(
|
|
612
|
+
Math.min(this.state.dataProvider.getSize() - 1, 1),
|
|
613
|
+
RenderTargetOptions.Measurement
|
|
614
|
+
)}
|
|
615
|
+
</View>
|
|
616
|
+
) : null;
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
private getValidComponent(
|
|
620
|
+
component: React.ComponentType | React.ReactElement | null | undefined
|
|
621
|
+
) {
|
|
622
|
+
const PassedComponent = component;
|
|
623
|
+
return (
|
|
624
|
+
(React.isValidElement(PassedComponent) && PassedComponent) ||
|
|
625
|
+
(PassedComponent && <PassedComponent />) ||
|
|
626
|
+
null
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
private applyWindowCorrection = (
|
|
631
|
+
_: any,
|
|
632
|
+
__: any,
|
|
633
|
+
correctionObject: { windowShift: number }
|
|
634
|
+
) => {
|
|
635
|
+
correctionObject.windowShift = -this.distanceFromWindow;
|
|
636
|
+
this.stickyContentContainerRef?.setEnabled(this.isStickyEnabled);
|
|
637
|
+
};
|
|
638
|
+
|
|
639
|
+
private rowRendererSticky = (index: number) => {
|
|
640
|
+
return this.rowRendererWithIndex(index, RenderTargetOptions.StickyHeader);
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
private rowRendererWithIndex = (index: number, target: RenderTarget) => {
|
|
644
|
+
// known issue: expected to pass separators which isn't available in RLV
|
|
645
|
+
return this.props.renderItem?.({
|
|
646
|
+
item: this.state.data![index],
|
|
647
|
+
index,
|
|
648
|
+
target,
|
|
649
|
+
extraData: this.state.extraData?.value,
|
|
650
|
+
}) as React.ReactElement;
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* This will prevent render item calls unless data changes.
|
|
655
|
+
* Output of this method is received as children object so returning null here is no issue as long as we handle it inside our child container.
|
|
656
|
+
* @module getCellContainerChild acts as the new rowRenderer and is called directly from our child container.
|
|
657
|
+
*/
|
|
658
|
+
private emptyRowRenderer = () => {
|
|
659
|
+
return null;
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
private getCellContainerChild = (index: number) => {
|
|
663
|
+
return (
|
|
664
|
+
<>
|
|
665
|
+
{this.props.inverted ? this.separator(index) : null}
|
|
666
|
+
<View
|
|
667
|
+
style={{
|
|
668
|
+
flexDirection:
|
|
669
|
+
this.props.horizontal || this.props.numColumns === 1
|
|
670
|
+
? "column"
|
|
671
|
+
: "row",
|
|
672
|
+
}}
|
|
673
|
+
>
|
|
674
|
+
{this.rowRendererWithIndex(index, RenderTargetOptions.Cell)}
|
|
675
|
+
</View>
|
|
676
|
+
{this.separator(index)}
|
|
677
|
+
</>
|
|
678
|
+
);
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
private recyclerRef = (ref: any) => {
|
|
682
|
+
this.rlvRef = ref;
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
private stickyContentRef = (ref: any) => {
|
|
686
|
+
this.stickyContentContainerRef = ref;
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
private stickyOverrideRowRenderer = (
|
|
690
|
+
_: any,
|
|
691
|
+
__: any,
|
|
692
|
+
index: number,
|
|
693
|
+
___: any
|
|
694
|
+
) => {
|
|
695
|
+
return (
|
|
696
|
+
<PureComponentWrapper
|
|
697
|
+
ref={this.stickyContentRef}
|
|
698
|
+
enabled={this.isStickyEnabled}
|
|
699
|
+
arg={index}
|
|
700
|
+
renderer={this.rowRendererSticky}
|
|
701
|
+
/>
|
|
702
|
+
);
|
|
703
|
+
};
|
|
704
|
+
|
|
705
|
+
private get isStickyEnabled() {
|
|
706
|
+
const currentOffset = this.rlvRef?.getCurrentScrollOffset() || 0;
|
|
707
|
+
return currentOffset >= this.distanceFromWindow;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
private onItemLayout = (index: number) => {
|
|
711
|
+
// Informing the layout provider about change to an item's layout. It already knows the dimensions so there's not need to pass them.
|
|
712
|
+
this.state.layoutProvider.reportItemLayout(index);
|
|
713
|
+
this.raiseOnLoadEventIfNeeded();
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
private raiseOnLoadEventIfNeeded = () => {
|
|
717
|
+
if (!this.isListLoaded) {
|
|
718
|
+
this.isListLoaded = true;
|
|
719
|
+
this.props.onLoad?.({
|
|
720
|
+
elapsedTimeInMs: Date.now() - this.loadStartTime,
|
|
721
|
+
});
|
|
722
|
+
this.runAfterOnLoad();
|
|
723
|
+
}
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
private runAfterOnLoad = () => {
|
|
727
|
+
if (this.props.estimatedItemSize === undefined) {
|
|
728
|
+
this.itemSizeWarningTimeoutId = setTimeout(() => {
|
|
729
|
+
const averageItemSize = Math.floor(
|
|
730
|
+
this.state.layoutProvider.averageItemSize
|
|
731
|
+
);
|
|
732
|
+
console.warn(
|
|
733
|
+
WarningList.estimatedItemSizeMissingWarning.replace(
|
|
734
|
+
"@size",
|
|
735
|
+
averageItemSize.toString()
|
|
736
|
+
)
|
|
737
|
+
);
|
|
738
|
+
}, 1000);
|
|
739
|
+
}
|
|
740
|
+
this.postLoadTimeoutId = setTimeout(() => {
|
|
741
|
+
// This force update is required to remove dummy element rendered to measure horizontal list height when the list doesn't update on its own.
|
|
742
|
+
// In most cases this timeout will never be triggered because list usually updates atleast once and this timeout is cleared on update.
|
|
743
|
+
if (this.props.horizontal) {
|
|
744
|
+
this.forceUpdate();
|
|
745
|
+
}
|
|
746
|
+
}, 500);
|
|
747
|
+
};
|
|
748
|
+
|
|
749
|
+
private clearPostLoadTimeout = () => {
|
|
750
|
+
if (this.postLoadTimeoutId !== undefined) {
|
|
751
|
+
clearTimeout(this.postLoadTimeoutId);
|
|
752
|
+
this.postLoadTimeoutId = undefined;
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
private clearRenderSizeWarningTimeout = () => {
|
|
757
|
+
if (this.renderedSizeWarningTimeoutId !== undefined) {
|
|
758
|
+
clearTimeout(this.renderedSizeWarningTimeoutId);
|
|
759
|
+
this.renderedSizeWarningTimeoutId = undefined;
|
|
760
|
+
}
|
|
761
|
+
};
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* Disables recycling for the next frame so that layout animations run well.
|
|
765
|
+
* Warning: Avoid this when making large changes to the data as the list might draw too much to run animations. Single item insertions/deletions
|
|
766
|
+
* should be good. With recycling paused the list cannot do much optimization.
|
|
767
|
+
* The next render will run as normal and reuse items.
|
|
768
|
+
*/
|
|
769
|
+
public prepareForLayoutAnimationRender(): void {
|
|
770
|
+
if (
|
|
771
|
+
this.props.keyExtractor === null ||
|
|
772
|
+
this.props.keyExtractor === undefined
|
|
773
|
+
) {
|
|
774
|
+
console.warn(WarningList.missingKeyExtractor);
|
|
775
|
+
} else {
|
|
776
|
+
this.rlvRef?.prepareForLayoutAnimationRender();
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
public scrollToEnd(params?: { animated?: boolean | null | undefined }) {
|
|
781
|
+
this.rlvRef?.scrollToEnd(Boolean(params?.animated));
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
public scrollToIndex(params: {
|
|
785
|
+
animated?: boolean | null | undefined;
|
|
786
|
+
index: number;
|
|
787
|
+
viewOffset?: number | undefined;
|
|
788
|
+
viewPosition?: number | undefined;
|
|
789
|
+
}) {
|
|
790
|
+
const layout = this.rlvRef?.getLayout(params.index);
|
|
791
|
+
const listSize = this.rlvRef?.getRenderedSize();
|
|
792
|
+
|
|
793
|
+
if (layout && listSize) {
|
|
794
|
+
const itemOffset = this.props.horizontal ? layout.x : layout.y;
|
|
795
|
+
const fixedDimension = this.props.horizontal
|
|
796
|
+
? listSize.width
|
|
797
|
+
: listSize.height;
|
|
798
|
+
const itemSize = this.props.horizontal ? layout.width : layout.height;
|
|
799
|
+
const scrollOffset =
|
|
800
|
+
Math.max(
|
|
801
|
+
0,
|
|
802
|
+
itemOffset - (params.viewPosition ?? 0) * (fixedDimension - itemSize)
|
|
803
|
+
) - (params.viewOffset ?? 0);
|
|
804
|
+
this.rlvRef?.scrollToOffset(
|
|
805
|
+
scrollOffset,
|
|
806
|
+
scrollOffset,
|
|
807
|
+
Boolean(params.animated),
|
|
808
|
+
true
|
|
809
|
+
);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
public scrollToItem(params: {
|
|
814
|
+
animated?: boolean | null | undefined;
|
|
815
|
+
item: any;
|
|
816
|
+
viewPosition?: number | undefined;
|
|
817
|
+
viewOffset?: number | undefined;
|
|
818
|
+
}) {
|
|
819
|
+
const index = this.props.data?.indexOf(params.item) ?? -1;
|
|
820
|
+
if (index >= 0) {
|
|
821
|
+
this.scrollToIndex({ ...params, index });
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
public scrollToOffset(params: {
|
|
826
|
+
animated?: boolean | null | undefined;
|
|
827
|
+
offset: number;
|
|
828
|
+
}) {
|
|
829
|
+
const x = this.props.horizontal ? params.offset : 0;
|
|
830
|
+
const y = this.props.horizontal ? 0 : params.offset;
|
|
831
|
+
this.rlvRef?.scrollToOffset(x, y, Boolean(params.animated));
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
public getScrollableNode(): number | null {
|
|
835
|
+
return this.rlvRef?.getScrollableNode?.() || null;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* Allows access to internal recyclerlistview. This is useful for enabling access to its public APIs.
|
|
840
|
+
* Warning: We may swap recyclerlistview for something else in the future. Use with caution.
|
|
841
|
+
*/
|
|
842
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
843
|
+
public get recyclerlistview_unsafe() {
|
|
844
|
+
return this.rlvRef;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* Specifies how far the first item is from top of the list. This would normally be a sum of header size and top/left padding applied to the list.
|
|
849
|
+
*/
|
|
850
|
+
public get firstItemOffset() {
|
|
851
|
+
return this.distanceFromWindow;
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* FlashList will skip using layout cache on next update. Can be useful when you know the layout will change drastically for example, orientation change when used as a carousel.
|
|
856
|
+
*/
|
|
857
|
+
public clearLayoutCacheOnUpdate() {
|
|
858
|
+
this.state.layoutProvider.markExpired();
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* Tells the list an interaction has occurred, which should trigger viewability calculations, e.g. if waitForInteractions is true and the user has not scrolled.
|
|
863
|
+
* This is typically called by taps on items or by navigation actions.
|
|
864
|
+
*/
|
|
865
|
+
public recordInteraction = () => {
|
|
866
|
+
this.viewabilityManager.recordInteraction();
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
export default FlashList;
|