@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,162 @@
|
|
|
1
|
+
import { ViewabilityConfig } from "react-native";
|
|
2
|
+
import { Dimension, Layout } from "recyclerlistview";
|
|
3
|
+
|
|
4
|
+
import CustomError from "../errors/CustomError";
|
|
5
|
+
import ExceptionList from "../errors/ExceptionList";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Helper class for computing viewable items based on the passed `viewabilityConfig`.
|
|
9
|
+
* Note methods in this class will be invoked on every scroll and should be optimized for performance.
|
|
10
|
+
*/
|
|
11
|
+
class ViewabilityHelper {
|
|
12
|
+
/**
|
|
13
|
+
* Viewable indices regardless of the viewability config
|
|
14
|
+
*/
|
|
15
|
+
possiblyViewableIndices: number[] = [];
|
|
16
|
+
|
|
17
|
+
hasInteracted = false;
|
|
18
|
+
|
|
19
|
+
private viewableIndices: number[] = [];
|
|
20
|
+
private lastReportedViewableIndices: number[] = [];
|
|
21
|
+
|
|
22
|
+
private viewabilityConfig: ViewabilityConfig | null | undefined;
|
|
23
|
+
private viewableIndicesChanged: (
|
|
24
|
+
indices: number[],
|
|
25
|
+
newlyVisibleIndicies: number[],
|
|
26
|
+
newlyNonvisibleIndices: number[]
|
|
27
|
+
) => void;
|
|
28
|
+
|
|
29
|
+
private timers: Set<NodeJS.Timeout> = new Set();
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
viewabilityConfig: ViewabilityConfig | null | undefined,
|
|
33
|
+
viewableIndicesChanged: (
|
|
34
|
+
indices: number[],
|
|
35
|
+
newlyVisibleIndicies: number[],
|
|
36
|
+
newlyNonvisibleIndices: number[]
|
|
37
|
+
) => void
|
|
38
|
+
) {
|
|
39
|
+
this.viewabilityConfig = viewabilityConfig;
|
|
40
|
+
this.viewableIndicesChanged = viewableIndicesChanged;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public dispose() {
|
|
44
|
+
// Clean up on dismount
|
|
45
|
+
this.timers.forEach(clearTimeout);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public updateViewableItems(
|
|
49
|
+
horizontal: boolean,
|
|
50
|
+
scrollOffset: number,
|
|
51
|
+
listSize: Dimension,
|
|
52
|
+
getLayout: (index: number) => Layout | undefined,
|
|
53
|
+
viewableIndices?: number[]
|
|
54
|
+
) {
|
|
55
|
+
if (viewableIndices !== undefined) {
|
|
56
|
+
this.possiblyViewableIndices = viewableIndices;
|
|
57
|
+
}
|
|
58
|
+
if (
|
|
59
|
+
this.viewabilityConfig?.itemVisiblePercentThreshold !== null &&
|
|
60
|
+
this.viewabilityConfig?.itemVisiblePercentThreshold !== undefined &&
|
|
61
|
+
this.viewabilityConfig?.viewAreaCoveragePercentThreshold !== null &&
|
|
62
|
+
this.viewabilityConfig?.viewAreaCoveragePercentThreshold !== undefined
|
|
63
|
+
) {
|
|
64
|
+
throw new CustomError(
|
|
65
|
+
ExceptionList.multipleViewabilityThresholdTypesNotSupported
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
if (
|
|
69
|
+
(this.viewabilityConfig?.waitForInteraction ?? false) &&
|
|
70
|
+
!this.hasInteracted
|
|
71
|
+
) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const newViewableIndices = this.possiblyViewableIndices.filter((index) =>
|
|
75
|
+
this.isItemViewable(
|
|
76
|
+
index,
|
|
77
|
+
horizontal,
|
|
78
|
+
scrollOffset,
|
|
79
|
+
listSize,
|
|
80
|
+
this.viewabilityConfig?.viewAreaCoveragePercentThreshold,
|
|
81
|
+
this.viewabilityConfig?.itemVisiblePercentThreshold,
|
|
82
|
+
getLayout
|
|
83
|
+
)
|
|
84
|
+
);
|
|
85
|
+
this.viewableIndices = newViewableIndices;
|
|
86
|
+
const minimumViewTime = this.viewabilityConfig?.minimumViewTime ?? 250;
|
|
87
|
+
// Setting default to 250. Default of 0 can impact performance when user scrolls fast.
|
|
88
|
+
if (minimumViewTime > 0) {
|
|
89
|
+
const timeoutId = setTimeout(() => {
|
|
90
|
+
this.timers.delete(timeoutId);
|
|
91
|
+
this.checkViewableIndicesChanges(newViewableIndices);
|
|
92
|
+
this.timers.add(timeoutId);
|
|
93
|
+
}, minimumViewTime);
|
|
94
|
+
} else {
|
|
95
|
+
this.checkViewableIndicesChanges(newViewableIndices);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public checkViewableIndicesChanges(newViewableIndices: number[]) {
|
|
100
|
+
// Check if all viewable indices are still available (applicable if minimumViewTime > 0)
|
|
101
|
+
const currentlyNewViewableIndices = newViewableIndices.filter((index) =>
|
|
102
|
+
this.viewableIndices.includes(index)
|
|
103
|
+
);
|
|
104
|
+
const newlyVisibleItems = currentlyNewViewableIndices.filter(
|
|
105
|
+
(index) => !this.lastReportedViewableIndices.includes(index)
|
|
106
|
+
);
|
|
107
|
+
const newlyNonvisibleItems = this.lastReportedViewableIndices.filter(
|
|
108
|
+
(index) => !currentlyNewViewableIndices.includes(index)
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
if (newlyVisibleItems.length > 0 || newlyNonvisibleItems.length > 0) {
|
|
112
|
+
this.lastReportedViewableIndices = currentlyNewViewableIndices;
|
|
113
|
+
this.viewableIndicesChanged(
|
|
114
|
+
currentlyNewViewableIndices,
|
|
115
|
+
newlyVisibleItems,
|
|
116
|
+
newlyNonvisibleItems
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private isItemViewable(
|
|
122
|
+
index: number,
|
|
123
|
+
horizontal: boolean,
|
|
124
|
+
scrollOffset: number,
|
|
125
|
+
listSize: Dimension,
|
|
126
|
+
viewAreaCoveragePercentThreshold: number | null | undefined,
|
|
127
|
+
itemVisiblePercentThreshold: number | null | undefined,
|
|
128
|
+
getLayout: (index: number) => Layout | undefined
|
|
129
|
+
) {
|
|
130
|
+
const itemLayout = getLayout(index);
|
|
131
|
+
if (itemLayout === undefined) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
const itemTop = (horizontal ? itemLayout.x : itemLayout.y) - scrollOffset;
|
|
135
|
+
const itemSize = horizontal ? itemLayout.width : itemLayout.height;
|
|
136
|
+
const listMainSize = horizontal ? listSize.width : listSize.height;
|
|
137
|
+
const pixelsVisible =
|
|
138
|
+
Math.min(itemTop + itemSize, listMainSize) - Math.max(itemTop, 0);
|
|
139
|
+
|
|
140
|
+
// Always consider item fully viewable if it is fully visible, regardless of the `viewAreaCoveragePercentThreshold`
|
|
141
|
+
if (pixelsVisible === itemSize) {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
// Skip checking item if it's not visible at all
|
|
145
|
+
if (pixelsVisible === 0) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
const viewAreaMode =
|
|
149
|
+
viewAreaCoveragePercentThreshold !== null &&
|
|
150
|
+
viewAreaCoveragePercentThreshold !== undefined;
|
|
151
|
+
const percent = viewAreaMode
|
|
152
|
+
? pixelsVisible / listMainSize
|
|
153
|
+
: pixelsVisible / itemSize;
|
|
154
|
+
const viewableAreaPercentThreshold = viewAreaMode
|
|
155
|
+
? viewAreaCoveragePercentThreshold * 0.01
|
|
156
|
+
: (itemVisiblePercentThreshold ?? 0) * 0.01;
|
|
157
|
+
|
|
158
|
+
return percent >= viewableAreaPercentThreshold;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export default ViewabilityHelper;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { ViewabilityConfig } from "react-native";
|
|
2
|
+
|
|
3
|
+
import FlashList from "../FlashList";
|
|
4
|
+
|
|
5
|
+
import ViewabilityHelper from "./ViewabilityHelper";
|
|
6
|
+
import ViewToken from "./ViewToken";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Manager for viewability tracking. It holds multiple viewability callback pairs and keeps them updated.
|
|
10
|
+
*/
|
|
11
|
+
export default class ViewabilityManager<T> {
|
|
12
|
+
private flashListRef: FlashList<T>;
|
|
13
|
+
private viewabilityHelpers: ViewabilityHelper[] = [];
|
|
14
|
+
private hasInteracted = false;
|
|
15
|
+
|
|
16
|
+
constructor(flashListRef: FlashList<T>) {
|
|
17
|
+
this.flashListRef = flashListRef;
|
|
18
|
+
if (
|
|
19
|
+
flashListRef.props.onViewableItemsChanged !== null &&
|
|
20
|
+
flashListRef.props.onViewableItemsChanged !== undefined
|
|
21
|
+
) {
|
|
22
|
+
this.viewabilityHelpers.push(
|
|
23
|
+
this.createViewabilityHelper(
|
|
24
|
+
flashListRef.props.viewabilityConfig,
|
|
25
|
+
flashListRef.props.onViewableItemsChanged
|
|
26
|
+
)
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
(flashListRef.props.viewabilityConfigCallbackPairs ?? []).forEach(
|
|
30
|
+
(pair) => {
|
|
31
|
+
this.viewabilityHelpers.push(
|
|
32
|
+
this.createViewabilityHelper(
|
|
33
|
+
pair.viewabilityConfig,
|
|
34
|
+
pair.onViewableItemsChanged
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @returns true if the viewability manager has any viewability callback pairs registered.
|
|
43
|
+
*/
|
|
44
|
+
public get shouldListenToVisibleIndices() {
|
|
45
|
+
return this.viewabilityHelpers.length > 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public dispose = () => {
|
|
49
|
+
this.viewabilityHelpers.forEach((viewabilityHelper) =>
|
|
50
|
+
viewabilityHelper.dispose()
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
public onVisibleIndicesChanged = (all: number[]) => {
|
|
55
|
+
this.updateViewableItems(all);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
public recordInteraction = () => {
|
|
59
|
+
if (this.hasInteracted) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
this.hasInteracted = true;
|
|
63
|
+
this.viewabilityHelpers.forEach((viewabilityHelper) => {
|
|
64
|
+
viewabilityHelper.hasInteracted = true;
|
|
65
|
+
});
|
|
66
|
+
this.updateViewableItems();
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
public updateViewableItems = (newViewableIndices?: number[]) => {
|
|
70
|
+
const listSize =
|
|
71
|
+
this.flashListRef.recyclerlistview_unsafe?.getRenderedSize() ??
|
|
72
|
+
this.flashListRef.props.estimatedListSize;
|
|
73
|
+
if (listSize === undefined || !this.shouldListenToVisibleIndices) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const scrollOffset =
|
|
77
|
+
(this.flashListRef.recyclerlistview_unsafe?.getCurrentScrollOffset() ??
|
|
78
|
+
0) - this.flashListRef.firstItemOffset;
|
|
79
|
+
this.viewabilityHelpers.forEach((viewabilityHelper) => {
|
|
80
|
+
viewabilityHelper.updateViewableItems(
|
|
81
|
+
this.flashListRef.props.horizontal ?? false,
|
|
82
|
+
scrollOffset,
|
|
83
|
+
listSize,
|
|
84
|
+
(index: number) =>
|
|
85
|
+
this.flashListRef.recyclerlistview_unsafe?.getLayout(index),
|
|
86
|
+
newViewableIndices
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Creates a new `ViewabilityHelper` instance with `onViewableItemsChanged` callback and `ViewabilityConfig`
|
|
93
|
+
* @returns `ViewabilityHelper` instance
|
|
94
|
+
*/
|
|
95
|
+
private createViewabilityHelper = (
|
|
96
|
+
viewabilityConfig: ViewabilityConfig | null | undefined,
|
|
97
|
+
onViewableItemsChanged:
|
|
98
|
+
| ((info: { viewableItems: ViewToken[]; changed: ViewToken[] }) => void)
|
|
99
|
+
| null
|
|
100
|
+
| undefined
|
|
101
|
+
) => {
|
|
102
|
+
const mapViewToken: (index: number, isViewable: boolean) => ViewToken = (
|
|
103
|
+
index: number,
|
|
104
|
+
isViewable: boolean
|
|
105
|
+
) => {
|
|
106
|
+
const item = this.flashListRef.props.data?.[index];
|
|
107
|
+
const key =
|
|
108
|
+
item === undefined || this.flashListRef.props.keyExtractor === undefined
|
|
109
|
+
? index.toString()
|
|
110
|
+
: this.flashListRef.props.keyExtractor(item, index);
|
|
111
|
+
return {
|
|
112
|
+
index,
|
|
113
|
+
isViewable,
|
|
114
|
+
item,
|
|
115
|
+
key,
|
|
116
|
+
timestamp: Date.now(),
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
return new ViewabilityHelper(
|
|
120
|
+
viewabilityConfig,
|
|
121
|
+
(indices, newlyVisibleIndices, newlyNonvisibleIndices) => {
|
|
122
|
+
onViewableItemsChanged?.({
|
|
123
|
+
viewableItems: indices.map((index) => mapViewToken(index, true)),
|
|
124
|
+
changed: [
|
|
125
|
+
...newlyVisibleIndices.map((index) => mapViewToken(index, true)),
|
|
126
|
+
...newlyNonvisibleIndices.map((index) =>
|
|
127
|
+
mapViewToken(index, false)
|
|
128
|
+
),
|
|
129
|
+
],
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
};
|
|
134
|
+
}
|