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