@shopify/flash-list 2.0.0-alpha.2 → 2.0.0-alpha.21
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 +67 -96
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/BlankAreaEvent.kt +2 -2
- package/dist/AnimatedFlashList.d.ts +0 -1
- package/dist/AnimatedFlashList.d.ts.map +1 -1
- package/dist/AnimatedFlashList.js +3 -3
- package/dist/AnimatedFlashList.js.map +1 -1
- package/dist/FlashList.d.ts +9 -0
- package/dist/FlashList.d.ts.map +1 -1
- package/dist/FlashList.js +22 -3
- package/dist/FlashList.js.map +1 -1
- package/dist/FlashListProps.d.ts +33 -13
- package/dist/FlashListProps.d.ts.map +1 -1
- package/dist/FlashListProps.js.map +1 -1
- package/dist/FlashListRef.d.ts +305 -0
- package/dist/FlashListRef.d.ts.map +1 -0
- package/dist/FlashListRef.js +3 -0
- package/dist/FlashListRef.js.map +1 -0
- package/dist/GridLayoutProviderWithProps.js +1 -2
- package/dist/GridLayoutProviderWithProps.js.map +1 -1
- package/dist/MasonryFlashList.d.ts +2 -2
- package/dist/MasonryFlashList.d.ts.map +1 -1
- package/dist/MasonryFlashList.js.map +1 -1
- package/dist/PureComponentWrapper.js +1 -1
- package/dist/PureComponentWrapper.js.map +1 -1
- package/dist/__tests__/AverageWindow.test.js.map +1 -1
- package/dist/__tests__/ConsecutiveNumbers.test.d.ts +2 -0
- package/dist/__tests__/ConsecutiveNumbers.test.d.ts.map +1 -0
- package/dist/__tests__/ConsecutiveNumbers.test.js +224 -0
- package/dist/__tests__/ConsecutiveNumbers.test.js.map +1 -0
- package/dist/__tests__/FlashList.test.js.map +1 -1
- package/dist/__tests__/GridLayoutManager.test.d.ts +2 -0
- package/dist/__tests__/GridLayoutManager.test.d.ts.map +1 -0
- package/dist/__tests__/GridLayoutManager.test.js +69 -0
- package/dist/__tests__/GridLayoutManager.test.js.map +1 -0
- package/dist/__tests__/GridLayoutProviderWithProps.test.js.map +1 -1
- package/dist/__tests__/LayoutCommitObserver.test.d.ts +2 -0
- package/dist/__tests__/LayoutCommitObserver.test.d.ts.map +1 -0
- package/dist/__tests__/LayoutCommitObserver.test.js +35 -0
- package/dist/__tests__/LayoutCommitObserver.test.js.map +1 -0
- package/dist/__tests__/LinearLayoutManager.test.d.ts +2 -0
- package/dist/__tests__/LinearLayoutManager.test.d.ts.map +1 -0
- package/dist/__tests__/LinearLayoutManager.test.js +140 -0
- package/dist/__tests__/LinearLayoutManager.test.js.map +1 -0
- package/dist/__tests__/MasonryFlashList.test.js.map +1 -1
- package/dist/__tests__/MasonryLayoutManager.test.d.ts +2 -0
- package/dist/__tests__/MasonryLayoutManager.test.d.ts.map +1 -0
- package/dist/__tests__/MasonryLayoutManager.test.js +148 -0
- package/dist/__tests__/MasonryLayoutManager.test.js.map +1 -0
- package/dist/__tests__/RecyclerView.test.d.ts +2 -0
- package/dist/__tests__/RecyclerView.test.d.ts.map +1 -0
- package/dist/__tests__/RecyclerView.test.js +103 -0
- package/dist/__tests__/RecyclerView.test.js.map +1 -0
- package/dist/__tests__/RenderStackManager.test.d.ts +2 -0
- package/dist/__tests__/RenderStackManager.test.d.ts.map +1 -0
- package/dist/__tests__/RenderStackManager.test.js +485 -0
- package/dist/__tests__/RenderStackManager.test.js.map +1 -0
- package/dist/__tests__/ViewabilityHelper.test.js.map +1 -1
- package/dist/__tests__/findVisibleIndex.test.d.ts +2 -0
- package/dist/__tests__/findVisibleIndex.test.d.ts.map +1 -0
- package/dist/__tests__/findVisibleIndex.test.js +259 -0
- package/dist/__tests__/findVisibleIndex.test.js.map +1 -0
- package/dist/__tests__/helpers/createLayoutManager.d.ts +34 -0
- package/dist/__tests__/helpers/createLayoutManager.d.ts.map +1 -0
- package/dist/__tests__/helpers/createLayoutManager.js +110 -0
- package/dist/__tests__/helpers/createLayoutManager.js.map +1 -0
- package/dist/__tests__/helpers/mountFlashList.d.ts +2 -2
- package/dist/__tests__/helpers/mountFlashList.d.ts.map +1 -1
- package/dist/__tests__/helpers/mountFlashList.js +2 -2
- package/dist/__tests__/helpers/mountFlashList.js.map +1 -1
- package/dist/__tests__/helpers/mountMasonryFlashList.d.ts +2 -2
- package/dist/__tests__/helpers/mountMasonryFlashList.d.ts.map +1 -1
- package/dist/__tests__/helpers/mountMasonryFlashList.js +2 -2
- package/dist/__tests__/helpers/mountMasonryFlashList.js.map +1 -1
- package/dist/__tests__/useBlankAreaTracker.test.js.map +1 -1
- package/dist/__tests__/useUnmountAwareCallbacks.test.d.ts +2 -0
- package/dist/__tests__/useUnmountAwareCallbacks.test.d.ts.map +1 -0
- package/dist/__tests__/useUnmountAwareCallbacks.test.js +185 -0
- package/dist/__tests__/useUnmountAwareCallbacks.test.js.map +1 -0
- package/dist/benchmark/AutoScrollHelper.js +2 -2
- package/dist/benchmark/AutoScrollHelper.js.map +1 -1
- package/dist/benchmark/JSFPSMonitor.js.map +1 -1
- package/dist/benchmark/roundToDecimalPlaces.js +1 -2
- package/dist/benchmark/roundToDecimalPlaces.js.map +1 -1
- package/dist/benchmark/useBenchmark.js +2 -28
- package/dist/benchmark/useBenchmark.js.map +1 -1
- package/dist/benchmark/useBlankAreaTracker.js +1 -2
- package/dist/benchmark/useBlankAreaTracker.js.map +1 -1
- package/dist/benchmark/useDataMultiplier.js +1 -2
- package/dist/benchmark/useDataMultiplier.js.map +1 -1
- package/dist/benchmark/useFlatListBenchmark.d.ts +0 -1
- package/dist/benchmark/useFlatListBenchmark.d.ts.map +1 -1
- package/dist/benchmark/useFlatListBenchmark.js +9 -9
- package/dist/benchmark/useFlatListBenchmark.js.map +1 -1
- package/dist/enableNewCore.d.ts.map +1 -1
- package/dist/enableNewCore.js +4 -4
- package/dist/enableNewCore.js.map +1 -1
- package/dist/errors/CustomError.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/dist/native/auto-layout/AutoLayoutView.d.ts +1 -1
- package/dist/native/auto-layout/AutoLayoutView.d.ts.map +1 -1
- package/dist/native/auto-layout/AutoLayoutView.js +1 -1
- package/dist/native/auto-layout/AutoLayoutView.js.map +1 -1
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.d.ts.map +1 -1
- package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.d.ts +1 -1
- package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.d.ts.map +1 -1
- package/dist/native/config/PlatformHelper.android.d.ts +2 -0
- package/dist/native/config/PlatformHelper.android.d.ts.map +1 -1
- package/dist/native/config/PlatformHelper.android.js +2 -0
- package/dist/native/config/PlatformHelper.android.js.map +1 -1
- package/dist/native/config/PlatformHelper.d.ts +2 -0
- package/dist/native/config/PlatformHelper.d.ts.map +1 -1
- package/dist/native/config/PlatformHelper.ios.d.ts +2 -0
- package/dist/native/config/PlatformHelper.ios.d.ts.map +1 -1
- package/dist/native/config/PlatformHelper.ios.js +2 -0
- package/dist/native/config/PlatformHelper.ios.js.map +1 -1
- package/dist/native/config/PlatformHelper.js +2 -0
- package/dist/native/config/PlatformHelper.js.map +1 -1
- package/dist/native/config/PlatformHelper.web.d.ts +2 -0
- package/dist/native/config/PlatformHelper.web.d.ts.map +1 -1
- package/dist/native/config/PlatformHelper.web.js +3 -1
- package/dist/native/config/PlatformHelper.web.js.map +1 -1
- package/dist/recyclerview/LayoutCommitObserver.d.ts +12 -0
- package/dist/recyclerview/LayoutCommitObserver.d.ts.map +1 -0
- package/dist/recyclerview/LayoutCommitObserver.js +62 -0
- package/dist/recyclerview/LayoutCommitObserver.js.map +1 -0
- package/dist/recyclerview/RecyclerView.d.ts +3 -2
- package/dist/recyclerview/RecyclerView.d.ts.map +1 -1
- package/dist/recyclerview/RecyclerView.js +133 -69
- package/dist/recyclerview/RecyclerView.js.map +1 -1
- package/dist/recyclerview/RecyclerViewContextProvider.d.ts +41 -7
- package/dist/recyclerview/RecyclerViewContextProvider.d.ts.map +1 -1
- package/dist/recyclerview/RecyclerViewContextProvider.js +6 -2
- package/dist/recyclerview/RecyclerViewContextProvider.js.map +1 -1
- package/dist/recyclerview/RecyclerViewManager.d.ts +31 -7
- package/dist/recyclerview/RecyclerViewManager.d.ts.map +1 -1
- package/dist/recyclerview/RecyclerViewManager.js +154 -117
- package/dist/recyclerview/RecyclerViewManager.js.map +1 -1
- package/dist/recyclerview/RecyclerViewProps.d.ts +1 -1
- package/dist/recyclerview/RecyclerViewProps.d.ts.map +1 -1
- package/dist/recyclerview/RenderStackManager.d.ts +86 -0
- package/dist/recyclerview/RenderStackManager.d.ts.map +1 -0
- package/dist/recyclerview/RenderStackManager.js +343 -0
- package/dist/recyclerview/RenderStackManager.js.map +1 -0
- package/dist/recyclerview/ViewHolder.d.ts.map +1 -1
- package/dist/recyclerview/ViewHolder.js +8 -6
- package/dist/recyclerview/ViewHolder.js.map +1 -1
- package/dist/recyclerview/ViewHolderCollection.d.ts +10 -4
- package/dist/recyclerview/ViewHolderCollection.d.ts.map +1 -1
- package/dist/recyclerview/ViewHolderCollection.js +26 -10
- package/dist/recyclerview/ViewHolderCollection.js.map +1 -1
- package/dist/recyclerview/components/ScrollAnchor.d.ts +2 -1
- package/dist/recyclerview/components/ScrollAnchor.d.ts.map +1 -1
- package/dist/recyclerview/components/ScrollAnchor.js +12 -9
- package/dist/recyclerview/components/ScrollAnchor.js.map +1 -1
- package/dist/recyclerview/components/StickyHeaders.d.ts +2 -2
- package/dist/recyclerview/components/StickyHeaders.d.ts.map +1 -1
- package/dist/recyclerview/components/StickyHeaders.js +44 -45
- package/dist/recyclerview/components/StickyHeaders.js.map +1 -1
- package/dist/recyclerview/helpers/ConsecutiveNumbers.d.ts +1 -1
- package/dist/recyclerview/helpers/ConsecutiveNumbers.d.ts.map +1 -1
- package/dist/recyclerview/helpers/ConsecutiveNumbers.js +2 -2
- package/dist/recyclerview/helpers/ConsecutiveNumbers.js.map +1 -1
- package/dist/recyclerview/helpers/EngagedIndicesTracker.d.ts +48 -2
- package/dist/recyclerview/helpers/EngagedIndicesTracker.d.ts.map +1 -1
- package/dist/recyclerview/helpers/EngagedIndicesTracker.js +89 -19
- package/dist/recyclerview/helpers/EngagedIndicesTracker.js.map +1 -1
- package/dist/recyclerview/helpers/RenderTimeTracker.d.ts +11 -0
- package/dist/recyclerview/helpers/RenderTimeTracker.d.ts.map +1 -0
- package/dist/recyclerview/helpers/RenderTimeTracker.js +42 -0
- package/dist/recyclerview/helpers/RenderTimeTracker.js.map +1 -0
- package/dist/recyclerview/helpers/VelocityTracker.d.ts +29 -0
- package/dist/recyclerview/helpers/VelocityTracker.d.ts.map +1 -0
- package/dist/recyclerview/helpers/VelocityTracker.js +70 -0
- package/dist/recyclerview/helpers/VelocityTracker.js.map +1 -0
- package/dist/recyclerview/hooks/useBoundDetection.d.ts +1 -3
- package/dist/recyclerview/hooks/useBoundDetection.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useBoundDetection.js +60 -28
- package/dist/recyclerview/hooks/useBoundDetection.js.map +1 -1
- package/dist/recyclerview/hooks/useLayoutState.d.ts +3 -1
- package/dist/recyclerview/hooks/useLayoutState.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useLayoutState.js +6 -5
- package/dist/recyclerview/hooks/useLayoutState.js.map +1 -1
- package/dist/recyclerview/hooks/useMappingHelper.d.ts +9 -0
- package/dist/recyclerview/hooks/useMappingHelper.d.ts.map +1 -0
- package/dist/recyclerview/hooks/useMappingHelper.js +19 -0
- package/dist/recyclerview/hooks/useMappingHelper.js.map +1 -0
- package/dist/recyclerview/hooks/useOnLoad.d.ts +2 -2
- package/dist/recyclerview/hooks/useOnLoad.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useOnLoad.js +9 -10
- package/dist/recyclerview/hooks/useOnLoad.js.map +1 -1
- package/dist/recyclerview/hooks/useRecyclerViewController.d.ts +5 -49
- package/dist/recyclerview/hooks/useRecyclerViewController.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useRecyclerViewController.js +343 -191
- package/dist/recyclerview/hooks/useRecyclerViewController.js.map +1 -1
- package/dist/recyclerview/hooks/useRecyclerViewManager.d.ts +2 -0
- package/dist/recyclerview/hooks/useRecyclerViewManager.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useRecyclerViewManager.js +11 -1
- package/dist/recyclerview/hooks/useRecyclerViewManager.js.map +1 -1
- package/dist/recyclerview/hooks/useRecyclingState.d.ts +4 -2
- package/dist/recyclerview/hooks/useRecyclingState.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useRecyclingState.js +3 -4
- package/dist/recyclerview/hooks/useRecyclingState.js.map +1 -1
- package/dist/recyclerview/hooks/useSecondaryProps.d.ts +1 -1
- package/dist/recyclerview/hooks/useSecondaryProps.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useSecondaryProps.js +15 -12
- package/dist/recyclerview/hooks/useSecondaryProps.js.map +1 -1
- package/dist/recyclerview/hooks/useUnmountAwareCallbacks.d.ts +15 -0
- package/dist/recyclerview/hooks/useUnmountAwareCallbacks.d.ts.map +1 -0
- package/dist/recyclerview/hooks/useUnmountAwareCallbacks.js +63 -0
- package/dist/recyclerview/hooks/useUnmountAwareCallbacks.js.map +1 -0
- package/dist/recyclerview/hooks/useUnmountFlag.d.ts +0 -1
- package/dist/recyclerview/hooks/useUnmountFlag.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useUnmountFlag.js +1 -0
- package/dist/recyclerview/hooks/useUnmountFlag.js.map +1 -1
- package/dist/recyclerview/layout-managers/GridLayoutManager.d.ts +18 -4
- package/dist/recyclerview/layout-managers/GridLayoutManager.d.ts.map +1 -1
- package/dist/recyclerview/layout-managers/GridLayoutManager.js +61 -25
- package/dist/recyclerview/layout-managers/GridLayoutManager.js.map +1 -1
- package/dist/recyclerview/layout-managers/LayoutManager.d.ts +36 -21
- package/dist/recyclerview/layout-managers/LayoutManager.d.ts.map +1 -1
- package/dist/recyclerview/layout-managers/LayoutManager.js +96 -28
- package/dist/recyclerview/layout-managers/LayoutManager.js.map +1 -1
- package/dist/recyclerview/layout-managers/LinearLayoutManager.d.ts +1 -2
- package/dist/recyclerview/layout-managers/LinearLayoutManager.d.ts.map +1 -1
- package/dist/recyclerview/layout-managers/LinearLayoutManager.js +3 -3
- package/dist/recyclerview/layout-managers/LinearLayoutManager.js.map +1 -1
- package/dist/recyclerview/layout-managers/MasonryLayoutManager.d.ts +9 -1
- package/dist/recyclerview/layout-managers/MasonryLayoutManager.d.ts.map +1 -1
- package/dist/recyclerview/layout-managers/MasonryLayoutManager.js +30 -16
- package/dist/recyclerview/layout-managers/MasonryLayoutManager.js.map +1 -1
- package/dist/recyclerview/utils/adjustOffsetForRTL.js +1 -2
- package/dist/recyclerview/utils/adjustOffsetForRTL.js.map +1 -1
- package/dist/recyclerview/utils/componentUtils.d.ts +1 -1
- package/dist/recyclerview/utils/componentUtils.d.ts.map +1 -1
- package/dist/recyclerview/utils/componentUtils.js.map +1 -1
- package/dist/recyclerview/utils/findVisibleIndex.d.ts.map +1 -1
- package/dist/recyclerview/utils/findVisibleIndex.js +3 -5
- package/dist/recyclerview/utils/findVisibleIndex.js.map +1 -1
- package/dist/recyclerview/utils/measureLayout.d.ts +24 -28
- package/dist/recyclerview/utils/measureLayout.d.ts.map +1 -1
- package/dist/recyclerview/utils/measureLayout.js +36 -6
- package/dist/recyclerview/utils/measureLayout.js.map +1 -1
- package/dist/recyclerview/utils/measureLayout.web.d.ts +29 -0
- package/dist/recyclerview/utils/measureLayout.web.d.ts.map +1 -0
- package/dist/recyclerview/utils/measureLayout.web.js +87 -0
- package/dist/recyclerview/utils/measureLayout.web.js.map +1 -0
- package/dist/specs/AutoLayoutNativeComponent.d.ts +1 -2
- package/dist/specs/AutoLayoutNativeComponent.d.ts.map +1 -1
- package/dist/specs/CellContainerNativeComponent.d.ts +0 -1
- package/dist/specs/CellContainerNativeComponent.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/AverageWindow.js.map +1 -1
- package/dist/utils/ContentContainerUtils.d.ts.map +1 -1
- package/dist/utils/ContentContainerUtils.js.map +1 -1
- package/dist/viewability/ViewToken.d.ts +2 -2
- package/dist/viewability/ViewToken.d.ts.map +1 -1
- package/dist/viewability/ViewabilityHelper.js +1 -1
- package/dist/viewability/ViewabilityHelper.js.map +1 -1
- package/dist/viewability/ViewabilityManager.d.ts.map +1 -1
- package/dist/viewability/ViewabilityManager.js +11 -5
- package/dist/viewability/ViewabilityManager.js.map +1 -1
- package/jestSetup.js +30 -11
- package/package.json +4 -3
- package/src/AnimatedFlashList.ts +3 -2
- package/src/FlashList.tsx +25 -1
- package/src/FlashListProps.ts +42 -11
- package/src/FlashListRef.ts +320 -0
- package/src/MasonryFlashList.tsx +2 -2
- package/src/__tests__/ConsecutiveNumbers.test.ts +232 -0
- package/src/__tests__/GridLayoutManager.test.ts +113 -0
- package/src/__tests__/LayoutCommitObserver.test.tsx +60 -0
- package/src/__tests__/LinearLayoutManager.test.ts +227 -0
- package/src/__tests__/MasonryLayoutManager.test.ts +202 -0
- package/src/__tests__/RecyclerView.test.tsx +144 -0
- package/src/__tests__/RenderStackManager.test.ts +574 -0
- package/src/__tests__/findVisibleIndex.test.ts +369 -0
- package/src/__tests__/helpers/createLayoutManager.ts +141 -0
- package/src/__tests__/useUnmountAwareCallbacks.test.tsx +285 -0
- package/src/benchmark/useBenchmark.ts +0 -37
- package/src/benchmark/useFlatListBenchmark.ts +2 -2
- package/src/enableNewCore.ts +3 -1
- package/src/index.ts +14 -3
- package/src/native/config/PlatformHelper.android.ts +2 -0
- package/src/native/config/PlatformHelper.ios.ts +2 -0
- package/src/native/config/PlatformHelper.ts +2 -0
- package/src/native/config/PlatformHelper.web.ts +3 -1
- package/src/recyclerview/LayoutCommitObserver.tsx +74 -0
- package/src/recyclerview/RecyclerView.tsx +178 -89
- package/src/recyclerview/RecyclerViewContextProvider.ts +53 -7
- package/src/recyclerview/RecyclerViewManager.ts +176 -97
- package/src/recyclerview/RecyclerViewProps.ts +2 -1
- package/src/recyclerview/RenderStackManager.ts +317 -0
- package/src/recyclerview/ViewHolder.tsx +13 -6
- package/src/recyclerview/ViewHolderCollection.tsx +45 -16
- package/src/recyclerview/components/ScrollAnchor.tsx +24 -11
- package/src/recyclerview/components/StickyHeaders.tsx +70 -58
- package/src/recyclerview/helpers/ConsecutiveNumbers.ts +2 -2
- package/src/recyclerview/helpers/EngagedIndicesTracker.ts +135 -25
- package/src/recyclerview/helpers/RenderTimeTracker.ts +42 -0
- package/src/recyclerview/helpers/VelocityTracker.ts +77 -0
- package/src/recyclerview/hooks/useBoundDetection.ts +74 -25
- package/src/recyclerview/hooks/useLayoutState.ts +15 -6
- package/src/recyclerview/hooks/useMappingHelper.ts +20 -0
- package/src/recyclerview/hooks/useOnLoad.ts +11 -10
- package/src/recyclerview/hooks/useRecyclerViewController.tsx +380 -241
- package/src/recyclerview/hooks/useRecyclerViewManager.ts +13 -1
- package/src/recyclerview/hooks/useRecyclingState.ts +11 -7
- package/src/recyclerview/hooks/useSecondaryProps.tsx +12 -7
- package/src/recyclerview/hooks/useUnmountAwareCallbacks.ts +73 -0
- package/src/recyclerview/hooks/useUnmountFlag.ts +1 -0
- package/src/recyclerview/layout-managers/GridLayoutManager.ts +68 -27
- package/src/recyclerview/layout-managers/LayoutManager.ts +116 -42
- package/src/recyclerview/layout-managers/LinearLayoutManager.ts +12 -8
- package/src/recyclerview/layout-managers/MasonryLayoutManager.ts +34 -13
- package/src/recyclerview/utils/componentUtils.ts +1 -1
- package/src/recyclerview/utils/findVisibleIndex.ts +1 -2
- package/src/recyclerview/utils/measureLayout.ts +41 -2
- package/src/recyclerview/utils/measureLayout.web.ts +102 -0
- package/src/viewability/ViewToken.ts +2 -2
- package/src/viewability/ViewabilityHelper.ts +1 -1
- package/src/viewability/ViewabilityManager.ts +16 -9
- package/dist/recyclerview/RecycleKeyManager.d.ts +0 -82
- package/dist/recyclerview/RecycleKeyManager.d.ts.map +0 -1
- package/dist/recyclerview/RecycleKeyManager.js +0 -135
- package/dist/recyclerview/RecycleKeyManager.js.map +0 -1
- package/src/recyclerview/RecycleKeyManager.ts +0 -185
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { useCallback, useEffect, useMemo } from "react";
|
|
2
|
-
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
2
|
+
|
|
3
3
|
import { RecyclerViewManager } from "../RecyclerViewManager";
|
|
4
|
-
import { RecyclerViewProps } from "../RecyclerViewProps";
|
|
5
4
|
import { CompatScroller } from "../components/CompatScroller";
|
|
6
5
|
|
|
6
|
+
import { useUnmountAwareAnimationFrame } from "./useUnmountAwareCallbacks";
|
|
7
|
+
|
|
7
8
|
/**
|
|
8
9
|
* Hook to detect when the scroll position reaches near the start or end of the list
|
|
9
10
|
* and trigger the appropriate callbacks. This hook is responsible for:
|
|
@@ -17,7 +18,6 @@ import { CompatScroller } from "../components/CompatScroller";
|
|
|
17
18
|
*/
|
|
18
19
|
export function useBoundDetection<T>(
|
|
19
20
|
recyclerViewManager: RecyclerViewManager<T>,
|
|
20
|
-
props: RecyclerViewProps<T>,
|
|
21
21
|
scrollViewRef: React.RefObject<CompatScroller>
|
|
22
22
|
) {
|
|
23
23
|
// Track whether we've already triggered the end reached callback to prevent duplicate calls
|
|
@@ -26,22 +26,48 @@ export function useBoundDetection<T>(
|
|
|
26
26
|
const pendingStartReached = useRef(false);
|
|
27
27
|
// Track whether we should auto-scroll to bottom when new content is added
|
|
28
28
|
const pendingAutoscrollToBottom = useRef(false);
|
|
29
|
-
|
|
29
|
+
|
|
30
|
+
const lastCheckBoundsTime = useRef(Date.now());
|
|
31
|
+
|
|
32
|
+
const { data } = recyclerViewManager.props;
|
|
33
|
+
const { requestAnimationFrame } = useUnmountAwareAnimationFrame();
|
|
34
|
+
|
|
35
|
+
const windowHeight = recyclerViewManager.hasLayout()
|
|
36
|
+
? recyclerViewManager.getWindowSize().height
|
|
37
|
+
: 0;
|
|
38
|
+
|
|
39
|
+
const contentHeight = recyclerViewManager.hasLayout()
|
|
40
|
+
? recyclerViewManager.getChildContainerDimensions().height
|
|
41
|
+
: 0;
|
|
42
|
+
|
|
43
|
+
const windowWidth = recyclerViewManager.hasLayout()
|
|
44
|
+
? recyclerViewManager.getWindowSize().width
|
|
45
|
+
: 0;
|
|
46
|
+
|
|
47
|
+
const contentWidth = recyclerViewManager.hasLayout()
|
|
48
|
+
? recyclerViewManager.getChildContainerDimensions().width
|
|
49
|
+
: 0;
|
|
30
50
|
|
|
31
51
|
/**
|
|
32
52
|
* Checks if the scroll position is near the start or end of the list
|
|
33
53
|
* and triggers appropriate callbacks if configured.
|
|
34
54
|
*/
|
|
35
55
|
const checkBounds = useCallback(() => {
|
|
56
|
+
lastCheckBoundsTime.current = Date.now();
|
|
57
|
+
|
|
58
|
+
const {
|
|
59
|
+
onEndReached,
|
|
60
|
+
onStartReached,
|
|
61
|
+
maintainVisibleContentPosition,
|
|
62
|
+
horizontal,
|
|
63
|
+
onEndReachedThreshold: onEndReachedThresholdProp,
|
|
64
|
+
onStartReachedThreshold: onStartReachedThresholdProp,
|
|
65
|
+
} = recyclerViewManager.props;
|
|
36
66
|
// Skip all calculations if neither callback is provided and autoscroll is disabled
|
|
37
67
|
const autoscrollToBottomThreshold =
|
|
38
68
|
maintainVisibleContentPosition?.autoscrollToBottomThreshold ?? -1;
|
|
39
69
|
|
|
40
|
-
if (
|
|
41
|
-
!props.onEndReached &&
|
|
42
|
-
!props.onStartReached &&
|
|
43
|
-
autoscrollToBottomThreshold < 0
|
|
44
|
-
) {
|
|
70
|
+
if (!onEndReached && !onStartReached && autoscrollToBottomThreshold < 0) {
|
|
45
71
|
return;
|
|
46
72
|
}
|
|
47
73
|
|
|
@@ -50,7 +76,7 @@ export function useBoundDetection<T>(
|
|
|
50
76
|
recyclerViewManager.getAbsoluteLastScrollOffset();
|
|
51
77
|
const contentSize = recyclerViewManager.getChildContainerDimensions();
|
|
52
78
|
const windowSize = recyclerViewManager.getWindowSize();
|
|
53
|
-
const isHorizontal =
|
|
79
|
+
const isHorizontal = horizontal === true;
|
|
54
80
|
|
|
55
81
|
// Calculate dimensions based on scroll direction
|
|
56
82
|
const visibleLength = isHorizontal ? windowSize.width : windowSize.height;
|
|
@@ -59,8 +85,8 @@ export function useBoundDetection<T>(
|
|
|
59
85
|
recyclerViewManager.firstItemOffset;
|
|
60
86
|
|
|
61
87
|
// Check if we're near the end of the list
|
|
62
|
-
if (
|
|
63
|
-
const onEndReachedThreshold =
|
|
88
|
+
if (onEndReached) {
|
|
89
|
+
const onEndReachedThreshold = onEndReachedThresholdProp ?? 0.5;
|
|
64
90
|
const endThresholdDistance = onEndReachedThreshold * visibleLength;
|
|
65
91
|
|
|
66
92
|
const isNearEnd =
|
|
@@ -69,27 +95,27 @@ export function useBoundDetection<T>(
|
|
|
69
95
|
|
|
70
96
|
if (isNearEnd && !pendingEndReached.current) {
|
|
71
97
|
pendingEndReached.current = true;
|
|
72
|
-
|
|
98
|
+
onEndReached();
|
|
73
99
|
}
|
|
74
100
|
pendingEndReached.current = isNearEnd;
|
|
75
101
|
}
|
|
76
102
|
|
|
77
103
|
// Check if we're near the start of the list
|
|
78
|
-
if (
|
|
79
|
-
const onStartReachedThreshold =
|
|
104
|
+
if (onStartReached) {
|
|
105
|
+
const onStartReachedThreshold = onStartReachedThresholdProp ?? 0.2;
|
|
80
106
|
const startThresholdDistance = onStartReachedThreshold * visibleLength;
|
|
81
107
|
|
|
82
108
|
const isNearStart = lastScrollOffset <= startThresholdDistance;
|
|
83
109
|
|
|
84
110
|
if (isNearStart && !pendingStartReached.current) {
|
|
85
111
|
pendingStartReached.current = true;
|
|
86
|
-
|
|
112
|
+
onStartReached();
|
|
87
113
|
}
|
|
88
114
|
pendingStartReached.current = isNearStart;
|
|
89
115
|
}
|
|
90
116
|
|
|
91
117
|
// Handle auto-scrolling to bottom for vertical lists
|
|
92
|
-
if (!
|
|
118
|
+
if (!isHorizontal && autoscrollToBottomThreshold >= 0) {
|
|
93
119
|
const autoscrollToBottomThresholdDistance =
|
|
94
120
|
autoscrollToBottomThreshold * visibleLength;
|
|
95
121
|
|
|
@@ -104,22 +130,45 @@ export function useBoundDetection<T>(
|
|
|
104
130
|
}
|
|
105
131
|
}
|
|
106
132
|
}
|
|
107
|
-
}, [recyclerViewManager
|
|
133
|
+
}, [recyclerViewManager]);
|
|
134
|
+
|
|
135
|
+
const runAutoScrollToBottomCheck = useCallback(() => {
|
|
136
|
+
if (pendingAutoscrollToBottom.current) {
|
|
137
|
+
pendingAutoscrollToBottom.current = false;
|
|
138
|
+
requestAnimationFrame(() => {
|
|
139
|
+
const shouldAnimate =
|
|
140
|
+
recyclerViewManager.props.maintainVisibleContentPosition
|
|
141
|
+
?.animateAutoScrollToBottom ?? true;
|
|
142
|
+
scrollViewRef.current?.scrollToEnd({
|
|
143
|
+
animated: shouldAnimate,
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}, [requestAnimationFrame, scrollViewRef, recyclerViewManager]);
|
|
108
148
|
|
|
109
149
|
// Reset end reached state when data changes
|
|
110
150
|
useMemo(() => {
|
|
111
151
|
pendingEndReached.current = false;
|
|
152
|
+
// needs to run only when data changes
|
|
153
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
112
154
|
}, [data]);
|
|
113
155
|
|
|
114
156
|
// Auto-scroll to bottom when new content is added and we're near the bottom
|
|
115
157
|
useEffect(() => {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
158
|
+
runAutoScrollToBottomCheck();
|
|
159
|
+
}, [data, runAutoScrollToBottomCheck, windowHeight, windowWidth]);
|
|
160
|
+
|
|
161
|
+
// Since content changes frequently, we try and avoid doing the auto scroll during active scrolls
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
if (Date.now() - lastCheckBoundsTime.current >= 100) {
|
|
164
|
+
runAutoScrollToBottomCheck();
|
|
121
165
|
}
|
|
122
|
-
}, [
|
|
166
|
+
}, [
|
|
167
|
+
contentHeight,
|
|
168
|
+
contentWidth,
|
|
169
|
+
recyclerViewManager.firstItemOffset,
|
|
170
|
+
runAutoScrollToBottomCheck,
|
|
171
|
+
]);
|
|
123
172
|
|
|
124
173
|
return {
|
|
125
174
|
checkBounds,
|
|
@@ -2,6 +2,13 @@ import { useState, useCallback } from "react";
|
|
|
2
2
|
|
|
3
3
|
import { useRecyclerViewContext } from "../RecyclerViewContextProvider";
|
|
4
4
|
|
|
5
|
+
export type LayoutStateSetter<T> = (
|
|
6
|
+
newValue: T | ((prevValue: T) => T),
|
|
7
|
+
skipParentLayout?: boolean
|
|
8
|
+
) => void;
|
|
9
|
+
|
|
10
|
+
export type LayoutStateInitialValue<T> = T | (() => T);
|
|
11
|
+
|
|
5
12
|
/**
|
|
6
13
|
* Custom hook that combines state management with RecyclerView layout updates.
|
|
7
14
|
* This hook provides a way to manage state that affects the layout of the RecyclerView,
|
|
@@ -13,8 +20,8 @@ import { useRecyclerViewContext } from "../RecyclerViewContextProvider";
|
|
|
13
20
|
* - A setter function that updates the state and triggers a layout recalculation
|
|
14
21
|
*/
|
|
15
22
|
export function useLayoutState<T>(
|
|
16
|
-
initialState: T
|
|
17
|
-
): [T,
|
|
23
|
+
initialState: LayoutStateInitialValue<T>
|
|
24
|
+
): [T, LayoutStateSetter<T>] {
|
|
18
25
|
// Initialize state with the provided initial value
|
|
19
26
|
const [state, setState] = useState<T>(initialState);
|
|
20
27
|
// Get the RecyclerView context for layout management
|
|
@@ -28,16 +35,18 @@ export function useLayoutState<T>(
|
|
|
28
35
|
* @param newValue - Either a new state value or a function that receives the previous state
|
|
29
36
|
* and returns the new state
|
|
30
37
|
*/
|
|
31
|
-
const setLayoutState = useCallback(
|
|
32
|
-
(newValue
|
|
38
|
+
const setLayoutState: LayoutStateSetter<T> = useCallback(
|
|
39
|
+
(newValue, skipParentLayout) => {
|
|
33
40
|
// Update the state using either the new value or the result of the updater function
|
|
34
41
|
setState((prevValue) =>
|
|
35
42
|
typeof newValue === "function"
|
|
36
43
|
? (newValue as (prevValue: T) => T)(prevValue)
|
|
37
44
|
: newValue
|
|
38
45
|
);
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
if (!skipParentLayout) {
|
|
47
|
+
// Trigger a layout recalculation in the RecyclerView
|
|
48
|
+
recyclerViewContext?.layout();
|
|
49
|
+
}
|
|
41
50
|
},
|
|
42
51
|
[recyclerViewContext]
|
|
43
52
|
);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
|
|
3
|
+
import { useRecyclerViewContext } from "../RecyclerViewContextProvider";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns a function that can help create a mapping key for the items.
|
|
7
|
+
* Useful when doing .map on items to create a list of components.
|
|
8
|
+
* Using this ensures that performance is optimal for FlashList
|
|
9
|
+
*/
|
|
10
|
+
export const useMappingHelper = () => {
|
|
11
|
+
const recyclerViewContext = useRecyclerViewContext();
|
|
12
|
+
const getMappingKey = useCallback(
|
|
13
|
+
(itemKey: string | number | bigint, index: number) => {
|
|
14
|
+
return recyclerViewContext ? index : itemKey;
|
|
15
|
+
},
|
|
16
|
+
[recyclerViewContext]
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
return { getMappingKey };
|
|
20
|
+
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
|
|
2
3
|
import { RecyclerViewManager } from "../RecyclerViewManager";
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
import { useUnmountAwareAnimationFrame } from "./useUnmountAwareCallbacks";
|
|
6
|
+
// import { ToastAndroid } from "react-native";
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* Hook to track when the RecyclerView has loaded its items and notify when loading is complete.
|
|
@@ -19,8 +21,8 @@ export const useOnListLoad = <T>(
|
|
|
19
21
|
const loadStartTimeRef = useRef<number>(Date.now());
|
|
20
22
|
const [isLoaded, setIsLoaded] = useState<boolean>(false);
|
|
21
23
|
const dataLength = recyclerViewManager.getDataLength();
|
|
22
|
-
//const dataCollector = useRef<number[]>([]);
|
|
23
|
-
const
|
|
24
|
+
// const dataCollector = useRef<number[]>([]);
|
|
25
|
+
const { requestAnimationFrame } = useUnmountAwareAnimationFrame();
|
|
24
26
|
// Track render cycles by collecting elapsed time on each render
|
|
25
27
|
// useEffect(() => {
|
|
26
28
|
// const elapsedTimeInMs = Date.now() - loadStartTimeRef.current;
|
|
@@ -29,6 +31,7 @@ export const useOnListLoad = <T>(
|
|
|
29
31
|
|
|
30
32
|
useMemo(() => {
|
|
31
33
|
loadStartTimeRef.current = Date.now();
|
|
34
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
32
35
|
}, [dataLength]);
|
|
33
36
|
|
|
34
37
|
useOnLoad(recyclerViewManager, () => {
|
|
@@ -42,13 +45,11 @@ export const useOnListLoad = <T>(
|
|
|
42
45
|
// `onLoad called after ${dataCollectorString}`,
|
|
43
46
|
// ToastAndroid.SHORT
|
|
44
47
|
// );
|
|
45
|
-
//console.log("----------> dataCollector", dataCollectorString);
|
|
46
|
-
//console.log("---------->
|
|
48
|
+
// console.log("----------> dataCollector", dataCollectorString);
|
|
49
|
+
// console.log("----------> FlashList v2 load in", `${elapsedTimeInMs} ms`);
|
|
47
50
|
requestAnimationFrame(() => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
setIsLoaded(true);
|
|
51
|
-
}
|
|
51
|
+
onLoad?.({ elapsedTimeInMs });
|
|
52
|
+
setIsLoaded(true);
|
|
52
53
|
});
|
|
53
54
|
});
|
|
54
55
|
|