@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,476 @@
|
|
|
1
|
+
import React, { useCallback, useRef, useEffect, useMemo } from "react";
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
Dimensions,
|
|
5
|
+
ScrollViewProps,
|
|
6
|
+
LayoutChangeEvent,
|
|
7
|
+
NativeScrollEvent,
|
|
8
|
+
NativeSyntheticEvent,
|
|
9
|
+
} from "react-native";
|
|
10
|
+
|
|
11
|
+
import CustomError from "./errors/CustomError";
|
|
12
|
+
import ExceptionList from "./errors/ExceptionList";
|
|
13
|
+
import FlashList from "./FlashList";
|
|
14
|
+
import { FlashListProps, ListRenderItemInfo } from "./FlashListProps";
|
|
15
|
+
import { applyContentContainerInsetForLayoutManager } from "./utils/ContentContainerUtils";
|
|
16
|
+
import ViewToken from "./viewability/ViewToken";
|
|
17
|
+
|
|
18
|
+
export interface MasonryListRenderItemInfo<TItem>
|
|
19
|
+
extends ListRenderItemInfo<TItem> {
|
|
20
|
+
columnSpan: number;
|
|
21
|
+
columnIndex: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type MasonryListRenderItem<TItem> = (
|
|
25
|
+
info: MasonryListRenderItemInfo<TItem>
|
|
26
|
+
) => React.ReactElement | null;
|
|
27
|
+
|
|
28
|
+
export interface MasonryFlashListProps<T>
|
|
29
|
+
extends Omit<
|
|
30
|
+
FlashListProps<T>,
|
|
31
|
+
| "horizontal"
|
|
32
|
+
| "initialScrollIndex"
|
|
33
|
+
| "inverted"
|
|
34
|
+
| "onBlankArea"
|
|
35
|
+
| "renderItem"
|
|
36
|
+
| "viewabilityConfigCallbackPairs"
|
|
37
|
+
> {
|
|
38
|
+
/**
|
|
39
|
+
* Allows you to change the column widths of the list. This is helpful if you want some columns to be wider than the others.
|
|
40
|
+
* e.g, if `numColumns` is `3`, you can return `2` for `index 1` and `1` for the rest to achieve a `1:2:1` split by width.
|
|
41
|
+
*/
|
|
42
|
+
getColumnFlex?: (
|
|
43
|
+
items: MasonryListItem<T>[],
|
|
44
|
+
columnIndex: number,
|
|
45
|
+
maxColumns: number,
|
|
46
|
+
extraData?: any
|
|
47
|
+
) => number;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* If enabled, MasonryFlashList will try to reduce difference in column height by modifying item order.
|
|
51
|
+
* `overrideItemLayout` is required to make this work.
|
|
52
|
+
*/
|
|
53
|
+
optimizeItemArrangement?: boolean;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Extends typical `renderItem` to include `columnIndex` and `columnSpan` (number of columns the item spans).
|
|
57
|
+
* `columnIndex` gives the consumer column information in case they might need to treat items differently based on column.
|
|
58
|
+
* This information may not otherwise be derived if using the `optimizeItemArrangement` feature, as the items will no
|
|
59
|
+
* longer be linearly distributed across the columns; instead they are allocated to the column with the least estimated height.
|
|
60
|
+
*/
|
|
61
|
+
renderItem: MasonryListRenderItem<T> | null | undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
type OnScrollCallback = ScrollViewProps["onScroll"];
|
|
65
|
+
const defaultEstimatedItemSize = 100;
|
|
66
|
+
|
|
67
|
+
export interface MasonryFlashListScrollEvent extends NativeScrollEvent {
|
|
68
|
+
doNotPropagate?: boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface MasonryListItem<T> {
|
|
72
|
+
originalIndex: number;
|
|
73
|
+
originalItem: T;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* MasonryFlashListRef with support for scroll related methods
|
|
78
|
+
*/
|
|
79
|
+
export interface MasonryFlashListRef<T> {
|
|
80
|
+
scrollToOffset: FlashList<T>["scrollToOffset"];
|
|
81
|
+
scrollToEnd: FlashList<T>["scrollToEnd"];
|
|
82
|
+
getScrollableNode: FlashList<T>["getScrollableNode"];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* FlashList variant that enables rendering of masonry layouts.
|
|
87
|
+
* If you want `MasonryFlashList` to optimize item arrangement, enable `optimizeItemArrangement` and pass a valid `overrideItemLayout` function.
|
|
88
|
+
*/
|
|
89
|
+
const MasonryFlashListComponent = React.forwardRef(
|
|
90
|
+
<T,>(
|
|
91
|
+
/**
|
|
92
|
+
* Forward Ref will force cast generic parament T to unknown. Export has a explicit cast to solve this.
|
|
93
|
+
*/
|
|
94
|
+
props: MasonryFlashListProps<T>,
|
|
95
|
+
forwardRef: React.ForwardedRef<MasonryFlashListRef<T>>
|
|
96
|
+
) => {
|
|
97
|
+
const columnCount = props.numColumns || 1;
|
|
98
|
+
const drawDistance = props.drawDistance;
|
|
99
|
+
const estimatedListSize = props.estimatedListSize ??
|
|
100
|
+
Dimensions.get("window") ?? { height: 500, width: 500 };
|
|
101
|
+
|
|
102
|
+
if (props.optimizeItemArrangement && !props.overrideItemLayout) {
|
|
103
|
+
throw new CustomError(
|
|
104
|
+
ExceptionList.overrideItemLayoutRequiredForMasonryOptimization
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
const dataSet = useDataSet(
|
|
108
|
+
columnCount,
|
|
109
|
+
Boolean(props.optimizeItemArrangement),
|
|
110
|
+
props.data,
|
|
111
|
+
props.overrideItemLayout,
|
|
112
|
+
props.extraData
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const totalColumnFlex = useTotalColumnFlex(dataSet, props);
|
|
116
|
+
|
|
117
|
+
const propsRef = useRef(props);
|
|
118
|
+
propsRef.current = props;
|
|
119
|
+
|
|
120
|
+
const onScrollRef = useRef<OnScrollCallback[]>([]);
|
|
121
|
+
const emptyScrollEvent = useRef(getEmptyScrollEvent())
|
|
122
|
+
.current as NativeSyntheticEvent<MasonryFlashListScrollEvent>;
|
|
123
|
+
const ScrollComponent = useRef(
|
|
124
|
+
getFlashListScrollView(onScrollRef, () => {
|
|
125
|
+
return (
|
|
126
|
+
getListRenderedSize(parentFlashList)?.height ||
|
|
127
|
+
estimatedListSize.height
|
|
128
|
+
);
|
|
129
|
+
})
|
|
130
|
+
).current;
|
|
131
|
+
|
|
132
|
+
const onScrollProxy = useRef<OnScrollCallback>(
|
|
133
|
+
(scrollEvent: NativeSyntheticEvent<MasonryFlashListScrollEvent>) => {
|
|
134
|
+
emptyScrollEvent.nativeEvent.contentOffset.y =
|
|
135
|
+
scrollEvent.nativeEvent.contentOffset.y -
|
|
136
|
+
(parentFlashList.current?.firstItemOffset ?? 0);
|
|
137
|
+
onScrollRef.current?.forEach((onScrollCallback) => {
|
|
138
|
+
onScrollCallback?.(emptyScrollEvent);
|
|
139
|
+
});
|
|
140
|
+
if (!scrollEvent.nativeEvent.doNotPropagate) {
|
|
141
|
+
propsRef.current.onScroll?.(scrollEvent);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
).current;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* We're triggering an onScroll on internal lists so that they register the correct offset which is offset - header size.
|
|
148
|
+
* This will make sure viewability callbacks are triggered correctly.
|
|
149
|
+
* 32 ms is equal to two frames at 60 fps. Faster framerates will not cause any problems.
|
|
150
|
+
*/
|
|
151
|
+
const onLoadForNestedLists = useRef((args: { elapsedTimeInMs: number }) => {
|
|
152
|
+
setTimeout(() => {
|
|
153
|
+
emptyScrollEvent.nativeEvent.doNotPropagate = true;
|
|
154
|
+
onScrollProxy?.(emptyScrollEvent);
|
|
155
|
+
emptyScrollEvent.nativeEvent.doNotPropagate = false;
|
|
156
|
+
}, 32);
|
|
157
|
+
propsRef.current.onLoad?.(args);
|
|
158
|
+
}).current;
|
|
159
|
+
|
|
160
|
+
const [parentFlashList, getFlashList] =
|
|
161
|
+
useRefWithForwardRef<FlashList<MasonryListItem<T>[]>>(forwardRef);
|
|
162
|
+
|
|
163
|
+
const {
|
|
164
|
+
renderItem,
|
|
165
|
+
getItemType,
|
|
166
|
+
getColumnFlex,
|
|
167
|
+
overrideItemLayout,
|
|
168
|
+
viewabilityConfig,
|
|
169
|
+
keyExtractor,
|
|
170
|
+
onLoad,
|
|
171
|
+
onViewableItemsChanged,
|
|
172
|
+
data,
|
|
173
|
+
stickyHeaderIndices,
|
|
174
|
+
CellRendererComponent,
|
|
175
|
+
ItemSeparatorComponent,
|
|
176
|
+
...remainingProps
|
|
177
|
+
} = props;
|
|
178
|
+
|
|
179
|
+
const firstColumnHeight =
|
|
180
|
+
(dataSet[0]?.length ?? 0) *
|
|
181
|
+
(props.estimatedItemSize ?? defaultEstimatedItemSize);
|
|
182
|
+
|
|
183
|
+
const insetForLayoutManager = applyContentContainerInsetForLayoutManager(
|
|
184
|
+
{ height: 0, width: 0 },
|
|
185
|
+
props.contentContainerStyle,
|
|
186
|
+
false
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
return (
|
|
190
|
+
<FlashList
|
|
191
|
+
ref={getFlashList}
|
|
192
|
+
{...remainingProps}
|
|
193
|
+
horizontal={false}
|
|
194
|
+
numColumns={columnCount}
|
|
195
|
+
data={dataSet}
|
|
196
|
+
onScroll={onScrollProxy}
|
|
197
|
+
estimatedItemSize={firstColumnHeight || estimatedListSize.height}
|
|
198
|
+
renderItem={(args) => {
|
|
199
|
+
return (
|
|
200
|
+
<FlashList
|
|
201
|
+
renderScrollComponent={ScrollComponent}
|
|
202
|
+
estimatedItemSize={props.estimatedItemSize}
|
|
203
|
+
data={args.item}
|
|
204
|
+
onLoad={args.index === 0 ? onLoadForNestedLists : undefined}
|
|
205
|
+
renderItem={(innerArgs) => {
|
|
206
|
+
return (
|
|
207
|
+
renderItem?.({
|
|
208
|
+
...innerArgs,
|
|
209
|
+
item: innerArgs.item.originalItem,
|
|
210
|
+
index: innerArgs.item.originalIndex,
|
|
211
|
+
columnSpan: 1,
|
|
212
|
+
columnIndex: args.index,
|
|
213
|
+
}) ?? null
|
|
214
|
+
);
|
|
215
|
+
}}
|
|
216
|
+
keyExtractor={
|
|
217
|
+
keyExtractor
|
|
218
|
+
? (item, _) => {
|
|
219
|
+
return keyExtractor?.(
|
|
220
|
+
item.originalItem,
|
|
221
|
+
item.originalIndex
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
: undefined
|
|
225
|
+
}
|
|
226
|
+
getItemType={
|
|
227
|
+
getItemType
|
|
228
|
+
? (item, _, extraData) => {
|
|
229
|
+
return getItemType?.(
|
|
230
|
+
item.originalItem,
|
|
231
|
+
item.originalIndex,
|
|
232
|
+
extraData
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
: undefined
|
|
236
|
+
}
|
|
237
|
+
drawDistance={drawDistance}
|
|
238
|
+
estimatedListSize={{
|
|
239
|
+
height: estimatedListSize.height,
|
|
240
|
+
width:
|
|
241
|
+
(((getListRenderedSize(parentFlashList)?.width ||
|
|
242
|
+
estimatedListSize.width) +
|
|
243
|
+
insetForLayoutManager.width) /
|
|
244
|
+
totalColumnFlex) *
|
|
245
|
+
(getColumnFlex?.(
|
|
246
|
+
args.item,
|
|
247
|
+
args.index,
|
|
248
|
+
columnCount,
|
|
249
|
+
props.extraData
|
|
250
|
+
) ?? 1),
|
|
251
|
+
}}
|
|
252
|
+
extraData={props.extraData}
|
|
253
|
+
CellRendererComponent={CellRendererComponent}
|
|
254
|
+
ItemSeparatorComponent={ItemSeparatorComponent}
|
|
255
|
+
viewabilityConfig={viewabilityConfig}
|
|
256
|
+
onViewableItemsChanged={
|
|
257
|
+
onViewableItemsChanged
|
|
258
|
+
? (info) => {
|
|
259
|
+
updateViewTokens(info.viewableItems);
|
|
260
|
+
updateViewTokens(info.changed);
|
|
261
|
+
onViewableItemsChanged?.(info as any);
|
|
262
|
+
}
|
|
263
|
+
: undefined
|
|
264
|
+
}
|
|
265
|
+
overrideItemLayout={
|
|
266
|
+
overrideItemLayout
|
|
267
|
+
? (layout, item, _, __, extraData) => {
|
|
268
|
+
overrideItemLayout?.(
|
|
269
|
+
layout,
|
|
270
|
+
item.originalItem,
|
|
271
|
+
item.originalIndex,
|
|
272
|
+
columnCount,
|
|
273
|
+
extraData
|
|
274
|
+
);
|
|
275
|
+
layout.span = undefined;
|
|
276
|
+
}
|
|
277
|
+
: undefined
|
|
278
|
+
}
|
|
279
|
+
/>
|
|
280
|
+
);
|
|
281
|
+
}}
|
|
282
|
+
overrideItemLayout={
|
|
283
|
+
getColumnFlex
|
|
284
|
+
? (layout, item, index, maxColumns, extraData) => {
|
|
285
|
+
layout.span =
|
|
286
|
+
(columnCount *
|
|
287
|
+
getColumnFlex(item, index, maxColumns, extraData)) /
|
|
288
|
+
totalColumnFlex;
|
|
289
|
+
}
|
|
290
|
+
: undefined
|
|
291
|
+
}
|
|
292
|
+
/>
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Splits data for each column's FlashList
|
|
299
|
+
*/
|
|
300
|
+
const useDataSet = <T,>(
|
|
301
|
+
columnCount: number,
|
|
302
|
+
optimizeItemArrangement: boolean,
|
|
303
|
+
sourceData?: FlashListProps<T>["data"],
|
|
304
|
+
overrideItemLayout?: MasonryFlashListProps<T>["overrideItemLayout"],
|
|
305
|
+
extraData?: MasonryFlashListProps<T>["extraData"]
|
|
306
|
+
): MasonryListItem<T>[][] => {
|
|
307
|
+
return useMemo(() => {
|
|
308
|
+
if (!sourceData || sourceData.length === 0) {
|
|
309
|
+
return [];
|
|
310
|
+
}
|
|
311
|
+
const columnHeightTracker = new Array<number>(columnCount).fill(0);
|
|
312
|
+
const layoutObject: { size: number | undefined } = { size: undefined };
|
|
313
|
+
const dataSet = new Array<MasonryListItem<T>[]>(columnCount);
|
|
314
|
+
const dataSize = sourceData.length;
|
|
315
|
+
|
|
316
|
+
for (let i = 0; i < columnCount; i++) {
|
|
317
|
+
dataSet[i] = [];
|
|
318
|
+
}
|
|
319
|
+
for (let i = 0; i < dataSize; i++) {
|
|
320
|
+
let nextColumnIndex = i % columnCount;
|
|
321
|
+
if (optimizeItemArrangement) {
|
|
322
|
+
for (let j = 0; j < columnCount; j++) {
|
|
323
|
+
if (columnHeightTracker[j] < columnHeightTracker[nextColumnIndex]) {
|
|
324
|
+
nextColumnIndex = j;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
// update height of column
|
|
328
|
+
layoutObject.size = undefined;
|
|
329
|
+
overrideItemLayout!(
|
|
330
|
+
layoutObject,
|
|
331
|
+
sourceData[i],
|
|
332
|
+
i,
|
|
333
|
+
columnCount,
|
|
334
|
+
extraData
|
|
335
|
+
);
|
|
336
|
+
columnHeightTracker[nextColumnIndex] +=
|
|
337
|
+
layoutObject.size ?? defaultEstimatedItemSize;
|
|
338
|
+
}
|
|
339
|
+
dataSet[nextColumnIndex].push({
|
|
340
|
+
originalItem: sourceData[i],
|
|
341
|
+
originalIndex: i,
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
return dataSet;
|
|
345
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
346
|
+
}, [sourceData, columnCount, optimizeItemArrangement, extraData]);
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const useTotalColumnFlex = <T,>(
|
|
350
|
+
dataSet: MasonryListItem<T>[][],
|
|
351
|
+
props: MasonryFlashListProps<T>
|
|
352
|
+
): number => {
|
|
353
|
+
return useMemo(() => {
|
|
354
|
+
const columnCount = props.numColumns || 1;
|
|
355
|
+
if (!props.getColumnFlex) {
|
|
356
|
+
return columnCount;
|
|
357
|
+
}
|
|
358
|
+
let totalFlexSum = 0;
|
|
359
|
+
const dataSize = dataSet.length;
|
|
360
|
+
for (let i = 0; i < dataSize; i++) {
|
|
361
|
+
totalFlexSum += props.getColumnFlex(
|
|
362
|
+
dataSet[i],
|
|
363
|
+
i,
|
|
364
|
+
columnCount,
|
|
365
|
+
props.extraData
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
return totalFlexSum;
|
|
369
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
370
|
+
}, [dataSet, props.getColumnFlex, props.extraData]);
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Handle both function refs and refs with current property
|
|
375
|
+
*/
|
|
376
|
+
const useRefWithForwardRef = <T,>(
|
|
377
|
+
forwardRef: any
|
|
378
|
+
): [React.MutableRefObject<T | null>, (instance: T | null) => void] => {
|
|
379
|
+
const ref: React.MutableRefObject<T | null> = useRef(null);
|
|
380
|
+
return [
|
|
381
|
+
ref,
|
|
382
|
+
useCallback(
|
|
383
|
+
(instance: T | null) => {
|
|
384
|
+
ref.current = instance;
|
|
385
|
+
if (typeof forwardRef === "function") {
|
|
386
|
+
forwardRef(instance);
|
|
387
|
+
} else if (forwardRef) {
|
|
388
|
+
forwardRef.current = instance;
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
[forwardRef]
|
|
392
|
+
),
|
|
393
|
+
];
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* This ScrollView is actually just a view mimicking a scrollview. We block the onScroll event from being passed to the parent list directly.
|
|
398
|
+
* We manually drive onScroll from the parent and thus, achieve recycling.
|
|
399
|
+
*/
|
|
400
|
+
const getFlashListScrollView = (
|
|
401
|
+
onScrollRef: React.RefObject<OnScrollCallback[]>,
|
|
402
|
+
getParentHeight: () => number
|
|
403
|
+
) => {
|
|
404
|
+
const FlashListScrollView = React.forwardRef(
|
|
405
|
+
(props: ScrollViewProps, ref: React.ForwardedRef<View>) => {
|
|
406
|
+
const { onLayout, onScroll, ...rest } = props;
|
|
407
|
+
const onLayoutProxy = useCallback(
|
|
408
|
+
(layoutEvent: LayoutChangeEvent) => {
|
|
409
|
+
onLayout?.({
|
|
410
|
+
nativeEvent: {
|
|
411
|
+
layout: {
|
|
412
|
+
height: getParentHeight(),
|
|
413
|
+
width: layoutEvent.nativeEvent.layout.width,
|
|
414
|
+
},
|
|
415
|
+
},
|
|
416
|
+
} as LayoutChangeEvent);
|
|
417
|
+
},
|
|
418
|
+
[onLayout]
|
|
419
|
+
);
|
|
420
|
+
useEffect(() => {
|
|
421
|
+
if (onScroll) {
|
|
422
|
+
onScrollRef.current?.push(onScroll);
|
|
423
|
+
}
|
|
424
|
+
return () => {
|
|
425
|
+
if (!onScrollRef.current || !onScroll) {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
const indexToDelete = onScrollRef.current.indexOf(onScroll);
|
|
429
|
+
if (indexToDelete > -1) {
|
|
430
|
+
onScrollRef.current.splice(indexToDelete, 1);
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
}, [onScroll]);
|
|
434
|
+
return <View ref={ref} {...rest} onLayout={onLayoutProxy} />;
|
|
435
|
+
}
|
|
436
|
+
);
|
|
437
|
+
FlashListScrollView.displayName = "FlashListScrollView";
|
|
438
|
+
return FlashListScrollView;
|
|
439
|
+
};
|
|
440
|
+
const updateViewTokens = (tokens: ViewToken<any>[]) => {
|
|
441
|
+
const length = tokens.length;
|
|
442
|
+
for (let i = 0; i < length; i++) {
|
|
443
|
+
const token = tokens[i];
|
|
444
|
+
if (token.index !== null && token.index !== undefined) {
|
|
445
|
+
if (token.item) {
|
|
446
|
+
token.index = token.item.originalIndex;
|
|
447
|
+
token.item = token.item.originalItem;
|
|
448
|
+
} else {
|
|
449
|
+
token.index = null;
|
|
450
|
+
token.item = undefined;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
const getEmptyScrollEvent = () => {
|
|
457
|
+
return {
|
|
458
|
+
nativeEvent: { contentOffset: { y: 0, x: 0 } },
|
|
459
|
+
};
|
|
460
|
+
};
|
|
461
|
+
const getListRenderedSize = <T,>(
|
|
462
|
+
parentFlashList: React.MutableRefObject<FlashList<T[]> | null>
|
|
463
|
+
) => {
|
|
464
|
+
return parentFlashList?.current?.recyclerlistview_unsafe?.getRenderedSize();
|
|
465
|
+
};
|
|
466
|
+
MasonryFlashListComponent.displayName = "MasonryFlashList";
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* FlashList variant that enables rendering of masonry layouts.
|
|
470
|
+
* If you want `MasonryFlashList` to optimize item arrangement, enable `optimizeItemArrangement` and pass a valid `overrideItemLayout` function.
|
|
471
|
+
*/
|
|
472
|
+
export const MasonryFlashList = MasonryFlashListComponent as <T>(
|
|
473
|
+
props: MasonryFlashListProps<T> & {
|
|
474
|
+
ref?: React.RefObject<MasonryFlashListRef<T>>;
|
|
475
|
+
}
|
|
476
|
+
) => React.ReactElement;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
export interface PureComponentWrapperProps {
|
|
4
|
+
renderer: (arg: unknown) => JSX.Element | null;
|
|
5
|
+
|
|
6
|
+
/** Renderer is called with this argument.
|
|
7
|
+
* Don't change this value everytime or else component will always rerender. Prefer primitives. */
|
|
8
|
+
arg?: unknown;
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
[other: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Pure component wrapper that can be used to prevent renders of the `renderer` method passed to the component. Any change in props will lead to `renderer` getting called.
|
|
15
|
+
*/
|
|
16
|
+
export class PureComponentWrapper extends React.PureComponent<PureComponentWrapperProps> {
|
|
17
|
+
static defaultProps = {
|
|
18
|
+
enabled: true,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
private overrideEnabled: boolean | undefined = undefined;
|
|
22
|
+
|
|
23
|
+
/** Once set explicitly, prop will be ignored. Not using state because of performance reasons. */
|
|
24
|
+
public setEnabled(enabled: boolean) {
|
|
25
|
+
if (enabled !== this.overrideEnabled) {
|
|
26
|
+
this.overrideEnabled = enabled;
|
|
27
|
+
this.forceUpdate();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
render() {
|
|
32
|
+
if (this.overrideEnabled === undefined) {
|
|
33
|
+
return (
|
|
34
|
+
(this.props.enabled && this.props.renderer(this.props.arg)) || null
|
|
35
|
+
);
|
|
36
|
+
} else {
|
|
37
|
+
return (
|
|
38
|
+
(this.overrideEnabled && this.props.renderer(this.props.arg)) || null
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyContentContainerInsetForLayoutManager,
|
|
3
|
+
getContentContainerPadding,
|
|
4
|
+
hasUnsupportedKeysInContentContainerStyle,
|
|
5
|
+
updateContentStyle,
|
|
6
|
+
} from "../utils/ContentContainerUtils";
|
|
7
|
+
|
|
8
|
+
describe("ContentContainerUtils", () => {
|
|
9
|
+
it("detects unsupported keys in style", () => {
|
|
10
|
+
expect(hasUnsupportedKeysInContentContainerStyle({ flex: 1 })).toBe(true);
|
|
11
|
+
expect(hasUnsupportedKeysInContentContainerStyle({ paddingTop: 0 })).toBe(
|
|
12
|
+
false
|
|
13
|
+
);
|
|
14
|
+
expect(
|
|
15
|
+
hasUnsupportedKeysInContentContainerStyle({
|
|
16
|
+
paddingTop: 1,
|
|
17
|
+
paddingVertical: 1,
|
|
18
|
+
})
|
|
19
|
+
).toBe(false);
|
|
20
|
+
expect(
|
|
21
|
+
hasUnsupportedKeysInContentContainerStyle({
|
|
22
|
+
paddingTop: 1,
|
|
23
|
+
paddingVertical: 1,
|
|
24
|
+
padding: 1,
|
|
25
|
+
paddingLeft: 1,
|
|
26
|
+
paddingRight: 1,
|
|
27
|
+
paddingBottom: 1,
|
|
28
|
+
backgroundColor: "red",
|
|
29
|
+
paddingHorizontal: 1,
|
|
30
|
+
})
|
|
31
|
+
).toBe(false);
|
|
32
|
+
expect(hasUnsupportedKeysInContentContainerStyle({ margin: 1 })).toBe(true);
|
|
33
|
+
expect(hasUnsupportedKeysInContentContainerStyle({ padding: 1 })).toBe(
|
|
34
|
+
false
|
|
35
|
+
);
|
|
36
|
+
expect(
|
|
37
|
+
hasUnsupportedKeysInContentContainerStyle({ backgroundColor: "red" })
|
|
38
|
+
).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
it("updated content style to have all supported styles defined", () => {
|
|
41
|
+
expect(
|
|
42
|
+
updateContentStyle({}, { padding: 1, backgroundColor: "red" })
|
|
43
|
+
).toEqual({
|
|
44
|
+
paddingTop: 1,
|
|
45
|
+
paddingBottom: 1,
|
|
46
|
+
paddingLeft: 1,
|
|
47
|
+
paddingRight: 1,
|
|
48
|
+
backgroundColor: "red",
|
|
49
|
+
});
|
|
50
|
+
expect(updateContentStyle({}, { paddingHorizontal: 1 })).toEqual({
|
|
51
|
+
paddingTop: 0,
|
|
52
|
+
paddingBottom: 0,
|
|
53
|
+
paddingLeft: 1,
|
|
54
|
+
paddingRight: 1,
|
|
55
|
+
});
|
|
56
|
+
expect(updateContentStyle({}, { paddingVertical: 1 })).toEqual({
|
|
57
|
+
paddingTop: 1,
|
|
58
|
+
paddingBottom: 1,
|
|
59
|
+
paddingLeft: 0,
|
|
60
|
+
paddingRight: 0,
|
|
61
|
+
});
|
|
62
|
+
expect(
|
|
63
|
+
updateContentStyle({}, { paddingLeft: 1, paddingVertical: 1 })
|
|
64
|
+
).toEqual({
|
|
65
|
+
paddingTop: 1,
|
|
66
|
+
paddingBottom: 1,
|
|
67
|
+
paddingLeft: 1,
|
|
68
|
+
paddingRight: 0,
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
it("computes correct layout manager insets", () => {
|
|
72
|
+
expect(
|
|
73
|
+
applyContentContainerInsetForLayoutManager(
|
|
74
|
+
{ height: 0, width: 0 },
|
|
75
|
+
{ padding: 1 },
|
|
76
|
+
false
|
|
77
|
+
)
|
|
78
|
+
).toEqual({ height: 0, width: -2 });
|
|
79
|
+
expect(
|
|
80
|
+
applyContentContainerInsetForLayoutManager(
|
|
81
|
+
{ height: 0, width: 0 },
|
|
82
|
+
{ padding: 1 },
|
|
83
|
+
true
|
|
84
|
+
)
|
|
85
|
+
).toEqual({ height: -2, width: 0 });
|
|
86
|
+
expect(
|
|
87
|
+
applyContentContainerInsetForLayoutManager(
|
|
88
|
+
{ height: 0, width: 0 },
|
|
89
|
+
{ paddingVertical: 1 },
|
|
90
|
+
true
|
|
91
|
+
)
|
|
92
|
+
).toEqual({ height: -2, width: 0 });
|
|
93
|
+
});
|
|
94
|
+
it("calculated correct padding for scrollview content", () => {
|
|
95
|
+
expect(
|
|
96
|
+
getContentContainerPadding(
|
|
97
|
+
{
|
|
98
|
+
paddingLeft: 1,
|
|
99
|
+
paddingTop: 1,
|
|
100
|
+
paddingBottom: 1,
|
|
101
|
+
paddingRight: 1,
|
|
102
|
+
backgroundColor: "red",
|
|
103
|
+
},
|
|
104
|
+
true
|
|
105
|
+
)
|
|
106
|
+
).toEqual({
|
|
107
|
+
paddingTop: 1,
|
|
108
|
+
paddingBottom: 1,
|
|
109
|
+
paddingLeft: undefined,
|
|
110
|
+
paddingRight: undefined,
|
|
111
|
+
});
|
|
112
|
+
expect(
|
|
113
|
+
getContentContainerPadding(
|
|
114
|
+
{
|
|
115
|
+
paddingLeft: 1,
|
|
116
|
+
paddingTop: 1,
|
|
117
|
+
paddingBottom: 1,
|
|
118
|
+
paddingRight: 1,
|
|
119
|
+
backgroundColor: "red",
|
|
120
|
+
},
|
|
121
|
+
false
|
|
122
|
+
)
|
|
123
|
+
).toEqual({
|
|
124
|
+
paddingTop: undefined,
|
|
125
|
+
paddingBottom: undefined,
|
|
126
|
+
paddingLeft: 1,
|
|
127
|
+
paddingRight: 1,
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|