@shopify/flash-list 2.0.1 → 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 +11 -2
- 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/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<a href="https://discord.gg/k2gzABTfav">Discord</a> •
|
|
6
6
|
<a href="https://shopify.github.io/flash-list/docs/">Getting started</a> •
|
|
7
7
|
<a href="https://shopify.github.io/flash-list/docs/usage">Usage</a> •
|
|
8
|
-
<a href="https://shopify.github.io/flash-list/docs/fundamentals/
|
|
8
|
+
<a href="https://shopify.github.io/flash-list/docs/fundamentals/performant-components">Writing performant components</a> •
|
|
9
9
|
<a href="https://shopify.github.io/flash-list/docs/known-issues">Known Issues</a>
|
|
10
10
|
<br><br>
|
|
11
11
|
|
|
@@ -19,41 +19,25 @@ Swap from FlatList in seconds. Get instant performance.
|
|
|
19
19
|
|
|
20
20
|
FlashList v2 has been rebuilt from the ground up for RN's new architecture and delivers fast performance, higher precision, and better ease of use compared to v1. We've achieved all this while moving to a JS-only solution! One of the key advantages of FlashList v2 is that it doesn't require any estimates. It also introduces several new features compared to v1. To know more about what's new in v2 click [here](https://shopify.github.io/flash-list/docs/v2-changes).
|
|
21
21
|
|
|
22
|
-
> ⚠️ **IMPORTANT:** FlashList v2.x has been designed to
|
|
22
|
+
> ⚠️ **IMPORTANT:** FlashList v2.x has been designed to fully leverage the new architecture. **Old architecture will only be supported while FlashList v2 is in alpha/beta/rc and will be dropped once it's ready.** When run on old architecture, we just fall back to v1.x which doesn't have any of the new features.
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
### Is v2 production ready?
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
Yes, please use one of the release candidates if you want to ship to production `2.0.0-rc.x`. While we can make some changes in the final version, we expect release candidates to be quite stable. Use the alpha track if you want to test new changes quickly and don't mind occasional bugs.
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
- Fast initial render: Optimized for quick first paint.
|
|
30
|
-
- Efficient memory usage: Recycles views instead of destroying them, reducing memory overhead.
|
|
31
|
-
- Supports view types: Great performance even if different types of components make up the list.
|
|
32
|
-
- Dynamic sizes: Super fast and doesn't need any estimates.
|
|
28
|
+
> ⚠️ **IMPORTANT:** FlashList v2.x's alpha track moves quickly and can have some issues. Please report any issues or edge cases you run into. We're actively working on testing and optimizing v2. We also highly recommend using it with RN 0.78+ for optimal performance.
|
|
33
29
|
|
|
34
|
-
###
|
|
30
|
+
### Old architecture / FlashList v1
|
|
35
31
|
|
|
36
|
-
|
|
37
|
-
- No size estimates required in v2: Unlike v1, FlashList v2 automatically handles item sizing.
|
|
38
|
-
- Type-safe: Full TypeScript support with comprehensive type definitions.
|
|
32
|
+
If you're running on old architecture or using FlashList v1.x, you can access the documentation specific to v1 here: [FlashList v1 Documentation](https://shopify.github.io/flash-list/docs/1.x/).
|
|
39
33
|
|
|
40
|
-
###
|
|
34
|
+
### Web support
|
|
41
35
|
|
|
42
|
-
|
|
43
|
-
- Maintain visible content position: Automatically handles content shifts when adding items (enabled by default in v2).
|
|
44
|
-
- Multiple recycling pools: Optimizes performance for lists with different item types using `getItemType`.
|
|
45
|
-
- Built for React Native's new architecture: FlashList v2 is designed specifically for the new architecture.
|
|
46
|
-
|
|
47
|
-
### ⚡ Real-world Benefits
|
|
48
|
-
|
|
49
|
-
- Reduced frame drops: Maintains 60 FPS even with complex item components.
|
|
50
|
-
- Lower CPU usage: Efficient recycling reduces computational overhead.
|
|
51
|
-
- Smoother scrolling: Predictable performance even with thousands of items.
|
|
52
|
-
- JS-only solution in v2: No native dependencies, making it easier to maintain while delivering fast performance.
|
|
36
|
+
FlashList v2 has web support. Most of the features should work but we're not actively testing it right now. If you run into an issue, please raise it on GitHub.
|
|
53
37
|
|
|
54
38
|
## Installation
|
|
55
39
|
|
|
56
|
-
Add the package to your project via `yarn add @shopify/flash-list
|
|
40
|
+
Add the package to your project via `yarn add @shopify/flash-list@rc` and run `pod install` in the `ios` directory.
|
|
57
41
|
|
|
58
42
|
## Usage
|
|
59
43
|
|
|
@@ -83,7 +67,93 @@ const MyList = () => {
|
|
|
83
67
|
};
|
|
84
68
|
```
|
|
85
69
|
|
|
86
|
-
To avoid common pitfalls, you can also follow these
|
|
70
|
+
To avoid common pitfalls, you can also follow these steps for migrating from `FlatList`, based on our own experience:
|
|
71
|
+
|
|
72
|
+
1. Simply change from `FlatList` to `FlashList` and render the list.
|
|
73
|
+
2. **Important**: Scan your [`renderItem`](https://shopify.github.io/flash-list/docs/usage/#renderitem) hierarchy for explicit `key` prop definitions and remove them. If you’re doing a `.map()` use our hook called [`useMappingHelper`](https://shopify.github.io/flash-list/docs/usage/#usemappinghelper).
|
|
74
|
+
3. Check your [`renderItem`](https://shopify.github.io/flash-list/docs/usage/#renderitem) hierarchy for components that make use of `useState` and verify whether that state would need to be reset if a different item is passed to that component (see [Recycling](https://shopify.github.io/flash-list/docs/recycling))
|
|
75
|
+
4. If your list has heterogenous views, pass their types to `FlashList` using [`getItemType`](https://shopify.github.io/flash-list/docs/usage/#getitemtype) prop to improve performance.
|
|
76
|
+
5. Do not test performance with JS dev mode on. Make sure you’re in release mode. `FlashList` can appear slower while in dev mode due to a small render buffer.
|
|
77
|
+
6. Memoizing props passed to FlashList is more important in v2. v1 was more selective about updating items, but this was often perceived as a bug by developers. We will not follow that approach and will instead allow developers to ensure that props are memoized. We will stop re-renders of children wherever it is obvious.
|
|
78
|
+
|
|
79
|
+
## Other things to know
|
|
80
|
+
|
|
81
|
+
- `keyExtractor` is important to prevent glitches due to item layout changes when going upwards. We highly recommend having a valid `keyExtractor` with v2.
|
|
82
|
+
- `useLayoutState`: This is similar to `useState` but communicates the change in state to FlashList. It's useful if you want to resize a child component based on a local state. Item layout changes will still be detected using `onLayout` callback in the absence of `useLayoutState`, which might not look as smooth on a case-by-case basis.
|
|
83
|
+
|
|
84
|
+
```jsx
|
|
85
|
+
import { useLayoutState } from "@shopify/flash-list";
|
|
86
|
+
|
|
87
|
+
const MyItem = ({ item }) => {
|
|
88
|
+
const [isExpanded, setIsExpanded] = useLayoutState(false);
|
|
89
|
+
const height = isExpanded ? 150 : 80;
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<Pressable onPress={() => setIsExpanded(!isExpanded)}>
|
|
93
|
+
<View style={{ height, padding: 16 }}>
|
|
94
|
+
<Text>{item.title}</Text>
|
|
95
|
+
</View>
|
|
96
|
+
</Pressable>
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
- `useRecyclingState`: Similar to `useState` but accepts a dependency array. On change of deps, the state gets reset without an additional `setState` call. Useful for maintaining local item state if really necessary. It also has the functionality of `useLayoutState` built in.
|
|
102
|
+
|
|
103
|
+
```jsx
|
|
104
|
+
import { useRecyclingState } from "@shopify/flash-list";
|
|
105
|
+
|
|
106
|
+
const GridItem = ({ item }) => {
|
|
107
|
+
const [isExpanded, setIsExpanded] = useRecyclingState(
|
|
108
|
+
false,
|
|
109
|
+
[item.id],
|
|
110
|
+
() => {
|
|
111
|
+
// runs on reset. Can be used to reset scroll positions of nested horizontal lists
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
const height = isExpanded ? 100 : 50;
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
<Pressable onPress={() => setIsExpanded(!isExpanded)}>
|
|
118
|
+
<View style={{ height, backgroundColor: item.color }}>
|
|
119
|
+
<Text>{item.title}</Text>
|
|
120
|
+
</View>
|
|
121
|
+
</Pressable>
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
- `useMappingHelper`: Returns a function that helps create optimal mapping keys for items when using `.map()` in your render methods. Using this ensures optimized recycling and performance for FlashList.
|
|
127
|
+
|
|
128
|
+
```jsx
|
|
129
|
+
import { useMappingHelper } from "@shopify/flash-list";
|
|
130
|
+
|
|
131
|
+
const MyComponent = ({ items }) => {
|
|
132
|
+
const { getMappingKey } = useMappingHelper();
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<FlashList
|
|
136
|
+
data={items}
|
|
137
|
+
renderItem={({ item }) => <ItemComponent item={item} />}
|
|
138
|
+
/>
|
|
139
|
+
);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// When mapping over items inside components:
|
|
143
|
+
const NestedList = ({ items }) => {
|
|
144
|
+
const { getMappingKey } = useMappingHelper();
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<View>
|
|
148
|
+
{items.map((item, index) => (
|
|
149
|
+
<Text key={getMappingKey(item.id, index)}>{item.title}</Text>
|
|
150
|
+
))}
|
|
151
|
+
</View>
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
- If you're nesting horizontal FlashLists in vertical lists, we highly recommend the vertical list to be FlashList too. We have optimizations to wait for child layout to complete which can improve load times.
|
|
87
157
|
|
|
88
158
|
## App / Playground
|
|
89
159
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED']
|
|
5
|
+
|
|
6
|
+
Pod::Spec.new do |s|
|
|
7
|
+
s.name = 'RNFlashList'
|
|
8
|
+
s.version = package['version']
|
|
9
|
+
s.summary = package['description']
|
|
10
|
+
s.homepage = package['homepage']
|
|
11
|
+
s.license = package['license']
|
|
12
|
+
s.author = package['author']
|
|
13
|
+
s.platforms = { :ios => '11.0', :tvos => '12.0' }
|
|
14
|
+
s.source = { git: 'https://github.com/shopify/flash-list.git', tag: "v#{s.version}" }
|
|
15
|
+
s.source_files = 'ios/Sources/**/*'
|
|
16
|
+
s.requires_arc = true
|
|
17
|
+
s.swift_version = '5.0'
|
|
18
|
+
|
|
19
|
+
if new_arch_enabled
|
|
20
|
+
s.pod_target_xcconfig = {
|
|
21
|
+
'OTHER_SWIFT_FLAGS' => '-D RCT_NEW_ARCH_ENABLED',
|
|
22
|
+
}
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# install_modules_dependencies is available since RN 0.71
|
|
26
|
+
if respond_to?(:install_modules_dependencies, true)
|
|
27
|
+
install_modules_dependencies(s)
|
|
28
|
+
else
|
|
29
|
+
s.dependency "React-Core"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Tests spec
|
|
33
|
+
s.test_spec 'Tests' do |test_spec|
|
|
34
|
+
test_spec.source_files = 'ios/Tests/**/*'
|
|
35
|
+
test_spec.framework = 'XCTest'
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
def isNewArchitectureEnabled() {
|
|
2
|
+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
apply plugin: 'com.android.library'
|
|
6
|
+
|
|
7
|
+
apply plugin: 'kotlin-android'
|
|
8
|
+
|
|
9
|
+
if (isNewArchitectureEnabled()) {
|
|
10
|
+
apply plugin: 'com.facebook.react'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
def _ext = rootProject.ext
|
|
14
|
+
|
|
15
|
+
def _reactNativeVersion = _ext.has('reactNative') ? _ext.reactNative : '+'
|
|
16
|
+
def _compileSdkVersion = _ext.has('compileSdkVersion') ? _ext.compileSdkVersion : 30
|
|
17
|
+
def _buildToolsVersion = _ext.has('buildToolsVersion') ? _ext.buildToolsVersion : '30.0.2'
|
|
18
|
+
def _minSdkVersion = _ext.has('minSdkVersion') ? _ext.minSdkVersion : 21
|
|
19
|
+
def _targetSdkVersion = _ext.has('targetSdkVersion') ? _ext.targetSdkVersion : 30
|
|
20
|
+
def _junitVersion = _ext.has('junitVersion') ? _ext.junitVersion : '4.13.2'
|
|
21
|
+
def _mockitoVersion = _ext.has('mockitoVersion') ? _ext.mockitoVersion : '3.2.0'
|
|
22
|
+
def _androidTestRunnerVersion = _ext.has('androidTestRunnerVersion') ? _ext.androidTestRunnerVersion : '1.1.0'
|
|
23
|
+
|
|
24
|
+
buildscript {
|
|
25
|
+
// buildscript is evaluated before any other task is executed, so this must be defined here
|
|
26
|
+
ext._kotlinVersion = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get('kotlinVersion') : '1.8.10'
|
|
27
|
+
|
|
28
|
+
repositories {
|
|
29
|
+
mavenCentral()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
dependencies {
|
|
33
|
+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${_kotlinVersion}")
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
android {
|
|
38
|
+
compileSdkVersion _compileSdkVersion
|
|
39
|
+
buildToolsVersion _buildToolsVersion
|
|
40
|
+
|
|
41
|
+
// Conditional for compatibility with AGP <4.2.
|
|
42
|
+
if (project.android.hasProperty("namespace")) {
|
|
43
|
+
namespace = "com.shopify.reactnative.flash_list"
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
compileOptions {
|
|
47
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
48
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
sourceSets {
|
|
52
|
+
main.java.srcDirs += 'src/main/kotlin'
|
|
53
|
+
debug.java.srcDirs += 'src/debug/kotlin'
|
|
54
|
+
test.java.srcDirs += 'src/test/kotlin'
|
|
55
|
+
androidTest.java.srcDirs += 'src/androidTest/kotlin'
|
|
56
|
+
|
|
57
|
+
if (!isNewArchitectureEnabled()) {
|
|
58
|
+
main.java.srcDirs += ['src/paper/java']
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
defaultConfig {
|
|
63
|
+
minSdkVersion _minSdkVersion
|
|
64
|
+
targetSdkVersion _targetSdkVersion
|
|
65
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
66
|
+
versionCode 1
|
|
67
|
+
versionName "1.0"
|
|
68
|
+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
lintOptions {
|
|
72
|
+
abortOnError false
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
testOptions {
|
|
76
|
+
unitTests.returnDefaultValues = true
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
dependencies {
|
|
81
|
+
compileOnly "com.facebook.react:react-native:${_reactNativeVersion}"
|
|
82
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${_kotlinVersion}"
|
|
83
|
+
testImplementation "junit:junit:${_junitVersion}"
|
|
84
|
+
testImplementation "org.mockito.kotlin:mockito-kotlin:${_mockitoVersion}"
|
|
85
|
+
testImplementation "org.mockito:mockito-inline:${_mockitoVersion}"
|
|
86
|
+
testImplementation 'com.google.code.gson:gson:2.8.9'
|
|
87
|
+
androidTestImplementation("androidx.test:runner:${_androidTestRunnerVersion}")
|
|
88
|
+
androidTestImplementation("androidx.test:rules:${_androidTestRunnerVersion}")
|
|
89
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
package com.shopify.reactnative.flash_list
|
|
2
|
+
|
|
3
|
+
class AutoLayoutShadow {
|
|
4
|
+
var horizontal: Boolean = false
|
|
5
|
+
var scrollOffset: Int = 0
|
|
6
|
+
var offsetFromStart: Int = 0
|
|
7
|
+
var windowSize: Int = 0
|
|
8
|
+
var renderOffset = 0
|
|
9
|
+
|
|
10
|
+
var blankOffsetAtStart = 0 // Tracks blank area from the top
|
|
11
|
+
var blankOffsetAtEnd = 0 // Tracks blank area from the bottom
|
|
12
|
+
|
|
13
|
+
var lastMaxBoundOverall = 0 // Tracks where the last pixel is drawn in the overall
|
|
14
|
+
|
|
15
|
+
private var lastMaxBound = 0 // Tracks where the last pixel is drawn in the visible window
|
|
16
|
+
private var lastMinBound = 0 // Tracks where first pixel is drawn in the visible window
|
|
17
|
+
|
|
18
|
+
/** Checks for overlaps or gaps between adjacent items and then applies a correction (Only Grid layouts with varying spans)
|
|
19
|
+
* Performance: RecyclerListView renders very small number of views and this is not going to trigger multiple layouts on Android side. Not expecting any major perf issue. */
|
|
20
|
+
fun clearGapsAndOverlaps(sortedItems: Array<CellContainer>) {
|
|
21
|
+
var maxBound = 0
|
|
22
|
+
var minBound = Int.MAX_VALUE
|
|
23
|
+
var maxBoundNeighbour = 0
|
|
24
|
+
lastMaxBoundOverall = 0
|
|
25
|
+
for (i in 0 until sortedItems.size - 1) {
|
|
26
|
+
val cell = sortedItems[i]
|
|
27
|
+
val neighbour = sortedItems[i + 1]
|
|
28
|
+
// Only apply correction if the next cell is consecutive.
|
|
29
|
+
val isNeighbourConsecutive = neighbour.index == cell.index + 1
|
|
30
|
+
if (isWithinBounds(cell) || isWithinBounds(neighbour)) {
|
|
31
|
+
if (!horizontal) {
|
|
32
|
+
maxBound = kotlin.math.max(maxBound, cell.bottom);
|
|
33
|
+
minBound = kotlin.math.min(minBound, cell.top);
|
|
34
|
+
maxBoundNeighbour = maxBound
|
|
35
|
+
if (isNeighbourConsecutive) {
|
|
36
|
+
if (cell.left < neighbour.left) {
|
|
37
|
+
if (cell.right != neighbour.left) {
|
|
38
|
+
neighbour.right = cell.right + neighbour.width
|
|
39
|
+
neighbour.left = cell.right
|
|
40
|
+
}
|
|
41
|
+
if (cell.top != neighbour.top) {
|
|
42
|
+
neighbour.bottom = cell.top + neighbour.height
|
|
43
|
+
neighbour.top = cell.top
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
neighbour.bottom = maxBound + neighbour.height
|
|
47
|
+
neighbour.top = maxBound
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (isWithinBounds(neighbour)) {
|
|
51
|
+
maxBoundNeighbour = kotlin.math.max(maxBound, neighbour.bottom)
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
maxBound = kotlin.math.max(maxBound, cell.right);
|
|
55
|
+
minBound = kotlin.math.min(minBound, cell.left);
|
|
56
|
+
maxBoundNeighbour = maxBound
|
|
57
|
+
if (isNeighbourConsecutive) {
|
|
58
|
+
if (cell.top < neighbour.top) {
|
|
59
|
+
if (cell.bottom != neighbour.top) {
|
|
60
|
+
neighbour.bottom = cell.bottom + neighbour.height
|
|
61
|
+
neighbour.top = cell.bottom
|
|
62
|
+
}
|
|
63
|
+
if (cell.left != neighbour.left) {
|
|
64
|
+
neighbour.right = cell.left + neighbour.width
|
|
65
|
+
neighbour.left = cell.left
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
neighbour.right = maxBound + neighbour.width
|
|
69
|
+
neighbour.left = maxBound
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (isWithinBounds(neighbour)) {
|
|
73
|
+
maxBoundNeighbour = kotlin.math.max(maxBound, neighbour.right)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
lastMaxBoundOverall = kotlin.math.max(lastMaxBoundOverall, if (horizontal) cell.right else cell.bottom)
|
|
78
|
+
lastMaxBoundOverall = kotlin.math.max(lastMaxBoundOverall, if (horizontal) neighbour.right else neighbour.bottom)
|
|
79
|
+
}
|
|
80
|
+
lastMaxBound = maxBoundNeighbour
|
|
81
|
+
lastMinBound = minBound
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Offset provided by react can be one frame behind the real one, it's important that this method is called with offset taken directly from
|
|
85
|
+
* scrollview object */
|
|
86
|
+
fun computeBlankFromGivenOffset(actualScrollOffset: Int, distanceFromWindowStart: Int, distanceFromWindowEnd: Int): Int {
|
|
87
|
+
val actualScrollOffset = actualScrollOffset - offsetFromStart;
|
|
88
|
+
blankOffsetAtStart = lastMinBound - actualScrollOffset - distanceFromWindowStart
|
|
89
|
+
blankOffsetAtEnd = actualScrollOffset + windowSize - renderOffset - lastMaxBound - distanceFromWindowEnd
|
|
90
|
+
return kotlin.math.max(blankOffsetAtStart, blankOffsetAtEnd)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** It's important to avoid correcting views outside the render window. An item that isn't being recycled might still remain in the view tree. If views outside get considered then gaps between
|
|
94
|
+
* unused items will cause algorithm to fail.*/
|
|
95
|
+
private fun isWithinBounds(cell: CellContainer): Boolean {
|
|
96
|
+
val scrollOffset = scrollOffset - offsetFromStart;
|
|
97
|
+
return if (!horizontal) {
|
|
98
|
+
(cell.top >= (scrollOffset - renderOffset) || cell.bottom >= (scrollOffset - renderOffset)) &&
|
|
99
|
+
(cell.top <= scrollOffset + windowSize || cell.bottom <= scrollOffset + windowSize)
|
|
100
|
+
} else {
|
|
101
|
+
(cell.left >= (scrollOffset - renderOffset) || cell.right >= (scrollOffset - renderOffset)) &&
|
|
102
|
+
(cell.left <= scrollOffset + windowSize || cell.right <= scrollOffset + windowSize)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
package com.shopify.reactnative.flash_list
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.graphics.Canvas
|
|
5
|
+
import android.util.DisplayMetrics
|
|
6
|
+
import android.util.Log
|
|
7
|
+
import android.view.View
|
|
8
|
+
import android.view.ViewGroup
|
|
9
|
+
import android.widget.HorizontalScrollView
|
|
10
|
+
import android.widget.ScrollView
|
|
11
|
+
import com.facebook.react.bridge.Arguments
|
|
12
|
+
import com.facebook.react.bridge.ReactContext
|
|
13
|
+
import com.facebook.react.bridge.WritableMap
|
|
14
|
+
import com.facebook.react.uimanager.UIManagerHelper
|
|
15
|
+
import com.facebook.react.uimanager.events.EventDispatcher
|
|
16
|
+
import com.facebook.react.uimanager.events.RCTEventEmitter
|
|
17
|
+
import com.facebook.react.views.view.ReactViewGroup
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
/** Container for all RecyclerListView children. This will automatically remove all gaps and overlaps for GridLayouts with flexible spans.
|
|
21
|
+
* Note: This cannot work for masonry layouts i.e, pinterest like layout */
|
|
22
|
+
class AutoLayoutView(context: Context) : ReactViewGroup(context) {
|
|
23
|
+
val alShadow = AutoLayoutShadow()
|
|
24
|
+
var enableInstrumentation = false
|
|
25
|
+
var disableAutoLayout = false
|
|
26
|
+
|
|
27
|
+
var pixelDensity = 1.0;
|
|
28
|
+
|
|
29
|
+
/** Overriding draw instead of onLayout. RecyclerListView uses absolute positions for each and every item which means that changes in child layouts may not trigger onLayout on this container. The same layout
|
|
30
|
+
* can still cause views to overlap. Therefore, it makes sense to override draw to do correction. */
|
|
31
|
+
override fun dispatchDraw(canvas: Canvas) {
|
|
32
|
+
fixLayout()
|
|
33
|
+
fixFooter()
|
|
34
|
+
super.dispatchDraw(canvas)
|
|
35
|
+
|
|
36
|
+
val parentScrollView = getParentScrollView()
|
|
37
|
+
if (enableInstrumentation && parentScrollView != null) {
|
|
38
|
+
/** Since we need to call this method with scrollOffset on the UI thread and not with the one react has we're querying parent's parent
|
|
39
|
+
directly which will be a ScrollView. If it isn't reported values will be incorrect but the component will not break.
|
|
40
|
+
RecyclerListView is expected not to change the hierarchy of children. */
|
|
41
|
+
|
|
42
|
+
val scrollContainerSize = if (alShadow.horizontal) parentScrollView.width else parentScrollView.height
|
|
43
|
+
|
|
44
|
+
val scrollOffset = if (alShadow.horizontal) parentScrollView.scrollX else parentScrollView.scrollY
|
|
45
|
+
|
|
46
|
+
val startOffset = if (alShadow.horizontal) left else top
|
|
47
|
+
val endOffset = if (alShadow.horizontal) right else bottom
|
|
48
|
+
|
|
49
|
+
val distanceFromWindowStart = kotlin.math.max(startOffset - scrollOffset, 0)
|
|
50
|
+
val distanceFromWindowEnd = kotlin.math.max(scrollOffset + scrollContainerSize - endOffset, 0)
|
|
51
|
+
|
|
52
|
+
alShadow.computeBlankFromGivenOffset(scrollOffset, distanceFromWindowStart, distanceFromWindowEnd)
|
|
53
|
+
emitBlankAreaEvent()
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Sorts views by index and then invokes clearGaps which does the correction.
|
|
58
|
+
* Performance: Sort is needed. Given relatively low number of views in RecyclerListView render tree this should be a non issue.*/
|
|
59
|
+
private fun fixLayout() {
|
|
60
|
+
if (childCount > 1 && !disableAutoLayout) {
|
|
61
|
+
val positionSortedViews: Array<CellContainer> = Array(childCount) {
|
|
62
|
+
val child = getChildAt(it)
|
|
63
|
+
if (child is CellContainer) {
|
|
64
|
+
child
|
|
65
|
+
} else {
|
|
66
|
+
throw IllegalStateException("CellRendererComponent outer view should always be CellContainer. Learn more here: https://shopify.github.io/flash-list/docs/usage#cellrenderercomponent.")
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
positionSortedViews.sortBy { it.index }
|
|
70
|
+
alShadow.offsetFromStart = if (alShadow.horizontal) left else top
|
|
71
|
+
alShadow.clearGapsAndOverlaps(positionSortedViews)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Fixes footer position along with rest of the items */
|
|
76
|
+
private fun fixFooter() {
|
|
77
|
+
val parentScrollView = getParentScrollView()
|
|
78
|
+
if (disableAutoLayout || parentScrollView == null) {
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
val isAutoLayoutEndVisible = if (alShadow.horizontal) right <= parentScrollView.width else bottom <= parentScrollView.height
|
|
82
|
+
if (!isAutoLayoutEndVisible) {
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
val autoLayoutParent = parent as? View
|
|
86
|
+
val footer = getFooter();
|
|
87
|
+
val diff = getFooterDiff()
|
|
88
|
+
if (diff == 0 || footer == null || autoLayoutParent == null) {
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (alShadow.horizontal) {
|
|
93
|
+
footer.offsetLeftAndRight(diff)
|
|
94
|
+
right += diff
|
|
95
|
+
autoLayoutParent.right += diff
|
|
96
|
+
} else {
|
|
97
|
+
footer.offsetTopAndBottom(diff)
|
|
98
|
+
bottom += diff
|
|
99
|
+
autoLayoutParent.bottom += diff
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private fun getFooterDiff(): Int {
|
|
104
|
+
if (childCount == 0) {
|
|
105
|
+
alShadow.lastMaxBoundOverall = 0
|
|
106
|
+
} else if (childCount == 1) {
|
|
107
|
+
val firstChild = getChildAt(0)
|
|
108
|
+
alShadow.lastMaxBoundOverall = if (alShadow.horizontal) {
|
|
109
|
+
firstChild.right
|
|
110
|
+
} else {
|
|
111
|
+
firstChild.bottom
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
val autoLayoutEnd = if (alShadow.horizontal) right - left else bottom - top
|
|
115
|
+
return alShadow.lastMaxBoundOverall - autoLayoutEnd
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private fun getFooter(): View? {
|
|
119
|
+
return (parent as? ViewGroup)?.let {
|
|
120
|
+
for (i in 0 until it.childCount) {
|
|
121
|
+
val view = it.getChildAt(i)
|
|
122
|
+
if (view is CellContainer && view.index == -1) {
|
|
123
|
+
return@let view
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return@let null
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private fun getParentScrollView(): View? {
|
|
131
|
+
var autoLayoutParent = parent;
|
|
132
|
+
while (autoLayoutParent != null) {
|
|
133
|
+
if (autoLayoutParent is ScrollView || autoLayoutParent is HorizontalScrollView) {
|
|
134
|
+
return autoLayoutParent as View
|
|
135
|
+
}
|
|
136
|
+
autoLayoutParent = autoLayoutParent.parent;
|
|
137
|
+
}
|
|
138
|
+
return null
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
private fun emitBlankAreaEvent() {
|
|
143
|
+
val eventDispatcher: EventDispatcher? =
|
|
144
|
+
UIManagerHelper.getEventDispatcherForReactTag(context as ReactContext, id)
|
|
145
|
+
|
|
146
|
+
if (eventDispatcher != null) {
|
|
147
|
+
val surfaceId = UIManagerHelper.getSurfaceId(context as ReactContext)
|
|
148
|
+
eventDispatcher.dispatchEvent(
|
|
149
|
+
BlankAreaEvent(
|
|
150
|
+
surfaceId,
|
|
151
|
+
viewTag = id,
|
|
152
|
+
offsetStart = alShadow.blankOffsetAtStart / pixelDensity,
|
|
153
|
+
offsetEnd = alShadow.blankOffsetAtEnd / pixelDensity
|
|
154
|
+
)
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
package com.shopify.reactnative.flash_list
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
4
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
5
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
6
|
+
import com.facebook.react.uimanager.ViewGroupManager
|
|
7
|
+
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
8
|
+
import com.facebook.react.viewmanagers.AutoLayoutViewManagerDelegate
|
|
9
|
+
import com.facebook.react.viewmanagers.AutoLayoutViewManagerInterface
|
|
10
|
+
import kotlin.math.roundToInt
|
|
11
|
+
|
|
12
|
+
/** ViewManager for AutoLayoutView - Container for all RecyclerListView children. Automatically removes all gaps and overlaps for GridLayouts with flexible spans.
|
|
13
|
+
* Note: This cannot work for masonry layouts i.e, pinterest like layout */
|
|
14
|
+
@ReactModule(name = AutoLayoutViewManager.REACT_CLASS)
|
|
15
|
+
class AutoLayoutViewManager: ViewGroupManager<AutoLayoutView>(), AutoLayoutViewManagerInterface<AutoLayoutView> {
|
|
16
|
+
private val mDelegate: AutoLayoutViewManagerDelegate<AutoLayoutView, AutoLayoutViewManager> =
|
|
17
|
+
AutoLayoutViewManagerDelegate(this)
|
|
18
|
+
|
|
19
|
+
companion object {
|
|
20
|
+
const val REACT_CLASS = "AutoLayoutView"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
override fun getName(): String {
|
|
24
|
+
return REACT_CLASS
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
override fun getDelegate(): ViewManagerDelegate<AutoLayoutView> = mDelegate
|
|
28
|
+
|
|
29
|
+
override fun createViewInstance(context: ThemedReactContext): AutoLayoutView {
|
|
30
|
+
return AutoLayoutView(context).also { it.pixelDensity = context.resources.displayMetrics.density.toDouble() }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
override fun getExportedCustomDirectEventTypeConstants() = mutableMapOf(
|
|
34
|
+
"onBlankAreaEvent" to mutableMapOf("registrationName" to "onBlankAreaEvent"),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
@ReactProp(name = "horizontal")
|
|
38
|
+
override fun setHorizontal(view: AutoLayoutView, isHorizontal: Boolean) {
|
|
39
|
+
view.alShadow.horizontal = isHorizontal
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@ReactProp(name = "disableAutoLayout")
|
|
43
|
+
override fun setDisableAutoLayout(view: AutoLayoutView, disableAutoLayout: Boolean) {
|
|
44
|
+
view.disableAutoLayout = disableAutoLayout
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@ReactProp(name = "scrollOffset")
|
|
48
|
+
override fun setScrollOffset(view: AutoLayoutView, scrollOffset: Double) {
|
|
49
|
+
view.alShadow.scrollOffset = convertToPixelLayout(scrollOffset, view.pixelDensity)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@ReactProp(name = "windowSize")
|
|
53
|
+
override fun setWindowSize(view: AutoLayoutView, windowSize: Double) {
|
|
54
|
+
view.alShadow.windowSize = convertToPixelLayout(windowSize, view.pixelDensity)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@ReactProp(name = "renderAheadOffset")
|
|
58
|
+
override fun setRenderAheadOffset(view: AutoLayoutView, renderOffset: Double) {
|
|
59
|
+
view.alShadow.renderOffset = convertToPixelLayout(renderOffset, view.pixelDensity)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@ReactProp(name = "enableInstrumentation")
|
|
63
|
+
override fun setEnableInstrumentation(view: AutoLayoutView, enableInstrumentation: Boolean) {
|
|
64
|
+
view.enableInstrumentation = enableInstrumentation
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private fun convertToPixelLayout(dp: Double, density: Double): Int {
|
|
68
|
+
return (dp * density).roundToInt()
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
@file:Suppress("DEPRECATION") // We want to use RCTEventEmitter for interop purposes
|
|
2
|
+
package com.shopify.reactnative.flash_list
|
|
3
|
+
|
|
4
|
+
import com.facebook.react.bridge.Arguments
|
|
5
|
+
import com.facebook.react.bridge.WritableMap
|
|
6
|
+
import com.facebook.react.uimanager.events.Event
|
|
7
|
+
import com.facebook.react.uimanager.events.RCTEventEmitter
|
|
8
|
+
|
|
9
|
+
class BlankAreaEvent(
|
|
10
|
+
surfaceId: Int,
|
|
11
|
+
viewTag: Int,
|
|
12
|
+
private val offsetStart: Double,
|
|
13
|
+
private val offsetEnd: Double
|
|
14
|
+
): Event<BlankAreaEvent>(surfaceId, viewTag) {
|
|
15
|
+
override fun getEventName() = EVENT_NAME
|
|
16
|
+
|
|
17
|
+
override fun getEventData(): WritableMap = Arguments.createMap().apply {
|
|
18
|
+
putDouble("offsetStart", offsetStart)
|
|
19
|
+
putDouble("offsetEnd", offsetEnd)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
override fun dispatch(rctEventEmitter: RCTEventEmitter) {
|
|
23
|
+
rctEventEmitter.receiveEvent(viewTag, eventName, getEventData())
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
companion object {
|
|
27
|
+
const val EVENT_NAME: String = "onBlankAreaEvent"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
package com.shopify.reactnative.flash_list;
|
|
2
|
+
|
|
3
|
+
public interface CellContainer {
|
|
4
|
+
void setIndex(int value);
|
|
5
|
+
int getIndex();
|
|
6
|
+
void setLeft(int value);
|
|
7
|
+
int getLeft();
|
|
8
|
+
void setTop(int value);
|
|
9
|
+
int getTop();
|
|
10
|
+
void setRight(int value);
|
|
11
|
+
int getRight();
|
|
12
|
+
void setBottom(int value);
|
|
13
|
+
int getBottom();
|
|
14
|
+
int getHeight();
|
|
15
|
+
int getWidth();
|
|
16
|
+
}
|