@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
package/src/FlashListProps.ts
CHANGED
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
ViewStyle,
|
|
7
7
|
} from "react-native";
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import { BlankAreaEventHandler } from "./native/auto-layout/AutoLayoutView";
|
|
10
|
+
import ViewToken from "./viewability/ViewToken";
|
|
10
11
|
|
|
11
12
|
export interface ListRenderItemInfo<TItem> {
|
|
12
13
|
item: TItem;
|
|
@@ -39,6 +40,18 @@ export type ListRenderItem<TItem> = (
|
|
|
39
40
|
info: ListRenderItemInfo<TItem>
|
|
40
41
|
) => React.ReactElement | null;
|
|
41
42
|
|
|
43
|
+
export type ContentStyle = Pick<
|
|
44
|
+
ViewStyle,
|
|
45
|
+
| "backgroundColor"
|
|
46
|
+
| "paddingTop"
|
|
47
|
+
| "paddingLeft"
|
|
48
|
+
| "paddingRight"
|
|
49
|
+
| "paddingBottom"
|
|
50
|
+
| "padding"
|
|
51
|
+
| "paddingVertical"
|
|
52
|
+
| "paddingHorizontal"
|
|
53
|
+
>;
|
|
54
|
+
|
|
42
55
|
export interface ViewabilityConfigCallbackPair<TItem> {
|
|
43
56
|
viewabilityConfig: ViewabilityConfig;
|
|
44
57
|
onViewableItemsChanged:
|
|
@@ -76,6 +89,14 @@ export interface FlashListProps<TItem>
|
|
|
76
89
|
*/
|
|
77
90
|
data: ReadonlyArray<TItem> | null | undefined;
|
|
78
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Average or median size for elements in the list. Doesn't have to be very accurate but a good estimate can improve performance.
|
|
94
|
+
* A quick look at `Element Inspector` can help you determine this. If you're confused between two values, the smaller value is a better choice.
|
|
95
|
+
* For vertical lists provide average height and for horizontal average width.
|
|
96
|
+
* Read more about it here: https://shopify.github.io/flash-list/docs/estimated-item-size
|
|
97
|
+
*/
|
|
98
|
+
estimatedItemSize?: number;
|
|
99
|
+
|
|
79
100
|
/**
|
|
80
101
|
* Each cell is rendered using this element.
|
|
81
102
|
* Can be a React Component Class, or a render function.
|
|
@@ -144,11 +165,30 @@ export interface FlashListProps<TItem>
|
|
|
144
165
|
| React.ComponentType<ScrollViewProps>
|
|
145
166
|
| React.FC<ScrollViewProps>;
|
|
146
167
|
|
|
168
|
+
/**
|
|
169
|
+
* You can use `contentContainerStyle` to apply padding that will be applied to the whole content itself.
|
|
170
|
+
* For example, you can apply this padding, so that all of your items have leading and trailing space.
|
|
171
|
+
*/
|
|
172
|
+
contentContainerStyle?: ContentStyle;
|
|
173
|
+
|
|
147
174
|
/**
|
|
148
175
|
* Draw distance for advanced rendering (in dp/px)
|
|
149
176
|
*/
|
|
150
177
|
drawDistance?: number;
|
|
151
178
|
|
|
179
|
+
/**
|
|
180
|
+
* Specifies how far the first item is drawn from start of the list window or, offset of the first item of the list (not the header).
|
|
181
|
+
* Needed if you're using initialScrollIndex prop. Before the initial draw the list cannot figure out the size of header or, any special margin/padding that might have been applied
|
|
182
|
+
* using header styles etc.
|
|
183
|
+
* If this isn't provided initialScrollIndex might not scroll to the provided index.
|
|
184
|
+
*/
|
|
185
|
+
estimatedFirstItemOffset?: number;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Visible height and width of the list. This is not the scroll content size.
|
|
189
|
+
*/
|
|
190
|
+
estimatedListSize?: { height: number; width: number };
|
|
191
|
+
|
|
152
192
|
/**
|
|
153
193
|
* A marker property for telling the list to re-render (since it implements PureComponent).
|
|
154
194
|
* If any of your `renderItem`, Header, Footer, etc. functions depend on anything outside of the `data` prop,
|
|
@@ -166,6 +206,11 @@ export interface FlashListProps<TItem>
|
|
|
166
206
|
*/
|
|
167
207
|
initialScrollIndex?: number | null | undefined;
|
|
168
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Reverses the direction of scroll. Uses scale transforms of -1.
|
|
211
|
+
*/
|
|
212
|
+
inverted?: boolean | null | undefined;
|
|
213
|
+
|
|
169
214
|
/**
|
|
170
215
|
* Used to extract a unique key for a given item at the specified index.
|
|
171
216
|
* Key is used for optimizing performance. Defining `keyExtractor` is also necessary
|
|
@@ -180,6 +225,18 @@ export interface FlashListProps<TItem>
|
|
|
180
225
|
*/
|
|
181
226
|
numColumns?: number | undefined;
|
|
182
227
|
|
|
228
|
+
/**
|
|
229
|
+
* Computes blank space that is visible to the user during scroll or list load. If list doesn't have enough items to fill the screen even then this will be raised.
|
|
230
|
+
* Values reported: {
|
|
231
|
+
* offsetStart -> visible blank space on top of the screen (while going up). If value is greater than 0 then it's visible to user.
|
|
232
|
+
* offsetEnd -> visible blank space at the end of the screen (while going down). If value is greater than 0 then it's visible to user.
|
|
233
|
+
* blankArea -> max(offsetStart, offsetEnd) use this directly and look for values > 0
|
|
234
|
+
* }
|
|
235
|
+
* Please note that this event isn't synced with onScroll event but works with native onDraw/layoutSubviews. Events with values > 0 are blanks.
|
|
236
|
+
* This event is raised even when there is no visible blank with negative values for extensibility however, for most use cases check blankArea > 0 and use the value.
|
|
237
|
+
*/
|
|
238
|
+
onBlankArea?: BlankAreaEventHandler;
|
|
239
|
+
|
|
183
240
|
/**
|
|
184
241
|
* Called once when the scroll position gets within onEndReachedThreshold of the rendered content.
|
|
185
242
|
*/
|
|
@@ -235,7 +292,11 @@ export interface FlashListProps<TItem>
|
|
|
235
292
|
) => string | number | undefined;
|
|
236
293
|
|
|
237
294
|
/**
|
|
238
|
-
* This method can be used to change column span of an item.
|
|
295
|
+
* This method can be used to provide explicit size estimates or change column span of an item.
|
|
296
|
+
*
|
|
297
|
+
* Providing specific estimates is a good idea when you can calculate sizes reliably. FlashList will prefer this value over `estimatedItemSize` for that specific item.
|
|
298
|
+
* Precise estimates will also improve precision of `scrollToIndex` method and `initialScrollIndex` prop. If you have a `separator` below your items you can include its size in the estimate.
|
|
299
|
+
*
|
|
239
300
|
* Changing item span is useful when you have grid layouts (numColumns > 1) and you want few items to be bigger than the rest.
|
|
240
301
|
*
|
|
241
302
|
* Modify the given layout. Do not return. FlashList will fallback to default values if this is ignored.
|
|
@@ -243,7 +304,7 @@ export interface FlashListProps<TItem>
|
|
|
243
304
|
* Performance: This method is called very frequently. Keep it fast.
|
|
244
305
|
*/
|
|
245
306
|
overrideItemLayout?: (
|
|
246
|
-
layout: { span?: number },
|
|
307
|
+
layout: { span?: number; size?: number },
|
|
247
308
|
item: TItem,
|
|
248
309
|
index: number,
|
|
249
310
|
maxColumns: number,
|
|
@@ -281,6 +342,21 @@ export interface FlashListProps<TItem>
|
|
|
281
342
|
| ViewabilityConfigCallbackPairs<TItem>
|
|
282
343
|
| undefined;
|
|
283
344
|
|
|
345
|
+
/**
|
|
346
|
+
* FlashList attempts to measure size of horizontal lists by drawing an extra list item in advance. This can sometimes cause issues when used with `initialScrollIndex` in lists
|
|
347
|
+
* with very little content. You might see some amount of over scroll. When set to true the list's rendered size needs to be deterministic (i.e., height and width greater than 0)
|
|
348
|
+
* as FlashList will skip rendering the extra item for measurement. Default value is `false`.
|
|
349
|
+
*/
|
|
350
|
+
disableHorizontalListHeightMeasurement?: boolean;
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* FlashList applies some fixes to layouts of its children which can conflict with custom `CellRendererComponent`
|
|
354
|
+
* implementations. You can disable this behavior by setting this to `true`.
|
|
355
|
+
* Recommendation: Set this to `true` while you apply special behavior to the `CellRendererComponent`. Once done set this to
|
|
356
|
+
* `false` again.
|
|
357
|
+
*/
|
|
358
|
+
disableAutoLayout?: boolean;
|
|
359
|
+
|
|
284
360
|
/**
|
|
285
361
|
* New arch only
|
|
286
362
|
* Maximum number of items in the recycle pool. These are the items that are cached in the recycle pool when they are scrolled off the screen.
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Dimension,
|
|
3
|
+
GridLayoutProvider,
|
|
4
|
+
Layout,
|
|
5
|
+
LayoutManager,
|
|
6
|
+
} from "recyclerlistview";
|
|
7
|
+
|
|
8
|
+
import { FlashListProps } from "./FlashListProps";
|
|
9
|
+
import { AverageWindow } from "./utils/AverageWindow";
|
|
10
|
+
import { applyContentContainerInsetForLayoutManager } from "./utils/ContentContainerUtils";
|
|
11
|
+
|
|
12
|
+
export default class GridLayoutProviderWithProps<T> extends GridLayoutProvider {
|
|
13
|
+
private props: FlashListProps<T>;
|
|
14
|
+
private layoutObject = { span: undefined, size: undefined };
|
|
15
|
+
private averageWindow: AverageWindow;
|
|
16
|
+
private renderWindowInsets: Dimension = { width: 0, height: 0 };
|
|
17
|
+
private _hasExpired = false;
|
|
18
|
+
public defaultEstimatedItemSize = 100;
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
maxSpan: number,
|
|
22
|
+
getLayoutType: (
|
|
23
|
+
index: number,
|
|
24
|
+
props: FlashListProps<T>,
|
|
25
|
+
mutableLayout: { span?: number; size?: number }
|
|
26
|
+
) => string | number,
|
|
27
|
+
getSpan: (
|
|
28
|
+
index: number,
|
|
29
|
+
props: FlashListProps<T>,
|
|
30
|
+
mutableLayout: { span?: number; size?: number }
|
|
31
|
+
) => number,
|
|
32
|
+
getHeightOrWidth: (
|
|
33
|
+
index: number,
|
|
34
|
+
props: FlashListProps<T>,
|
|
35
|
+
mutableLayout: { span?: number; size?: number }
|
|
36
|
+
) => number | undefined,
|
|
37
|
+
props: FlashListProps<T>,
|
|
38
|
+
acceptableRelayoutDelta?: number
|
|
39
|
+
) {
|
|
40
|
+
super(
|
|
41
|
+
maxSpan,
|
|
42
|
+
(i) => {
|
|
43
|
+
return getLayoutType(i, this.props, this.getCleanLayoutObj());
|
|
44
|
+
},
|
|
45
|
+
(i) => {
|
|
46
|
+
return getSpan(i, this.props, this.getCleanLayoutObj());
|
|
47
|
+
},
|
|
48
|
+
(i) => {
|
|
49
|
+
return (
|
|
50
|
+
// Using average item size if no override has been provided by the developer
|
|
51
|
+
getHeightOrWidth(i, this.props, this.getCleanLayoutObj()) ??
|
|
52
|
+
this.averageItemSize
|
|
53
|
+
);
|
|
54
|
+
},
|
|
55
|
+
acceptableRelayoutDelta
|
|
56
|
+
);
|
|
57
|
+
this.props = props;
|
|
58
|
+
this.averageWindow = new AverageWindow(
|
|
59
|
+
1,
|
|
60
|
+
props.estimatedItemSize ?? this.defaultEstimatedItemSize
|
|
61
|
+
);
|
|
62
|
+
this.renderWindowInsets = this.getAdjustedRenderWindowSize(
|
|
63
|
+
this.renderWindowInsets
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public updateProps(props: FlashListProps<T>): GridLayoutProviderWithProps<T> {
|
|
68
|
+
const newInsetValues = applyContentContainerInsetForLayoutManager(
|
|
69
|
+
{
|
|
70
|
+
height: 0,
|
|
71
|
+
width: 0,
|
|
72
|
+
},
|
|
73
|
+
props.contentContainerStyle,
|
|
74
|
+
Boolean(props.horizontal)
|
|
75
|
+
);
|
|
76
|
+
this._hasExpired =
|
|
77
|
+
this._hasExpired ||
|
|
78
|
+
this.props.numColumns !== props.numColumns ||
|
|
79
|
+
newInsetValues.height !== this.renderWindowInsets.height ||
|
|
80
|
+
newInsetValues.width !== this.renderWindowInsets.width;
|
|
81
|
+
this.renderWindowInsets = newInsetValues;
|
|
82
|
+
this.props = props;
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* This methods returns true if the layout provider has expired and needs to be recreated.
|
|
88
|
+
* This can happen if the number of columns has changed or the render window size has changed in a way that cannot be handled by the layout provider internally.
|
|
89
|
+
*/
|
|
90
|
+
public get hasExpired() {
|
|
91
|
+
return this._hasExpired;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Calling this method will mark the layout provider as expired. As a result, a new one will be created by FlashList and old cached layouts will be discarded.
|
|
96
|
+
*/
|
|
97
|
+
public markExpired() {
|
|
98
|
+
this._hasExpired = true;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Calling this method will help the layout provider track average item sizes on its own
|
|
103
|
+
* Overriding layout manager can help achieve the same thing without relying on this method being called however, it will make implementation very complex for a simple use case
|
|
104
|
+
* @param index Index of the item being reported
|
|
105
|
+
*/
|
|
106
|
+
public reportItemLayout(index: number) {
|
|
107
|
+
const layout = this.getLayoutManager()?.getLayouts()[index];
|
|
108
|
+
if (layout) {
|
|
109
|
+
// For the same index we can now return different estimates because average is updated in realtime
|
|
110
|
+
// Marking the layout as overridden will help layout manager avoid using the average after initial measurement
|
|
111
|
+
layout.isOverridden = true;
|
|
112
|
+
this.averageWindow.addValue(
|
|
113
|
+
this.props.horizontal ? layout.width : layout.height
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public get averageItemSize() {
|
|
119
|
+
return this.averageWindow.currentValue;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public newLayoutManager(
|
|
123
|
+
renderWindowSize: Dimension,
|
|
124
|
+
isHorizontal?: boolean,
|
|
125
|
+
cachedLayouts?: Layout[]
|
|
126
|
+
): LayoutManager {
|
|
127
|
+
// Average window is updated whenever a new layout manager is created. This is because old values are not relevant anymore.
|
|
128
|
+
const estimatedItemCount = Math.max(
|
|
129
|
+
3,
|
|
130
|
+
Math.round(
|
|
131
|
+
(this.props.horizontal
|
|
132
|
+
? renderWindowSize.width
|
|
133
|
+
: renderWindowSize.height) /
|
|
134
|
+
(this.props.estimatedItemSize ?? this.defaultEstimatedItemSize)
|
|
135
|
+
)
|
|
136
|
+
);
|
|
137
|
+
this.averageWindow = new AverageWindow(
|
|
138
|
+
2 * (this.props.numColumns || 1) * estimatedItemCount,
|
|
139
|
+
this.averageWindow.currentValue
|
|
140
|
+
);
|
|
141
|
+
const newLayoutManager = super.newLayoutManager(
|
|
142
|
+
this.getAdjustedRenderWindowSize(renderWindowSize),
|
|
143
|
+
isHorizontal,
|
|
144
|
+
cachedLayouts
|
|
145
|
+
);
|
|
146
|
+
if (cachedLayouts) {
|
|
147
|
+
this.updateCachedDimensions(cachedLayouts, newLayoutManager);
|
|
148
|
+
}
|
|
149
|
+
return newLayoutManager;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
private updateCachedDimensions(
|
|
153
|
+
cachedLayouts: Layout[],
|
|
154
|
+
layoutManager: LayoutManager
|
|
155
|
+
) {
|
|
156
|
+
const layoutCount = cachedLayouts.length;
|
|
157
|
+
for (let i = 0; i < layoutCount; i++) {
|
|
158
|
+
cachedLayouts[i] = {
|
|
159
|
+
...cachedLayouts[i],
|
|
160
|
+
// helps in updating the fixed dimension of layouts e.g, width in case of horizontal list
|
|
161
|
+
// updating them in advance will make sure layout manager won't try to fit more items in the same row or column
|
|
162
|
+
...layoutManager.getStyleOverridesForIndex(i),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private getCleanLayoutObj() {
|
|
168
|
+
this.layoutObject.size = undefined;
|
|
169
|
+
this.layoutObject.span = undefined;
|
|
170
|
+
return this.layoutObject;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private getAdjustedRenderWindowSize(renderWindowSize: Dimension) {
|
|
174
|
+
return applyContentContainerInsetForLayoutManager(
|
|
175
|
+
{ ...renderWindowSize },
|
|
176
|
+
this.props.contentContainerStyle,
|
|
177
|
+
Boolean(this.props.horizontal)
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
}
|