@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
|
@@ -2,15 +2,20 @@ import { useEffect, useMemo, useState } from "react";
|
|
|
2
2
|
|
|
3
3
|
import { RecyclerViewProps } from "../RecyclerViewProps";
|
|
4
4
|
import { RecyclerViewManager } from "../RecyclerViewManager";
|
|
5
|
+
import { VelocityTracker } from "../helpers/VelocityTracker";
|
|
5
6
|
|
|
6
7
|
export const useRecyclerViewManager = <T>(props: RecyclerViewProps<T>) => {
|
|
7
8
|
const [recyclerViewManager] = useState<RecyclerViewManager<T>>(
|
|
8
9
|
() => new RecyclerViewManager(props)
|
|
9
10
|
);
|
|
11
|
+
const [velocityTracker] = useState(() => new VelocityTracker());
|
|
12
|
+
|
|
10
13
|
const { data } = props;
|
|
11
14
|
|
|
12
15
|
useMemo(() => {
|
|
13
16
|
recyclerViewManager.updateProps(props);
|
|
17
|
+
// used to update props so rule can be disabled
|
|
18
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
14
19
|
}, [props]);
|
|
15
20
|
|
|
16
21
|
/**
|
|
@@ -18,13 +23,20 @@ export const useRecyclerViewManager = <T>(props: RecyclerViewProps<T>) => {
|
|
|
18
23
|
*/
|
|
19
24
|
useMemo(() => {
|
|
20
25
|
recyclerViewManager.processDataUpdate();
|
|
26
|
+
// used to process data update so rule can be disabled
|
|
27
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
21
28
|
}, [data]);
|
|
22
29
|
|
|
23
30
|
useEffect(() => {
|
|
31
|
+
recyclerViewManager.restoreIfNeeded();
|
|
32
|
+
|
|
24
33
|
return () => {
|
|
25
34
|
recyclerViewManager.dispose();
|
|
35
|
+
velocityTracker.cleanUp();
|
|
26
36
|
};
|
|
37
|
+
// Used to perform cleanup on unmount
|
|
38
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27
39
|
}, []);
|
|
28
40
|
|
|
29
|
-
return { recyclerViewManager };
|
|
41
|
+
return { recyclerViewManager, velocityTracker };
|
|
30
42
|
};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useCallback, useMemo, useRef } from "react";
|
|
2
2
|
|
|
3
|
-
import { useLayoutState } from "./useLayoutState";
|
|
3
|
+
import { LayoutStateSetter, useLayoutState } from "./useLayoutState";
|
|
4
|
+
|
|
5
|
+
export type RecyclingStateSetter<T> = LayoutStateSetter<T>;
|
|
6
|
+
|
|
7
|
+
export type RecyclingStateInitialValue<T> = T | (() => T);
|
|
4
8
|
|
|
5
9
|
/**
|
|
6
10
|
* A custom hook that provides state management with automatic reset functionality.
|
|
@@ -16,10 +20,10 @@ import { useLayoutState } from "./useLayoutState";
|
|
|
16
20
|
* - A setState function that works like useState's setState
|
|
17
21
|
*/
|
|
18
22
|
export function useRecyclingState<T>(
|
|
19
|
-
initialState: T
|
|
23
|
+
initialState: RecyclingStateInitialValue<T>,
|
|
20
24
|
deps: React.DependencyList,
|
|
21
25
|
onReset?: () => void
|
|
22
|
-
): [T,
|
|
26
|
+
): [T, RecyclingStateSetter<T>] {
|
|
23
27
|
// Store the current state value in a ref to persist between renders
|
|
24
28
|
const valueStore = useRef<T>();
|
|
25
29
|
// Use layoutState to trigger re-renders when state changes
|
|
@@ -42,8 +46,8 @@ export function useRecyclingState<T>(
|
|
|
42
46
|
* Proxy setState function that updates the stored value and triggers a re-render.
|
|
43
47
|
* Only triggers a re-render if the new value is different from the current value.
|
|
44
48
|
*/
|
|
45
|
-
const setStateProxy = useCallback(
|
|
46
|
-
(newValue
|
|
49
|
+
const setStateProxy: RecyclingStateSetter<T> = useCallback(
|
|
50
|
+
(newValue, skipParentLayout) => {
|
|
47
51
|
// Calculate next state value from function or direct value
|
|
48
52
|
const nextState =
|
|
49
53
|
typeof newValue === "function"
|
|
@@ -53,7 +57,7 @@ export function useRecyclingState<T>(
|
|
|
53
57
|
// Only update and trigger re-render if value has changed
|
|
54
58
|
if (nextState !== valueStore.current) {
|
|
55
59
|
valueStore.current = nextState;
|
|
56
|
-
setCounter((prev) => prev + 1);
|
|
60
|
+
setCounter((prev) => prev + 1, skipParentLayout);
|
|
57
61
|
}
|
|
58
62
|
},
|
|
59
63
|
[setCounter]
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Animated, RefreshControl } from "react-native";
|
|
2
|
+
import React, { useMemo } from "react";
|
|
3
|
+
|
|
2
4
|
import { RecyclerViewProps } from "../RecyclerViewProps";
|
|
3
|
-
import { useMemo } from "react";
|
|
4
5
|
import { getValidComponent } from "../utils/componentUtils";
|
|
5
6
|
import { CompatView } from "../components/CompatView";
|
|
6
7
|
import { CompatAnimatedScroller } from "../components/CompatScroller";
|
|
7
|
-
import React from "react";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Hook that manages secondary props and components for the RecyclerView.
|
|
@@ -34,13 +34,16 @@ export function useSecondaryProps<T>(props: RecyclerViewProps<T>) {
|
|
|
34
34
|
progressViewOffset,
|
|
35
35
|
onRefresh,
|
|
36
36
|
data,
|
|
37
|
+
refreshControl: customRefreshControl,
|
|
37
38
|
} = props;
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
41
|
* Creates the refresh control component if onRefresh is provided.
|
|
41
42
|
*/
|
|
42
43
|
const refreshControl = useMemo(() => {
|
|
43
|
-
if (
|
|
44
|
+
if (customRefreshControl) {
|
|
45
|
+
return customRefreshControl;
|
|
46
|
+
} else if (onRefresh) {
|
|
44
47
|
return (
|
|
45
48
|
<RefreshControl
|
|
46
49
|
refreshing={Boolean(refreshing)}
|
|
@@ -50,7 +53,7 @@ export function useSecondaryProps<T>(props: RecyclerViewProps<T>) {
|
|
|
50
53
|
);
|
|
51
54
|
}
|
|
52
55
|
return undefined;
|
|
53
|
-
}, [onRefresh, refreshing, progressViewOffset]);
|
|
56
|
+
}, [onRefresh, refreshing, progressViewOffset, customRefreshControl]);
|
|
54
57
|
|
|
55
58
|
/**
|
|
56
59
|
* Creates the header component with optional styling.
|
|
@@ -99,9 +102,11 @@ export function useSecondaryProps<T>(props: RecyclerViewProps<T>) {
|
|
|
99
102
|
let scrollComponent = CompatAnimatedScroller;
|
|
100
103
|
if (typeof renderScrollComponent === "function") {
|
|
101
104
|
// Create a forwarded ref wrapper for the custom scroll component
|
|
102
|
-
|
|
103
|
-
(renderScrollComponent as any)({ ...
|
|
104
|
-
)
|
|
105
|
+
const ForwardedScrollComponent = React.forwardRef((_props, ref) =>
|
|
106
|
+
(renderScrollComponent as any)({ ..._props, ref } as any)
|
|
107
|
+
);
|
|
108
|
+
ForwardedScrollComponent.displayName = "CustomScrollView";
|
|
109
|
+
scrollComponent = ForwardedScrollComponent as any;
|
|
105
110
|
} else if (renderScrollComponent) {
|
|
106
111
|
scrollComponent = renderScrollComponent;
|
|
107
112
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hook that provides a setTimeout which is aware of component unmount state.
|
|
5
|
+
* Any timeouts created with this hook will be automatically cleared when the component unmounts.
|
|
6
|
+
*/
|
|
7
|
+
export function useUnmountAwareTimeout() {
|
|
8
|
+
// Store active timeout IDs in a Set for more efficient add/remove operations
|
|
9
|
+
const [timeoutIds] = useState<Set<NodeJS.Timeout>>(() => new Set());
|
|
10
|
+
|
|
11
|
+
// Clear all timeouts on unmount
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
return () => {
|
|
14
|
+
timeoutIds.forEach((id) => global.clearTimeout(id));
|
|
15
|
+
timeoutIds.clear();
|
|
16
|
+
};
|
|
17
|
+
}, [timeoutIds]);
|
|
18
|
+
|
|
19
|
+
// Create a safe setTimeout that will be cleared on unmount
|
|
20
|
+
const setTimeout = useCallback(
|
|
21
|
+
(callback: () => void, delay: number): void => {
|
|
22
|
+
const id = global.setTimeout(() => {
|
|
23
|
+
// Remove this timeout ID from the tracking set
|
|
24
|
+
timeoutIds.delete(id);
|
|
25
|
+
callback();
|
|
26
|
+
}, delay);
|
|
27
|
+
|
|
28
|
+
// Track this timeout ID
|
|
29
|
+
timeoutIds.add(id);
|
|
30
|
+
},
|
|
31
|
+
[timeoutIds]
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
setTimeout,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Hook that provides a requestAnimationFrame which is aware of component unmount state.
|
|
41
|
+
* Any animation frames requested with this hook will be automatically canceled when the component unmounts.
|
|
42
|
+
*/
|
|
43
|
+
export function useUnmountAwareAnimationFrame() {
|
|
44
|
+
// Store active animation frame request IDs in a Set for more efficient add/remove operations
|
|
45
|
+
const [requestIds] = useState<Set<number>>(() => new Set());
|
|
46
|
+
|
|
47
|
+
// Cancel all animation frame requests on unmount
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
return () => {
|
|
50
|
+
requestIds.forEach((id) => cancelAnimationFrame(id));
|
|
51
|
+
requestIds.clear();
|
|
52
|
+
};
|
|
53
|
+
}, [requestIds]);
|
|
54
|
+
|
|
55
|
+
// Create a safe requestAnimationFrame that will be canceled on unmount
|
|
56
|
+
const requestAnimationFrame = useCallback(
|
|
57
|
+
(callback: FrameRequestCallback): void => {
|
|
58
|
+
const id = global.requestAnimationFrame((timestamp) => {
|
|
59
|
+
// Remove this request ID from the tracking set
|
|
60
|
+
requestIds.delete(id);
|
|
61
|
+
callback(timestamp);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Track this request ID
|
|
65
|
+
requestIds.add(id);
|
|
66
|
+
},
|
|
67
|
+
[requestIds]
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
requestAnimationFrame,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -16,6 +16,7 @@ export const useUnmountFlag = () => {
|
|
|
16
16
|
// Use layoutEffect to set up cleanup on unmount
|
|
17
17
|
// This ensures the flag is set before any other cleanup effects run
|
|
18
18
|
useLayoutEffect(() => {
|
|
19
|
+
isUnmounted.current = false;
|
|
19
20
|
// Cleanup function that runs when the component unmounts
|
|
20
21
|
return () => {
|
|
21
22
|
isUnmounted.current = true;
|
|
@@ -14,6 +14,9 @@ export class RVGridLayoutManagerImpl extends RVLayoutManager {
|
|
|
14
14
|
/** The width of the bounded area for the grid */
|
|
15
15
|
private boundedSize: number;
|
|
16
16
|
|
|
17
|
+
/** If there's a span change for grid layout, we need to recompute all the widths */
|
|
18
|
+
private fullRelayoutRequired = false;
|
|
19
|
+
|
|
17
20
|
constructor(params: LayoutParams, previousLayoutManager?: RVLayoutManager) {
|
|
18
21
|
super(params, previousLayoutManager);
|
|
19
22
|
this.boundedSize = params.windowSize.width;
|
|
@@ -32,11 +35,8 @@ export class RVGridLayoutManagerImpl extends RVLayoutManager {
|
|
|
32
35
|
) {
|
|
33
36
|
this.boundedSize = params.windowSize.width;
|
|
34
37
|
if (this.layouts.length > 0) {
|
|
35
|
-
//update all widths
|
|
36
|
-
|
|
37
|
-
this.layouts[i].width = this.getWidth(i);
|
|
38
|
-
}
|
|
39
|
-
//console.log("-----> recomputeLayouts");
|
|
38
|
+
// update all widths
|
|
39
|
+
this.updateAllWidths();
|
|
40
40
|
|
|
41
41
|
this.recomputeLayouts(0, this.layouts.length - 1);
|
|
42
42
|
this.requiresRepaint = true;
|
|
@@ -57,6 +57,13 @@ export class RVGridLayoutManagerImpl extends RVLayoutManager {
|
|
|
57
57
|
layout.isHeightMeasured = true;
|
|
58
58
|
layout.isWidthMeasured = true;
|
|
59
59
|
}
|
|
60
|
+
|
|
61
|
+
// TODO: Can be optimized
|
|
62
|
+
if (this.fullRelayoutRequired) {
|
|
63
|
+
this.updateAllWidths();
|
|
64
|
+
this.fullRelayoutRequired = false;
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
60
67
|
}
|
|
61
68
|
|
|
62
69
|
/**
|
|
@@ -72,18 +79,24 @@ export class RVGridLayoutManagerImpl extends RVLayoutManager {
|
|
|
72
79
|
layout.enforcedWidth = true;
|
|
73
80
|
}
|
|
74
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Handles span change for an item.
|
|
84
|
+
* @param index Index of the item
|
|
85
|
+
*/
|
|
86
|
+
handleSpanChange(index: number) {
|
|
87
|
+
this.fullRelayoutRequired = true;
|
|
88
|
+
}
|
|
89
|
+
|
|
75
90
|
/**
|
|
76
91
|
* Returns the total size of the layout area.
|
|
77
92
|
* @returns RVDimension containing width and height of the layout
|
|
78
93
|
*/
|
|
79
94
|
getLayoutSize(): RVDimension {
|
|
80
95
|
if (this.layouts.length === 0) return { width: 0, height: 0 };
|
|
81
|
-
const
|
|
82
|
-
this.layouts.length - 1
|
|
83
|
-
);
|
|
96
|
+
const totalHeight = this.computeTotalHeightTillRow(this.layouts.length - 1);
|
|
84
97
|
return {
|
|
85
98
|
width: this.boundedSize,
|
|
86
|
-
height:
|
|
99
|
+
height: totalHeight,
|
|
87
100
|
};
|
|
88
101
|
}
|
|
89
102
|
|
|
@@ -93,7 +106,9 @@ export class RVGridLayoutManagerImpl extends RVLayoutManager {
|
|
|
93
106
|
* @param endIndex Ending index of items to recompute
|
|
94
107
|
*/
|
|
95
108
|
recomputeLayouts(startIndex: number, endIndex: number): void {
|
|
96
|
-
const newStartIndex = this.
|
|
109
|
+
const newStartIndex = this.locateFirstIndexInRow(
|
|
110
|
+
Math.max(0, startIndex - 1)
|
|
111
|
+
);
|
|
97
112
|
const startVal = this.getLayout(newStartIndex);
|
|
98
113
|
|
|
99
114
|
let startX = startVal.x;
|
|
@@ -102,7 +117,7 @@ export class RVGridLayoutManagerImpl extends RVLayoutManager {
|
|
|
102
117
|
for (let i = newStartIndex; i <= endIndex; i++) {
|
|
103
118
|
const layout = this.getLayout(i);
|
|
104
119
|
if (!this.checkBounds(startX, layout.width)) {
|
|
105
|
-
const tallestItem = this.processAndReturnTallestItemInRow(i);
|
|
120
|
+
const tallestItem = this.processAndReturnTallestItemInRow(i - 1);
|
|
106
121
|
startY = tallestItem.y + tallestItem.height;
|
|
107
122
|
startX = 0;
|
|
108
123
|
}
|
|
@@ -111,6 +126,9 @@ export class RVGridLayoutManagerImpl extends RVLayoutManager {
|
|
|
111
126
|
layout.y = startY;
|
|
112
127
|
startX += layout.width;
|
|
113
128
|
}
|
|
129
|
+
if (endIndex === this.layouts.length - 1) {
|
|
130
|
+
this.processAndReturnTallestItemInRow(endIndex);
|
|
131
|
+
}
|
|
114
132
|
}
|
|
115
133
|
|
|
116
134
|
/**
|
|
@@ -119,26 +137,23 @@ export class RVGridLayoutManagerImpl extends RVLayoutManager {
|
|
|
119
137
|
* @returns Width of the item
|
|
120
138
|
*/
|
|
121
139
|
private getWidth(index: number): number {
|
|
122
|
-
|
|
123
|
-
return (this.boundedSize / this.maxColumns) * span;
|
|
140
|
+
return (this.boundedSize / this.maxColumns) * this.getSpan(index);
|
|
124
141
|
}
|
|
125
142
|
|
|
126
143
|
/**
|
|
127
144
|
* Processes items in a row and returns the tallest item.
|
|
128
145
|
* Also handles height normalization for items in the same row.
|
|
129
146
|
* Tallest item per row helps in forcing tallest items height on neighbouring items.
|
|
130
|
-
* @param
|
|
147
|
+
* @param endIndex Index of the last item in the row
|
|
131
148
|
* @returns The tallest item in the row
|
|
132
149
|
*/
|
|
133
|
-
private processAndReturnTallestItemInRow(
|
|
134
|
-
const startIndex = this.
|
|
135
|
-
const y = this.layouts[startIndex].y;
|
|
150
|
+
private processAndReturnTallestItemInRow(endIndex: number): RVLayout {
|
|
151
|
+
const startIndex = this.locateFirstIndexInRow(endIndex);
|
|
136
152
|
let tallestItem: RVLayout | undefined;
|
|
137
153
|
let maxHeight = 0;
|
|
138
154
|
let i = startIndex;
|
|
139
155
|
let isMeasured = false;
|
|
140
|
-
|
|
141
|
-
while (Math.ceil(this.layouts[i].y) === Math.ceil(y)) {
|
|
156
|
+
while (i <= endIndex) {
|
|
142
157
|
const layout = this.layouts[i];
|
|
143
158
|
isMeasured = isMeasured || Boolean(layout.isHeightMeasured);
|
|
144
159
|
maxHeight = Math.max(maxHeight, layout.height);
|
|
@@ -154,7 +169,9 @@ export class RVGridLayoutManagerImpl extends RVLayoutManager {
|
|
|
154
169
|
break;
|
|
155
170
|
}
|
|
156
171
|
}
|
|
157
|
-
|
|
172
|
+
if (!tallestItem && maxHeight > 0) {
|
|
173
|
+
maxHeight = Number.MAX_SAFE_INTEGER;
|
|
174
|
+
}
|
|
158
175
|
tallestItem = tallestItem ?? this.layouts[startIndex];
|
|
159
176
|
|
|
160
177
|
if (!isMeasured) {
|
|
@@ -168,8 +185,7 @@ export class RVGridLayoutManagerImpl extends RVLayoutManager {
|
|
|
168
185
|
this.requiresRepaint = true;
|
|
169
186
|
}
|
|
170
187
|
i = startIndex;
|
|
171
|
-
|
|
172
|
-
while (Math.ceil(this.layouts[i].y) === Math.ceil(y)) {
|
|
188
|
+
while (i <= endIndex) {
|
|
173
189
|
this.layouts[i].minHeight = targetHeight;
|
|
174
190
|
if (targetHeight > 0) {
|
|
175
191
|
this.layouts[i].height = targetHeight;
|
|
@@ -184,6 +200,32 @@ export class RVGridLayoutManagerImpl extends RVLayoutManager {
|
|
|
184
200
|
return tallestItem;
|
|
185
201
|
}
|
|
186
202
|
|
|
203
|
+
/**
|
|
204
|
+
* Computes the total height of the layout.
|
|
205
|
+
* @param endIndex Index of the last item in the row
|
|
206
|
+
* @returns Total height of the layout
|
|
207
|
+
*/
|
|
208
|
+
private computeTotalHeightTillRow(endIndex: number): number {
|
|
209
|
+
const startIndex = this.locateFirstIndexInRow(endIndex);
|
|
210
|
+
const y = this.layouts[startIndex].y;
|
|
211
|
+
let maxHeight = 0;
|
|
212
|
+
let i = startIndex;
|
|
213
|
+
while (i <= endIndex) {
|
|
214
|
+
maxHeight = Math.max(maxHeight, this.layouts[i].height);
|
|
215
|
+
i++;
|
|
216
|
+
if (i >= this.layouts.length) {
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return y + maxHeight;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
private updateAllWidths() {
|
|
224
|
+
for (let i = 0; i < this.layouts.length; i++) {
|
|
225
|
+
this.layouts[i].width = this.getWidth(i);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
187
229
|
/**
|
|
188
230
|
* Checks if an item can fit within the bounded width.
|
|
189
231
|
* @param itemX Starting X position of the item
|
|
@@ -191,20 +233,19 @@ export class RVGridLayoutManagerImpl extends RVLayoutManager {
|
|
|
191
233
|
* @returns True if the item fits within bounds
|
|
192
234
|
*/
|
|
193
235
|
private checkBounds(itemX: number, width: number): boolean {
|
|
194
|
-
// TODO: Manage precision problems
|
|
195
236
|
return itemX + width <= this.boundedSize + 0.9;
|
|
196
237
|
}
|
|
197
238
|
|
|
198
239
|
/**
|
|
199
240
|
* Locates the index of the first item in the current row.
|
|
200
|
-
* @param
|
|
241
|
+
* @param itemIndex Index to start searching from
|
|
201
242
|
* @returns Index of the first item in the row
|
|
202
243
|
*/
|
|
203
|
-
private
|
|
204
|
-
if (
|
|
244
|
+
private locateFirstIndexInRow(itemIndex: number): number {
|
|
245
|
+
if (itemIndex === 0) {
|
|
205
246
|
return 0;
|
|
206
247
|
}
|
|
207
|
-
let i =
|
|
248
|
+
let i = itemIndex;
|
|
208
249
|
for (; i >= 0; i--) {
|
|
209
250
|
if (this.layouts[i].x === 0) {
|
|
210
251
|
break;
|