@shopify/flash-list 2.0.0 → 2.0.2-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/README.md +97 -27
- package/RNFlashList.podspec +37 -0
- package/android/build.gradle +89 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/AutoLayoutShadow.kt +105 -0
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/AutoLayoutView.kt +158 -0
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/AutoLayoutViewManager.kt +70 -0
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/BlankAreaEvent.kt +29 -0
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/CellContainer.java +16 -0
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/CellContainerImpl.kt +16 -0
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/CellContainerManager.kt +34 -0
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/FlashListPackage.kt +19 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/AutoLayoutViewManagerDelegate.java +47 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/AutoLayoutViewManagerInterface.java +21 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/CellContainerManagerDelegate.java +32 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/CellContainerManagerInterface.java +16 -0
- package/android/src/test/java/com/shopify/reactnative/flash_list/AutoLayoutShadowTest.kt +147 -0
- package/android/src/test/java/com/shopify/reactnative/flash_list/models/Rect.kt +61 -0
- package/android/src/test/java/com/shopify/reactnative/flash_list/models/TestCollection.kt +6 -0
- package/android/src/test/java/com/shopify/reactnative/flash_list/models/TestDataModel.kt +8 -0
- package/android/src/test/resources/LayoutTestData.json +788 -0
- package/dist/AnimatedFlashList.js +2 -2
- package/dist/AnimatedFlashList.js.map +1 -1
- package/dist/FlashList.d.ts +167 -1
- package/dist/FlashList.d.ts.map +1 -1
- package/dist/FlashList.js +595 -3
- package/dist/FlashList.js.map +1 -1
- package/dist/FlashListProps.d.ts +63 -2
- package/dist/FlashListProps.d.ts.map +1 -1
- package/dist/FlashListProps.js.map +1 -1
- package/dist/GridLayoutProviderWithProps.d.ts +42 -0
- package/dist/GridLayoutProviderWithProps.d.ts.map +1 -0
- package/dist/GridLayoutProviderWithProps.js +114 -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__/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 +902 -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.js +4 -3
- package/dist/__tests__/ViewabilityHelper.test.js.map +1 -1
- 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 +179 -0
- package/dist/__tests__/useBlankAreaTracker.test.js.map +1 -0
- package/dist/benchmark/JSFPSMonitor.d.ts.map +1 -1
- package/dist/benchmark/JSFPSMonitor.js +1 -2
- package/dist/benchmark/JSFPSMonitor.js.map +1 -1
- package/dist/benchmark/useBenchmark.d.ts +4 -2
- package/dist/benchmark/useBenchmark.d.ts.map +1 -1
- package/dist/benchmark/useBenchmark.js +24 -12
- package/dist/benchmark/useBenchmark.js.map +1 -1
- package/dist/benchmark/useBlankAreaTracker.d.ts +34 -0
- package/dist/benchmark/useBlankAreaTracker.d.ts.map +1 -0
- package/dist/benchmark/useBlankAreaTracker.js +66 -0
- package/dist/benchmark/useBlankAreaTracker.js.map +1 -0
- package/dist/benchmark/useFlatListBenchmark.d.ts.map +1 -1
- package/dist/benchmark/useFlatListBenchmark.js +1 -2
- package/dist/benchmark/useFlatListBenchmark.js.map +1 -1
- package/dist/enableNewCore.d.ts +3 -0
- package/dist/enableNewCore.d.ts.map +1 -0
- package/dist/enableNewCore.js +25 -0
- package/dist/enableNewCore.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/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -7
- package/dist/index.js.map +1 -1
- 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.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.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 +22 -1
- package/dist/native/config/PlatformHelper.android.d.ts.map +1 -1
- package/dist/native/config/PlatformHelper.android.js +16 -1
- package/dist/native/config/PlatformHelper.android.js.map +1 -1
- package/dist/native/config/PlatformHelper.d.ts +22 -1
- package/dist/native/config/PlatformHelper.d.ts.map +1 -1
- package/dist/native/config/PlatformHelper.ios.d.ts +22 -1
- package/dist/native/config/PlatformHelper.ios.d.ts.map +1 -1
- package/dist/native/config/PlatformHelper.ios.js +15 -1
- package/dist/native/config/PlatformHelper.ios.js.map +1 -1
- package/dist/native/config/PlatformHelper.js +16 -1
- package/dist/native/config/PlatformHelper.js.map +1 -1
- package/dist/native/config/PlatformHelper.web.d.ts +23 -1
- package/dist/native/config/PlatformHelper.web.d.ts.map +1 -1
- package/dist/native/config/PlatformHelper.web.js +18 -1
- package/dist/native/config/PlatformHelper.web.js.map +1 -1
- package/dist/recyclerview/RecyclerView.d.ts.map +1 -1
- package/dist/recyclerview/RecyclerView.js +6 -6
- package/dist/recyclerview/RecyclerView.js.map +1 -1
- package/dist/recyclerview/RecyclerViewManager.d.ts.map +1 -1
- package/dist/recyclerview/RecyclerViewManager.js +8 -9
- package/dist/recyclerview/RecyclerViewManager.js.map +1 -1
- package/dist/recyclerview/RecyclerViewProps.d.ts +8 -1
- package/dist/recyclerview/RecyclerViewProps.d.ts.map +1 -1
- package/dist/recyclerview/helpers/RenderTimeTracker.d.ts +3 -0
- package/dist/recyclerview/helpers/RenderTimeTracker.d.ts.map +1 -1
- package/dist/recyclerview/helpers/RenderTimeTracker.js +7 -0
- package/dist/recyclerview/helpers/RenderTimeTracker.js.map +1 -1
- package/dist/recyclerview/hooks/useRecyclerViewController.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useRecyclerViewController.js +0 -4
- package/dist/recyclerview/hooks/useRecyclerViewController.js.map +1 -1
- package/dist/recyclerview/layout-managers/LayoutManager.d.ts.map +1 -1
- package/dist/recyclerview/layout-managers/LayoutManager.js +1 -2
- package/dist/recyclerview/layout-managers/LayoutManager.js.map +1 -1
- package/dist/specs/AutoLayoutNativeComponent.d.ts +18 -0
- package/dist/specs/AutoLayoutNativeComponent.d.ts.map +1 -0
- package/dist/specs/AutoLayoutNativeComponent.js +6 -0
- package/dist/specs/AutoLayoutNativeComponent.js.map +1 -0
- package/dist/specs/CellContainerNativeComponent.d.ts +8 -0
- package/dist/specs/CellContainerNativeComponent.d.ts.map +1 -0
- package/dist/specs/CellContainerNativeComponent.js +6 -0
- package/dist/specs/CellContainerNativeComponent.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- 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.map +1 -0
- package/dist/viewability/ViewToken.js.map +1 -0
- package/dist/{recyclerview/viewability → viewability}/ViewabilityHelper.d.ts +2 -2
- package/dist/viewability/ViewabilityHelper.d.ts.map +1 -0
- package/dist/{recyclerview/viewability → viewability}/ViewabilityHelper.js +4 -2
- package/dist/{recyclerview/viewability → viewability}/ViewabilityHelper.js.map +1 -1
- package/dist/{recyclerview/viewability → viewability}/ViewabilityManager.d.ts +3 -3
- package/dist/viewability/ViewabilityManager.d.ts.map +1 -0
- package/dist/{recyclerview/viewability → viewability}/ViewabilityManager.js +16 -16
- package/dist/viewability/ViewabilityManager.js.map +1 -0
- package/ios/RNFlashList.xcodeproj/project.pbxproj +3 -0
- package/ios/RNFlashList.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
- package/ios/Sources/AutoLayoutView.swift +294 -0
- package/ios/Sources/AutoLayoutViewComponentView.h +16 -0
- package/ios/Sources/AutoLayoutViewComponentView.mm +90 -0
- package/ios/Sources/AutoLayoutViewManager.mm +14 -0
- package/ios/Sources/AutoLayoutViewManager.swift +12 -0
- package/ios/Sources/CellContainerComponentView.h +18 -0
- package/ios/Sources/CellContainerComponentView.mm +62 -0
- package/ios/Sources/CellContainerManager.mm +8 -0
- package/ios/Sources/CellContainerManager.swift +12 -0
- package/ios/Sources/FlatListPro-Bridging-Header.h +11 -0
- package/ios/Tests/AutoLayoutViewTests.swift +113 -0
- package/package.json +14 -3
- package/src/AnimatedFlashList.ts +2 -2
- package/src/FlashList.tsx +953 -0
- package/src/FlashListProps.ts +79 -3
- package/src/GridLayoutProviderWithProps.ts +180 -0
- package/src/MasonryFlashList.tsx +476 -0
- package/src/PureComponentWrapper.tsx +42 -0
- package/src/__tests__/ContentContainerUtils.test.ts +130 -0
- package/src/__tests__/FlashList.test.tsx +1001 -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 +14 -13
- package/src/__tests__/helpers/mountFlashList.tsx +62 -0
- package/src/__tests__/helpers/mountMasonryFlashList.tsx +70 -0
- package/src/__tests__/useBlankAreaTracker.test.tsx +206 -0
- package/src/benchmark/JSFPSMonitor.ts +3 -3
- package/src/benchmark/useBenchmark.ts +40 -12
- package/src/benchmark/useBlankAreaTracker.ts +117 -0
- package/src/benchmark/useFlatListBenchmark.ts +1 -3
- package/src/enableNewCore.ts +24 -0
- package/src/errors/CustomError.ts +10 -0
- package/src/errors/ExceptionList.ts +28 -0
- package/src/errors/Warnings.ts +15 -0
- package/src/index.ts +43 -7
- 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.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.ios.ts +7 -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 +25 -1
- package/src/native/config/PlatformHelper.ios.ts +24 -1
- package/src/native/config/PlatformHelper.ts +25 -1
- package/src/native/config/PlatformHelper.web.ts +30 -1
- package/src/recyclerview/RecyclerView.tsx +11 -6
- package/src/recyclerview/RecyclerViewManager.ts +18 -9
- package/src/recyclerview/RecyclerViewProps.ts +11 -1
- package/src/recyclerview/helpers/RenderTimeTracker.ts +8 -0
- package/src/recyclerview/hooks/useRecyclerViewController.tsx +0 -4
- package/src/recyclerview/layout-managers/LayoutManager.ts +1 -2
- package/src/specs/AutoLayoutNativeComponent.ts +24 -0
- package/src/specs/CellContainerNativeComponent.ts +9 -0
- package/src/utils/ContentContainerUtils.ts +92 -0
- package/src/{recyclerview/viewability → viewability}/ViewabilityHelper.ts +9 -8
- package/src/{recyclerview/viewability → viewability}/ViewabilityManager.ts +20 -18
- package/dist/errors/ErrorMessages.d.ts +0 -16
- package/dist/errors/ErrorMessages.d.ts.map +0 -1
- package/dist/errors/ErrorMessages.js +0 -19
- package/dist/errors/ErrorMessages.js.map +0 -1
- package/dist/errors/WarningMessages.d.ts +0 -4
- package/dist/errors/WarningMessages.d.ts.map +0 -1
- package/dist/errors/WarningMessages.js +0 -7
- package/dist/errors/WarningMessages.js.map +0 -1
- package/dist/isNewArch.d.ts +0 -2
- package/dist/isNewArch.d.ts.map +0 -1
- package/dist/isNewArch.js +0 -25
- package/dist/isNewArch.js.map +0 -1
- package/dist/recyclerview/viewability/ViewToken.d.ts.map +0 -1
- package/dist/recyclerview/viewability/ViewToken.js.map +0 -1
- package/dist/recyclerview/viewability/ViewabilityHelper.d.ts.map +0 -1
- package/dist/recyclerview/viewability/ViewabilityManager.d.ts.map +0 -1
- package/dist/recyclerview/viewability/ViewabilityManager.js.map +0 -1
- package/src/FlashList.ts +0 -1
- package/src/errors/ErrorMessages.ts +0 -26
- package/src/errors/WarningMessages.ts +0 -4
- package/src/isNewArch.ts +0 -25
- /package/dist/{recyclerview/viewability → viewability}/ViewToken.d.ts +0 -0
- /package/dist/{recyclerview/viewability → viewability}/ViewToken.js +0 -0
- /package/src/{recyclerview/viewability → viewability}/ViewToken.ts +0 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { ScrollView } from "react-native";
|
|
2
|
+
import { ProgressiveListView } from "recyclerlistview";
|
|
3
|
+
|
|
4
|
+
import FlashList from "../FlashList";
|
|
5
|
+
|
|
6
|
+
import { mountFlashList } from "./helpers/mountFlashList";
|
|
7
|
+
|
|
8
|
+
describe("GridLayoutProviderWithProps", () => {
|
|
9
|
+
it("updates average window on layout manager change", () => {
|
|
10
|
+
const flashList = mountFlashList();
|
|
11
|
+
const oldAverageWindow = (flashList.instance as FlashList<any>).state
|
|
12
|
+
.layoutProvider["averageWindow"];
|
|
13
|
+
|
|
14
|
+
// width change from default 400 to 600 will force layout manager to change
|
|
15
|
+
flashList.find(ScrollView)?.trigger("onLayout", {
|
|
16
|
+
nativeEvent: { layout: { height: 900, width: 600 } },
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const newAverageWindow =
|
|
20
|
+
flashList.instance.state.layoutProvider["averageWindow"];
|
|
21
|
+
|
|
22
|
+
expect(newAverageWindow).not.toBe(oldAverageWindow);
|
|
23
|
+
flashList.unmount();
|
|
24
|
+
});
|
|
25
|
+
it("average window's size is two times the number of items that will fill the screen", () => {
|
|
26
|
+
const flashList = mountFlashList({ numColumns: 2 });
|
|
27
|
+
expect(
|
|
28
|
+
flashList.instance.state.layoutProvider["averageWindow"]["inputValues"]
|
|
29
|
+
.length
|
|
30
|
+
).toBe(20);
|
|
31
|
+
flashList.find(ScrollView)?.trigger("onLayout", {
|
|
32
|
+
nativeEvent: { layout: { height: 2000, width: 600 } },
|
|
33
|
+
});
|
|
34
|
+
expect(
|
|
35
|
+
flashList.instance.state.layoutProvider["averageWindow"]["inputValues"]
|
|
36
|
+
.length
|
|
37
|
+
).toBe(40);
|
|
38
|
+
flashList.setProps({ numColumns: 1 });
|
|
39
|
+
expect(
|
|
40
|
+
flashList.instance.state.layoutProvider["averageWindow"]["inputValues"]
|
|
41
|
+
.length
|
|
42
|
+
).toBe(20);
|
|
43
|
+
flashList.unmount();
|
|
44
|
+
});
|
|
45
|
+
it("average window should not be less than 6 in size", () => {
|
|
46
|
+
const flashList = mountFlashList();
|
|
47
|
+
flashList.find(ScrollView)?.trigger("onLayout", {
|
|
48
|
+
nativeEvent: { layout: { height: 100, width: 100 } },
|
|
49
|
+
});
|
|
50
|
+
expect(
|
|
51
|
+
flashList.instance.state.layoutProvider["averageWindow"]["inputValues"]
|
|
52
|
+
.length
|
|
53
|
+
).toBe(6);
|
|
54
|
+
flashList.unmount();
|
|
55
|
+
});
|
|
56
|
+
it("vertical list: average should not update when widths change", () => {
|
|
57
|
+
const flashList = mountFlashList();
|
|
58
|
+
const layoutProvider = flashList.instance.state.layoutProvider;
|
|
59
|
+
const oldAverage = layoutProvider.averageItemSize;
|
|
60
|
+
|
|
61
|
+
layoutProvider.getLayoutManager()!.getLayouts()[0].width = 500;
|
|
62
|
+
flashList.find(ProgressiveListView)?.instance.onItemLayout(0);
|
|
63
|
+
|
|
64
|
+
expect(oldAverage).toBe(layoutProvider.averageItemSize);
|
|
65
|
+
flashList.unmount();
|
|
66
|
+
});
|
|
67
|
+
it("horizontal list: average should not update when heights change", () => {
|
|
68
|
+
const flashList = mountFlashList({ horizontal: true });
|
|
69
|
+
const layoutProvider = flashList.instance.state.layoutProvider;
|
|
70
|
+
const oldAverage = layoutProvider.averageItemSize;
|
|
71
|
+
|
|
72
|
+
layoutProvider.getLayoutManager()!.getLayouts()[0].height = 600;
|
|
73
|
+
|
|
74
|
+
// Can throw a no op set state warning. Should be handled in PLV.
|
|
75
|
+
flashList.find(ProgressiveListView)?.instance.onItemLayout(0);
|
|
76
|
+
|
|
77
|
+
expect(oldAverage).toBe(layoutProvider.averageItemSize);
|
|
78
|
+
flashList.unmount();
|
|
79
|
+
});
|
|
80
|
+
it("computes correct average", () => {
|
|
81
|
+
const flashList = mountFlashList();
|
|
82
|
+
const layoutProvider = flashList.instance.state.layoutProvider;
|
|
83
|
+
expect(layoutProvider.averageItemSize).toBe(200);
|
|
84
|
+
|
|
85
|
+
const layouts = layoutProvider.getLayoutManager()!.getLayouts();
|
|
86
|
+
const progressiveListView = flashList.find(ProgressiveListView);
|
|
87
|
+
layouts[0].height = 100;
|
|
88
|
+
layouts[1].height = 200;
|
|
89
|
+
layouts[2].height = 300;
|
|
90
|
+
layouts[3].height = 400;
|
|
91
|
+
progressiveListView?.instance.onItemLayout(0);
|
|
92
|
+
progressiveListView?.instance.onItemLayout(1);
|
|
93
|
+
progressiveListView?.instance.onItemLayout(2);
|
|
94
|
+
progressiveListView?.instance.onItemLayout(3);
|
|
95
|
+
|
|
96
|
+
// estimatedItemSize is treated as one of the values. That's why 240.
|
|
97
|
+
expect(layoutProvider.averageItemSize).toBe(240);
|
|
98
|
+
flashList.unmount();
|
|
99
|
+
});
|
|
100
|
+
it("updates all cached widths for vertical list and heights for horizontal list when orientation changes", () => {
|
|
101
|
+
const runCacheUpdateTest = (horizontal: boolean) => {
|
|
102
|
+
const flashList = mountFlashList({
|
|
103
|
+
data: new Array(20).fill("1"),
|
|
104
|
+
horizontal,
|
|
105
|
+
});
|
|
106
|
+
const progressiveListView = flashList.find(ProgressiveListView);
|
|
107
|
+
const layoutProvider = flashList.instance.state.layoutProvider;
|
|
108
|
+
|
|
109
|
+
layoutProvider
|
|
110
|
+
.getLayoutManager()!
|
|
111
|
+
.getLayouts()
|
|
112
|
+
.forEach((layout, index) => {
|
|
113
|
+
// marking layouts as if they're actual rendered sizes
|
|
114
|
+
progressiveListView?.instance.onItemLayout(index);
|
|
115
|
+
|
|
116
|
+
// checking size
|
|
117
|
+
if (horizontal) {
|
|
118
|
+
expect(layout.height).toBe(900);
|
|
119
|
+
} else {
|
|
120
|
+
expect(layout.width).toBe(400);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// simulates orientation change
|
|
125
|
+
flashList.find(ScrollView)?.trigger("onLayout", {
|
|
126
|
+
nativeEvent: { layout: { height: 400, width: 900 } },
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
layoutProvider
|
|
130
|
+
.getLayoutManager()!
|
|
131
|
+
.getLayouts()
|
|
132
|
+
.forEach((layout) => {
|
|
133
|
+
// making sure all widths or heights are updated
|
|
134
|
+
if (horizontal) {
|
|
135
|
+
expect(layout.height).toBe(400);
|
|
136
|
+
} else {
|
|
137
|
+
expect(layout.width).toBe(900);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// making sure extra keys don't make their way to layout unnecessarily
|
|
141
|
+
expect(Object.keys(layout).length).toBe(6);
|
|
142
|
+
});
|
|
143
|
+
flashList.unmount();
|
|
144
|
+
};
|
|
145
|
+
// vertical list
|
|
146
|
+
runCacheUpdateTest(false);
|
|
147
|
+
// horizontal list
|
|
148
|
+
runCacheUpdateTest(true);
|
|
149
|
+
});
|
|
150
|
+
it("expires if column count or padding changes", () => {
|
|
151
|
+
const flashList = mountFlashList();
|
|
152
|
+
const baseProps = flashList.instance.props;
|
|
153
|
+
expect(
|
|
154
|
+
flashList.instance.state.layoutProvider.updateProps({
|
|
155
|
+
...baseProps,
|
|
156
|
+
contentContainerStyle: { paddingTop: 10 },
|
|
157
|
+
}).hasExpired
|
|
158
|
+
).toBe(false);
|
|
159
|
+
expect(
|
|
160
|
+
flashList.instance.state.layoutProvider.updateProps({
|
|
161
|
+
...baseProps,
|
|
162
|
+
contentContainerStyle: { paddingBottom: 10 },
|
|
163
|
+
}).hasExpired
|
|
164
|
+
).toBe(false);
|
|
165
|
+
expect(
|
|
166
|
+
flashList.instance.state.layoutProvider.updateProps({
|
|
167
|
+
...baseProps,
|
|
168
|
+
contentContainerStyle: { paddingLeft: 10 },
|
|
169
|
+
}).hasExpired
|
|
170
|
+
).toBe(true);
|
|
171
|
+
flashList.instance.state.layoutProvider["_hasExpired"] = false;
|
|
172
|
+
expect(
|
|
173
|
+
flashList.instance.state.layoutProvider.updateProps({
|
|
174
|
+
...baseProps,
|
|
175
|
+
numColumns: 2,
|
|
176
|
+
}).hasExpired
|
|
177
|
+
).toBe(true);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { ScrollView, Text, View } from "react-native";
|
|
2
|
+
import "@quilted/react-testing/matchers";
|
|
3
|
+
import { ProgressiveListView } from "recyclerlistview";
|
|
4
|
+
import React from "react";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
MasonryFlashListProps,
|
|
8
|
+
MasonryFlashListRef,
|
|
9
|
+
} from "../MasonryFlashList";
|
|
10
|
+
import FlashList from "../FlashList";
|
|
11
|
+
|
|
12
|
+
import { mountMasonryFlashList } from "./helpers/mountMasonryFlashList";
|
|
13
|
+
|
|
14
|
+
describe("MasonryFlashList", () => {
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
jest.clearAllMocks();
|
|
17
|
+
jest.useFakeTimers();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("renders items and has 3 internal lists", () => {
|
|
21
|
+
const masonryFlashList = mountMasonryFlashList();
|
|
22
|
+
expect(masonryFlashList.findAll(ProgressiveListView).length).toBe(3);
|
|
23
|
+
expect(masonryFlashList).toContainReactComponent(Text, { children: "One" });
|
|
24
|
+
expect(masonryFlashList).toContainReactComponent(ProgressiveListView, {
|
|
25
|
+
isHorizontal: false,
|
|
26
|
+
});
|
|
27
|
+
masonryFlashList.unmount();
|
|
28
|
+
});
|
|
29
|
+
it("invokes renderItem with columnIndex and columnSpan", () => {
|
|
30
|
+
const mockRenderItem = jest.fn(() => null);
|
|
31
|
+
const masonryFlashList = mountMasonryFlashList({
|
|
32
|
+
renderItem: mockRenderItem,
|
|
33
|
+
data: ["One", "Two", "Three"],
|
|
34
|
+
numColumns: 3,
|
|
35
|
+
});
|
|
36
|
+
expect(mockRenderItem).toHaveBeenCalledWith(
|
|
37
|
+
expect.objectContaining({
|
|
38
|
+
columnIndex: 0,
|
|
39
|
+
columnSpan: 1,
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
expect(mockRenderItem).toHaveBeenCalledWith(
|
|
44
|
+
expect.objectContaining({
|
|
45
|
+
columnIndex: 1,
|
|
46
|
+
columnSpan: 1,
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(mockRenderItem).toHaveBeenCalledWith(
|
|
51
|
+
expect.objectContaining({
|
|
52
|
+
columnSpan: 1,
|
|
53
|
+
columnIndex: 2,
|
|
54
|
+
})
|
|
55
|
+
);
|
|
56
|
+
masonryFlashList.unmount();
|
|
57
|
+
});
|
|
58
|
+
it("raised onLoad event only when first internal child mounts", () => {
|
|
59
|
+
const onLoadMock = jest.fn();
|
|
60
|
+
const ref = React.createRef<MasonryFlashListRef<string>>();
|
|
61
|
+
const masonryFlashList = mountMasonryFlashList(
|
|
62
|
+
{
|
|
63
|
+
onLoad: onLoadMock,
|
|
64
|
+
},
|
|
65
|
+
ref
|
|
66
|
+
);
|
|
67
|
+
expect(onLoadMock).not.toHaveBeenCalled();
|
|
68
|
+
masonryFlashList.findAll(ProgressiveListView)[1]?.instance.onItemLayout(0);
|
|
69
|
+
expect(onLoadMock).toHaveBeenCalledTimes(1);
|
|
70
|
+
|
|
71
|
+
// on load shouldn't be passed to wrapper list
|
|
72
|
+
expect((ref.current as FlashList<string>).props.onLoad).toBeUndefined();
|
|
73
|
+
masonryFlashList.unmount();
|
|
74
|
+
});
|
|
75
|
+
it("can resize columns using getColumnFlex", () => {
|
|
76
|
+
const masonryFlashList = mountMasonryFlashList({
|
|
77
|
+
getColumnFlex: (_, column) => (column === 0 ? 1 : 3),
|
|
78
|
+
});
|
|
79
|
+
const progressiveListView =
|
|
80
|
+
masonryFlashList.find(ProgressiveListView)!.instance;
|
|
81
|
+
expect(progressiveListView.getLayout(0).width).toBe(100);
|
|
82
|
+
expect(progressiveListView.getLayout(1).width).toBe(300);
|
|
83
|
+
|
|
84
|
+
expect(masonryFlashList.findAll(ProgressiveListView).length).toBe(3);
|
|
85
|
+
masonryFlashList.findAll(ProgressiveListView).forEach((plv, index) => {
|
|
86
|
+
if (index === 1) {
|
|
87
|
+
expect(plv.instance.props.layoutSize.width).toBe(100);
|
|
88
|
+
}
|
|
89
|
+
if (index === 2) {
|
|
90
|
+
expect(plv.instance.props.layoutSize.width).toBe(300);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
masonryFlashList.unmount();
|
|
94
|
+
});
|
|
95
|
+
it("mounts a single ScrollView", () => {
|
|
96
|
+
const masonryFlashList = mountMasonryFlashList();
|
|
97
|
+
expect(masonryFlashList.findAll(ScrollView)).toHaveLength(1);
|
|
98
|
+
masonryFlashList.unmount();
|
|
99
|
+
});
|
|
100
|
+
it("forwards single onScroll event to external listener", () => {
|
|
101
|
+
const onScrollMock = jest.fn();
|
|
102
|
+
const masonryFlashList = mountMasonryFlashList({
|
|
103
|
+
onScroll: onScrollMock,
|
|
104
|
+
});
|
|
105
|
+
masonryFlashList.find(ScrollView)?.instance.props.onScroll({
|
|
106
|
+
nativeEvent: { contentOffset: { x: 0, y: 0 } },
|
|
107
|
+
});
|
|
108
|
+
expect(onScrollMock).toHaveBeenCalledTimes(1);
|
|
109
|
+
masonryFlashList.unmount();
|
|
110
|
+
});
|
|
111
|
+
it("updates scroll offset of all internal lists", () => {
|
|
112
|
+
const onScrollMock = jest.fn();
|
|
113
|
+
const masonryFlashList = mountMasonryFlashList({
|
|
114
|
+
onScroll: onScrollMock,
|
|
115
|
+
});
|
|
116
|
+
masonryFlashList.find(ScrollView)?.instance.props.onScroll({
|
|
117
|
+
nativeEvent: { contentOffset: { x: 0, y: 100 } },
|
|
118
|
+
});
|
|
119
|
+
masonryFlashList.findAll(ProgressiveListView).forEach((list) => {
|
|
120
|
+
expect(list.instance.getCurrentScrollOffset()).toBe(100);
|
|
121
|
+
});
|
|
122
|
+
masonryFlashList.unmount();
|
|
123
|
+
});
|
|
124
|
+
it("has a valid ref object", () => {
|
|
125
|
+
const ref = React.createRef<MasonryFlashListRef<string>>();
|
|
126
|
+
const masonryFlashList = mountMasonryFlashList({}, ref);
|
|
127
|
+
expect(ref.current).toBeDefined();
|
|
128
|
+
masonryFlashList.unmount();
|
|
129
|
+
});
|
|
130
|
+
it("forwards overrideItemLayout to internal lists", () => {
|
|
131
|
+
const overrideItemLayout = jest.fn((layout) => {
|
|
132
|
+
layout.size = 300;
|
|
133
|
+
});
|
|
134
|
+
const masonryFlashList = mountMasonryFlashList({
|
|
135
|
+
overrideItemLayout,
|
|
136
|
+
});
|
|
137
|
+
expect(masonryFlashList.findAll(ProgressiveListView).length).toBe(3);
|
|
138
|
+
masonryFlashList.findAll(ProgressiveListView).forEach((list, index) => {
|
|
139
|
+
if (index !== 0) {
|
|
140
|
+
expect(list.instance.getLayout(0).height).toBe(300);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
masonryFlashList.unmount();
|
|
144
|
+
});
|
|
145
|
+
it("forwards keyExtractor to internal list", () => {
|
|
146
|
+
const keyExtractor = (_: string, index: number) => (index + 1).toString();
|
|
147
|
+
const masonryFlashList = mountMasonryFlashList({
|
|
148
|
+
keyExtractor,
|
|
149
|
+
});
|
|
150
|
+
expect(masonryFlashList.findAll(ProgressiveListView).length).toBe(3);
|
|
151
|
+
expect(
|
|
152
|
+
masonryFlashList
|
|
153
|
+
.findAll(ProgressiveListView)[0]
|
|
154
|
+
.instance.props.dataProvider.getStableId(0)
|
|
155
|
+
).toBe("0");
|
|
156
|
+
expect(
|
|
157
|
+
masonryFlashList
|
|
158
|
+
.findAll(ProgressiveListView)[1]
|
|
159
|
+
.instance.props.dataProvider.getStableId(0)
|
|
160
|
+
).toBe("1");
|
|
161
|
+
expect(
|
|
162
|
+
masonryFlashList
|
|
163
|
+
.findAll(ProgressiveListView)[2]
|
|
164
|
+
.instance.props.dataProvider.getStableId(0)
|
|
165
|
+
).toBe("2");
|
|
166
|
+
masonryFlashList.unmount();
|
|
167
|
+
});
|
|
168
|
+
it("correctly maps list indices to actual indices", () => {
|
|
169
|
+
const data = new Array(20).fill(0).map((_, index) => index.toString());
|
|
170
|
+
const getItemType = (item: string, index: number) => {
|
|
171
|
+
expect(index.toString()).toBe(item);
|
|
172
|
+
return 0;
|
|
173
|
+
};
|
|
174
|
+
const renderItem: MasonryFlashListProps<string>["renderItem"] = ({
|
|
175
|
+
item,
|
|
176
|
+
index,
|
|
177
|
+
}) => {
|
|
178
|
+
expect(index.toString()).toBe(item);
|
|
179
|
+
return null;
|
|
180
|
+
};
|
|
181
|
+
const overrideItemLayout: MasonryFlashListProps<string>["overrideItemLayout"] =
|
|
182
|
+
(layout, item: string, index: number) => {
|
|
183
|
+
expect(index.toString()).toBe(item);
|
|
184
|
+
};
|
|
185
|
+
const keyExtractor = (item: string, index: number) => {
|
|
186
|
+
expect(index.toString()).toBe(item);
|
|
187
|
+
return index.toString();
|
|
188
|
+
};
|
|
189
|
+
const onViewableItemsChanged: MasonryFlashListProps<string>["onViewableItemsChanged"] =
|
|
190
|
+
(info) => {
|
|
191
|
+
info.viewableItems.forEach((viewToken) => {
|
|
192
|
+
expect(viewToken.index?.toString()).toBe(viewToken.item);
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const masonryFlashList = mountMasonryFlashList({
|
|
197
|
+
data,
|
|
198
|
+
renderItem,
|
|
199
|
+
getItemType,
|
|
200
|
+
overrideItemLayout,
|
|
201
|
+
keyExtractor,
|
|
202
|
+
onViewableItemsChanged,
|
|
203
|
+
});
|
|
204
|
+
jest.advanceTimersByTime(1000);
|
|
205
|
+
masonryFlashList.unmount();
|
|
206
|
+
});
|
|
207
|
+
it("internal list height should be derived from the parent and width from itself", () => {
|
|
208
|
+
const masonryFlashList = mountMasonryFlashList({
|
|
209
|
+
testID: "MasonryProxyScrollView",
|
|
210
|
+
});
|
|
211
|
+
expect(masonryFlashList.findAll(ProgressiveListView).length).toBe(3);
|
|
212
|
+
masonryFlashList.findAll(View).forEach((view: any) => {
|
|
213
|
+
view.props?.onLayout?.({
|
|
214
|
+
nativeEvent: { layout: { width: 500, height: 500 } },
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
masonryFlashList.findAll(ProgressiveListView).forEach((list, index) => {
|
|
218
|
+
if (index !== 0) {
|
|
219
|
+
expect(list.instance.getRenderedSize().width).toBe(500);
|
|
220
|
+
expect(list.instance.getRenderedSize().height).toBe(900);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
masonryFlashList.unmount();
|
|
224
|
+
});
|
|
225
|
+
it("can optimize item arrangement", () => {
|
|
226
|
+
const columnCount = 3;
|
|
227
|
+
const data = new Array(999).fill(null).map((_, index) => {
|
|
228
|
+
return "1";
|
|
229
|
+
});
|
|
230
|
+
const masonryFlashList = mountMasonryFlashList({
|
|
231
|
+
data,
|
|
232
|
+
optimizeItemArrangement: true,
|
|
233
|
+
numColumns: columnCount,
|
|
234
|
+
overrideItemLayout(layout, _, index, __, ___?) {
|
|
235
|
+
layout.size = ((index * 10) % 100) + 100 / ((index % columnCount) + 1);
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
expect(masonryFlashList.findAll(ProgressiveListView).length).toBe(4);
|
|
239
|
+
|
|
240
|
+
// I've verified that the following values are correct by observing the algorithm in action
|
|
241
|
+
// Captured values will help prevent regression in the future
|
|
242
|
+
expect(
|
|
243
|
+
Math.floor(
|
|
244
|
+
masonryFlashList
|
|
245
|
+
.findAll(ProgressiveListView)[1]
|
|
246
|
+
.instance.getContentDimension().height
|
|
247
|
+
)
|
|
248
|
+
).toBe(35306);
|
|
249
|
+
expect(
|
|
250
|
+
Math.floor(
|
|
251
|
+
masonryFlashList
|
|
252
|
+
.findAll(ProgressiveListView)[2]
|
|
253
|
+
.instance.getContentDimension().height
|
|
254
|
+
)
|
|
255
|
+
).toBe(35313);
|
|
256
|
+
expect(
|
|
257
|
+
Math.floor(
|
|
258
|
+
masonryFlashList
|
|
259
|
+
.findAll(ProgressiveListView)[3]
|
|
260
|
+
.instance.getContentDimension().height
|
|
261
|
+
)
|
|
262
|
+
).toBe(35339);
|
|
263
|
+
});
|
|
264
|
+
it("applies horizontal content container padding to the list", () => {
|
|
265
|
+
const masonryFlashList = mountMasonryFlashList({
|
|
266
|
+
numColumns: 4,
|
|
267
|
+
contentContainerStyle: { paddingHorizontal: 10 },
|
|
268
|
+
});
|
|
269
|
+
expect(masonryFlashList.findAll(ProgressiveListView).length).toBe(5);
|
|
270
|
+
masonryFlashList.findAll(ProgressiveListView).forEach((list, index) => {
|
|
271
|
+
if (index === 0) {
|
|
272
|
+
expect(list.instance.getRenderedSize().width).toBe(400);
|
|
273
|
+
expect(list.instance.getRenderedSize().height).toBe(900);
|
|
274
|
+
} else {
|
|
275
|
+
expect(list.instance.getRenderedSize().width).toBe(95);
|
|
276
|
+
expect(list.instance.getRenderedSize().height).toBe(900);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
masonryFlashList.unmount();
|
|
280
|
+
});
|
|
281
|
+
it("divides columns equally if no getColumnFlex is passed", () => {
|
|
282
|
+
const masonryFlashList = mountMasonryFlashList({
|
|
283
|
+
numColumns: 4,
|
|
284
|
+
});
|
|
285
|
+
const progressiveListView =
|
|
286
|
+
masonryFlashList.find(ProgressiveListView)!.instance;
|
|
287
|
+
expect(progressiveListView.getLayout(0).width).toBe(100);
|
|
288
|
+
expect(progressiveListView.getLayout(1).width).toBe(100);
|
|
289
|
+
expect(progressiveListView.getLayout(2).width).toBe(100);
|
|
290
|
+
expect(progressiveListView.getLayout(3).width).toBe(100);
|
|
291
|
+
});
|
|
292
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCellContainerPlatformStyles,
|
|
3
|
+
getItemAnimator,
|
|
4
|
+
} from "../native/config/PlatformHelper.web";
|
|
5
|
+
|
|
6
|
+
describe("Platform Helper Web", () => {
|
|
7
|
+
it("can compute right transform for web", () => {
|
|
8
|
+
const transformStyle = getCellContainerPlatformStyles(false, {
|
|
9
|
+
x: 20,
|
|
10
|
+
y: 70,
|
|
11
|
+
});
|
|
12
|
+
const transformInvertedStyle = getCellContainerPlatformStyles(true, {
|
|
13
|
+
x: 30,
|
|
14
|
+
y: 30,
|
|
15
|
+
});
|
|
16
|
+
const transformHorizontalInvertedStyle = getCellContainerPlatformStyles(
|
|
17
|
+
true,
|
|
18
|
+
{
|
|
19
|
+
x: 30,
|
|
20
|
+
y: 30,
|
|
21
|
+
isHorizontal: true,
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
const expectedTransform = "translate(20px,70px)";
|
|
25
|
+
const expectedTransformInverted = "translate(30px,30px) scaleY(-1)";
|
|
26
|
+
const expectedTransformHorizontalInverted =
|
|
27
|
+
"translate(30px,30px) scaleX(-1)";
|
|
28
|
+
|
|
29
|
+
expect(transformStyle?.transform).toBe(expectedTransform);
|
|
30
|
+
expect(transformStyle?.WebkitTransform).toBe(expectedTransform);
|
|
31
|
+
expect(transformInvertedStyle?.transform).toBe(expectedTransformInverted);
|
|
32
|
+
expect(transformInvertedStyle?.WebkitTransform).toBe(
|
|
33
|
+
expectedTransformInverted
|
|
34
|
+
);
|
|
35
|
+
expect(transformHorizontalInvertedStyle?.transform).toBe(
|
|
36
|
+
expectedTransformHorizontalInverted
|
|
37
|
+
);
|
|
38
|
+
expect(transformHorizontalInvertedStyle?.WebkitTransform).toBe(
|
|
39
|
+
expectedTransformHorizontalInverted
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
it("can return an animator", () => {
|
|
43
|
+
expect(getItemAnimator()!["animateWillMount"]).toBeDefined();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "../recyclerview/layout-managers/LayoutManager";
|
|
1
|
+
import { Dimension, Layout } from "recyclerlistview";
|
|
2
|
+
|
|
3
|
+
import CustomError from "../errors/CustomError";
|
|
4
|
+
import ExceptionList from "../errors/ExceptionList";
|
|
5
|
+
import ViewabilityHelper from "../viewability/ViewabilityHelper";
|
|
7
6
|
|
|
8
7
|
describe("ViewabilityHelper", () => {
|
|
9
8
|
const viewableIndicesChanged = jest.fn();
|
|
@@ -62,7 +61,7 @@ describe("ViewabilityHelper", () => {
|
|
|
62
61
|
);
|
|
63
62
|
viewabilityHelper.possiblyViewableIndices = [0, 1, 2, 3];
|
|
64
63
|
const getLayout = (index: number) => {
|
|
65
|
-
return { x: index * 100, y: 0, height: 300, width: 100 } as
|
|
64
|
+
return { x: index * 100, y: 0, height: 300, width: 100 } as Layout;
|
|
66
65
|
};
|
|
67
66
|
updateViewableItems({ viewabilityHelper, horizontal: true, getLayout });
|
|
68
67
|
expect(viewableIndicesChanged).toHaveBeenCalledWith(
|
|
@@ -161,9 +160,9 @@ describe("ViewabilityHelper", () => {
|
|
|
161
160
|
it("reports items that only satisfy viewAreaCoveragePercentThreshold", () => {
|
|
162
161
|
const getLayout = (index: number) => {
|
|
163
162
|
if (index === 4) {
|
|
164
|
-
return { x: 0, y: index * 100, width: 100, height: 25 } as
|
|
163
|
+
return { x: 0, y: index * 100, width: 100, height: 25 } as Layout;
|
|
165
164
|
}
|
|
166
|
-
return { x: 0, y: index * 100, height: 100, width: 300 } as
|
|
165
|
+
return { x: 0, y: index * 100, height: 100, width: 300 } as Layout;
|
|
167
166
|
};
|
|
168
167
|
const viewabilityHelper = new ViewabilityHelper(
|
|
169
168
|
{ viewAreaCoveragePercentThreshold: 25 },
|
|
@@ -247,7 +246,9 @@ describe("ViewabilityHelper", () => {
|
|
|
247
246
|
viewableIndicesChanged
|
|
248
247
|
);
|
|
249
248
|
expect(() => updateViewableItems({ viewabilityHelper })).toThrow(
|
|
250
|
-
|
|
249
|
+
new CustomError(
|
|
250
|
+
ExceptionList.multipleViewabilityThresholdTypesNotSupported
|
|
251
|
+
)
|
|
251
252
|
);
|
|
252
253
|
});
|
|
253
254
|
|
|
@@ -262,8 +263,8 @@ describe("ViewabilityHelper", () => {
|
|
|
262
263
|
viewabilityHelper: ViewabilityHelper;
|
|
263
264
|
horizontal?: boolean;
|
|
264
265
|
scrollOffset?: number;
|
|
265
|
-
listSize?:
|
|
266
|
-
getLayout?: (index: number) =>
|
|
266
|
+
listSize?: Dimension;
|
|
267
|
+
getLayout?: (index: number) => Layout | undefined;
|
|
267
268
|
runAllTimers?: boolean;
|
|
268
269
|
}) => {
|
|
269
270
|
viewabilityHelper.updateViewableItems(
|
|
@@ -272,7 +273,7 @@ describe("ViewabilityHelper", () => {
|
|
|
272
273
|
listSize ?? { height: 300, width: 300 },
|
|
273
274
|
getLayout ??
|
|
274
275
|
((index) => {
|
|
275
|
-
return { x: 0, y: index * 100, height: 100, width: 300 } as
|
|
276
|
+
return { x: 0, y: index * 100, height: 100, width: 300 } as Layout;
|
|
276
277
|
})
|
|
277
278
|
);
|
|
278
279
|
if (runAllTimers ?? true) {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Text } from "react-native";
|
|
3
|
+
import "@quilted/react-testing/matchers";
|
|
4
|
+
import { render, Root } from "@quilted/react-testing";
|
|
5
|
+
|
|
6
|
+
import FlashList from "../../FlashList";
|
|
7
|
+
import { FlashListProps, ListRenderItem } from "../../FlashListProps";
|
|
8
|
+
|
|
9
|
+
jest.mock("../../FlashList", () => {
|
|
10
|
+
const ActualFlashList = jest.requireActual("../../FlashList").default;
|
|
11
|
+
class MockFlashList extends ActualFlashList {
|
|
12
|
+
componentDidMount() {
|
|
13
|
+
super.componentDidMount();
|
|
14
|
+
this.rlvRef?._scrollComponent?._scrollViewRef?.props.onLayout({
|
|
15
|
+
nativeEvent: { layout: { height: 900, width: 400 } },
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return MockFlashList;
|
|
20
|
+
});
|
|
21
|
+
export type MockFlashListProps = Omit<
|
|
22
|
+
FlashListProps<string>,
|
|
23
|
+
"estimatedItemSize" | "data" | "renderItem"
|
|
24
|
+
> & {
|
|
25
|
+
estimatedItemSize?: number;
|
|
26
|
+
data?: string[];
|
|
27
|
+
renderItem?: ListRenderItem<string>;
|
|
28
|
+
disableDefaultEstimatedItemSize?: boolean;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Helper to mount FlashList for testing.
|
|
32
|
+
*/
|
|
33
|
+
export const mountFlashList = (
|
|
34
|
+
props?: MockFlashListProps,
|
|
35
|
+
ref?: React.RefObject<FlashList<string>>
|
|
36
|
+
) => {
|
|
37
|
+
const flashList = render(renderFlashList(props, ref)) as Omit<
|
|
38
|
+
Root<FlashListProps<string>>,
|
|
39
|
+
"instance"
|
|
40
|
+
> & {
|
|
41
|
+
instance: FlashList<string>;
|
|
42
|
+
};
|
|
43
|
+
return flashList;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export function renderFlashList(
|
|
47
|
+
props?: MockFlashListProps,
|
|
48
|
+
ref?: React.RefObject<FlashList<string>>
|
|
49
|
+
) {
|
|
50
|
+
return (
|
|
51
|
+
<FlashList
|
|
52
|
+
{...props}
|
|
53
|
+
ref={ref}
|
|
54
|
+
renderItem={props?.renderItem || (({ item }) => <Text>{item}</Text>)}
|
|
55
|
+
estimatedItemSize={
|
|
56
|
+
props?.estimatedItemSize ??
|
|
57
|
+
(props?.disableDefaultEstimatedItemSize ? undefined : 200)
|
|
58
|
+
}
|
|
59
|
+
data={props?.data || ["One", "Two", "Three", "Four"]}
|
|
60
|
+
/>
|
|
61
|
+
);
|
|
62
|
+
}
|