@shopify/flash-list 2.0.0-alpha.1 → 2.0.0-alpha.11
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 +40 -5
- 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 +16 -9
- package/dist/FlashListProps.d.ts.map +1 -1
- package/dist/FlashListProps.js.map +1 -1
- package/dist/FlashListRef.d.ts +295 -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__/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 +94 -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 +405 -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 +111 -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 -3
- 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 +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -6
- 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/RecyclerView.d.ts +3 -2
- package/dist/recyclerview/RecyclerView.d.ts.map +1 -1
- package/dist/recyclerview/RecyclerView.js +87 -51
- package/dist/recyclerview/RecyclerView.js.map +1 -1
- package/dist/recyclerview/RecyclerViewContextProvider.d.ts +6 -6
- package/dist/recyclerview/RecyclerViewContextProvider.d.ts.map +1 -1
- package/dist/recyclerview/RecyclerViewContextProvider.js +2 -2
- package/dist/recyclerview/RecyclerViewContextProvider.js.map +1 -1
- package/dist/recyclerview/RecyclerViewManager.d.ts +20 -6
- package/dist/recyclerview/RecyclerViewManager.d.ts.map +1 -1
- package/dist/recyclerview/RecyclerViewManager.js +98 -95
- 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 +85 -0
- package/dist/recyclerview/RenderStackManager.d.ts.map +1 -0
- package/dist/recyclerview/RenderStackManager.js +261 -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 +4 -2
- package/dist/recyclerview/ViewHolderCollection.d.ts.map +1 -1
- package/dist/recyclerview/ViewHolderCollection.js +19 -4
- package/dist/recyclerview/ViewHolderCollection.js.map +1 -1
- package/dist/recyclerview/components/ScrollAnchor.d.ts +1 -0
- package/dist/recyclerview/components/ScrollAnchor.d.ts.map +1 -1
- package/dist/recyclerview/components/ScrollAnchor.js +6 -7
- package/dist/recyclerview/components/ScrollAnchor.js.map +1 -1
- package/dist/recyclerview/components/StickyHeaders.d.ts +1 -1
- package/dist/recyclerview/components/StickyHeaders.d.ts.map +1 -1
- package/dist/recyclerview/components/StickyHeaders.js +49 -30
- 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 +90 -19
- package/dist/recyclerview/helpers/EngagedIndicesTracker.js.map +1 -1
- package/dist/recyclerview/helpers/RenderTimeTracker.d.ts +10 -0
- package/dist/recyclerview/helpers/RenderTimeTracker.d.ts.map +1 -0
- package/dist/recyclerview/helpers/RenderTimeTracker.js +39 -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 +23 -22
- package/dist/recyclerview/hooks/useBoundDetection.js.map +1 -1
- package/dist/recyclerview/hooks/useLayoutState.js +1 -2
- 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 +3 -48
- package/dist/recyclerview/hooks/useRecyclerViewController.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useRecyclerViewController.js +236 -160
- 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 +10 -1
- package/dist/recyclerview/hooks/useRecyclerViewManager.js.map +1 -1
- package/dist/recyclerview/hooks/useRecyclingState.js +1 -2
- 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/layout-managers/GridLayoutManager.d.ts +6 -0
- package/dist/recyclerview/layout-managers/GridLayoutManager.d.ts.map +1 -1
- package/dist/recyclerview/layout-managers/GridLayoutManager.js +29 -10
- package/dist/recyclerview/layout-managers/GridLayoutManager.js.map +1 -1
- package/dist/recyclerview/layout-managers/LayoutManager.d.ts +3 -2
- package/dist/recyclerview/layout-managers/LayoutManager.d.ts.map +1 -1
- package/dist/recyclerview/layout-managers/LayoutManager.js +7 -3
- 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.map +1 -1
- package/dist/recyclerview/layout-managers/MasonryLayoutManager.js +5 -7
- 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 +89 -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/ViewabilityHelper.js.map +1 -1
- package/dist/viewability/ViewabilityManager.d.ts.map +1 -1
- 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 +17 -8
- package/src/FlashListRef.ts +309 -0
- package/src/__tests__/ConsecutiveNumbers.test.ts +232 -0
- package/src/__tests__/GridLayoutManager.test.ts +113 -0
- package/src/__tests__/LinearLayoutManager.test.ts +227 -0
- package/src/__tests__/MasonryLayoutManager.test.ts +202 -0
- package/src/__tests__/RecyclerView.test.tsx +123 -0
- package/src/__tests__/RenderStackManager.test.ts +488 -0
- package/src/__tests__/findVisibleIndex.test.ts +369 -0
- package/src/__tests__/helpers/createLayoutManager.ts +142 -0
- package/src/__tests__/useUnmountAwareCallbacks.test.tsx +285 -0
- package/src/benchmark/useFlatListBenchmark.ts +2 -2
- package/src/enableNewCore.ts +3 -1
- package/src/index.ts +22 -7
- 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/RecyclerView.tsx +110 -60
- package/src/recyclerview/RecyclerViewContextProvider.ts +13 -6
- package/src/recyclerview/RecyclerViewManager.ts +116 -76
- package/src/recyclerview/RecyclerViewProps.ts +2 -1
- package/src/recyclerview/RenderStackManager.ts +265 -0
- package/src/recyclerview/ViewHolder.tsx +13 -6
- package/src/recyclerview/ViewHolderCollection.tsx +32 -10
- package/src/recyclerview/components/ScrollAnchor.tsx +13 -8
- package/src/recyclerview/components/StickyHeaders.tsx +65 -33
- package/src/recyclerview/helpers/ConsecutiveNumbers.ts +2 -2
- package/src/recyclerview/helpers/EngagedIndicesTracker.ts +136 -25
- package/src/recyclerview/helpers/RenderTimeTracker.ts +38 -0
- package/src/recyclerview/helpers/VelocityTracker.ts +77 -0
- package/src/recyclerview/hooks/useBoundDetection.ts +27 -20
- package/src/recyclerview/hooks/useMappingHelper.ts +20 -0
- package/src/recyclerview/hooks/useOnLoad.ts +11 -10
- package/src/recyclerview/hooks/useRecyclerViewController.tsx +275 -237
- package/src/recyclerview/hooks/useRecyclerViewManager.ts +11 -1
- package/src/recyclerview/hooks/useSecondaryProps.tsx +12 -7
- package/src/recyclerview/hooks/useUnmountAwareCallbacks.ts +73 -0
- package/src/recyclerview/layout-managers/GridLayoutManager.ts +32 -12
- package/src/recyclerview/layout-managers/LayoutManager.ts +9 -4
- package/src/recyclerview/layout-managers/LinearLayoutManager.ts +12 -8
- package/src/recyclerview/layout-managers/MasonryLayoutManager.ts +4 -5
- 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 +104 -0
- package/src/viewability/ViewToken.ts +1 -1
- 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
|
@@ -19,11 +19,14 @@ import {
|
|
|
19
19
|
NativeSyntheticEvent,
|
|
20
20
|
} from "react-native";
|
|
21
21
|
|
|
22
|
+
import { FlashListRef } from "../FlashListRef";
|
|
23
|
+
|
|
22
24
|
import { RVDimension } from "./layout-managers/LayoutManager";
|
|
23
25
|
import {
|
|
24
26
|
areDimensionsNotEqual,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
measureFirstChildLayout,
|
|
28
|
+
measureItemLayout,
|
|
29
|
+
measureParentSize,
|
|
27
30
|
} from "./utils/measureLayout";
|
|
28
31
|
import {
|
|
29
32
|
RecyclerViewContext,
|
|
@@ -46,6 +49,7 @@ import { useSecondaryProps } from "./hooks/useSecondaryProps";
|
|
|
46
49
|
import { StickyHeaders, StickyHeaderRef } from "./components/StickyHeaders";
|
|
47
50
|
import { ScrollAnchor, ScrollAnchorRef } from "./components/ScrollAnchor";
|
|
48
51
|
import { useRecyclerViewController } from "./hooks/useRecyclerViewController";
|
|
52
|
+
import { RenderTimeTracker } from "./helpers/RenderTimeTracker";
|
|
49
53
|
|
|
50
54
|
/**
|
|
51
55
|
* Main RecyclerView component that handles list rendering, scrolling, and item recycling.
|
|
@@ -53,7 +57,7 @@ import { useRecyclerViewController } from "./hooks/useRecyclerViewController";
|
|
|
53
57
|
*/
|
|
54
58
|
const RecyclerViewComponent = <T,>(
|
|
55
59
|
props: RecyclerViewProps<T>,
|
|
56
|
-
ref: React.Ref<
|
|
60
|
+
ref: React.Ref<FlashListRef<T>>
|
|
57
61
|
) => {
|
|
58
62
|
// Destructure props and initialize refs
|
|
59
63
|
const {
|
|
@@ -74,8 +78,6 @@ const RecyclerViewComponent = <T,>(
|
|
|
74
78
|
ListFooterComponentStyle,
|
|
75
79
|
ItemSeparatorComponent,
|
|
76
80
|
renderScrollComponent,
|
|
77
|
-
onScroll,
|
|
78
|
-
disableRecycling,
|
|
79
81
|
style,
|
|
80
82
|
stickyHeaderIndices,
|
|
81
83
|
maintainVisibleContentPosition,
|
|
@@ -83,10 +85,14 @@ const RecyclerViewComponent = <T,>(
|
|
|
83
85
|
...rest
|
|
84
86
|
} = props;
|
|
85
87
|
|
|
88
|
+
const [renderTimeTracker] = useState(() => new RenderTimeTracker());
|
|
89
|
+
|
|
90
|
+
renderTimeTracker.startTracking();
|
|
91
|
+
|
|
86
92
|
// Core refs for managing scroll view, internal view, and child container
|
|
87
93
|
const scrollViewRef = useRef<CompatScroller>(null);
|
|
88
94
|
const internalViewRef = useRef<CompatView>(null);
|
|
89
|
-
const
|
|
95
|
+
const firstChildViewRef = useRef<CompatView>(null);
|
|
90
96
|
const containerViewSizeRef = useRef<RVDimension | undefined>(undefined);
|
|
91
97
|
const pendingChildIds = useRef<Set<string>>(new Set()).current;
|
|
92
98
|
|
|
@@ -108,14 +114,14 @@ const RecyclerViewComponent = <T,>(
|
|
|
108
114
|
);
|
|
109
115
|
|
|
110
116
|
// Initialize core RecyclerView manager and content offset management
|
|
111
|
-
const { recyclerViewManager } =
|
|
112
|
-
|
|
117
|
+
const { recyclerViewManager, velocityTracker } =
|
|
118
|
+
useRecyclerViewManager(props);
|
|
119
|
+
const { applyContentOffset, applyInitialScrollIndex, handlerMethods } =
|
|
113
120
|
useRecyclerViewController(
|
|
114
121
|
recyclerViewManager,
|
|
115
122
|
ref,
|
|
116
123
|
scrollViewRef,
|
|
117
|
-
scrollAnchorRef
|
|
118
|
-
props
|
|
124
|
+
scrollAnchorRef
|
|
119
125
|
);
|
|
120
126
|
|
|
121
127
|
// Initialize view holder collection ref
|
|
@@ -125,40 +131,44 @@ const RecyclerViewComponent = <T,>(
|
|
|
125
131
|
useOnListLoad(recyclerViewManager, onLoad);
|
|
126
132
|
|
|
127
133
|
// Hook to detect when scrolling reaches list bounds
|
|
128
|
-
const { checkBounds } = useBoundDetection(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
scrollViewRef
|
|
132
|
-
);
|
|
134
|
+
const { checkBounds } = useBoundDetection(recyclerViewManager, scrollViewRef);
|
|
135
|
+
|
|
136
|
+
const isHorizontalRTL = I18nManager.isRTL && horizontal;
|
|
133
137
|
|
|
134
138
|
/**
|
|
135
139
|
* Initialize the RecyclerView by measuring and setting up the window size
|
|
136
140
|
* This effect runs when the component mounts or when layout changes
|
|
137
141
|
*/
|
|
138
142
|
useLayoutEffect(() => {
|
|
139
|
-
if (internalViewRef.current &&
|
|
143
|
+
if (internalViewRef.current && firstChildViewRef.current) {
|
|
140
144
|
// Measure the outer and inner container layouts
|
|
141
|
-
const outerViewLayout =
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
internalViewRef.current
|
|
145
|
-
undefined
|
|
145
|
+
const outerViewLayout = measureParentSize(internalViewRef.current);
|
|
146
|
+
const firstChildViewLayout = measureFirstChildLayout(
|
|
147
|
+
firstChildViewRef.current,
|
|
148
|
+
internalViewRef.current
|
|
146
149
|
);
|
|
147
150
|
|
|
148
151
|
containerViewSizeRef.current = outerViewLayout;
|
|
149
152
|
|
|
150
153
|
// Calculate offset of first item
|
|
151
154
|
const firstItemOffset = horizontal
|
|
152
|
-
?
|
|
153
|
-
:
|
|
155
|
+
? firstChildViewLayout.x - outerViewLayout.x
|
|
156
|
+
: firstChildViewLayout.y - outerViewLayout.y;
|
|
154
157
|
|
|
155
158
|
// Update the RecyclerView manager with window dimensions
|
|
156
159
|
recyclerViewManager.updateLayoutParams(
|
|
157
160
|
{
|
|
158
|
-
width: horizontal
|
|
159
|
-
|
|
161
|
+
width: horizontal
|
|
162
|
+
? outerViewLayout.width
|
|
163
|
+
: firstChildViewLayout.width,
|
|
164
|
+
height: horizontal
|
|
165
|
+
? firstChildViewLayout.height
|
|
166
|
+
: outerViewLayout.height,
|
|
160
167
|
},
|
|
161
|
-
|
|
168
|
+
isHorizontalRTL && recyclerViewManager.hasLayout()
|
|
169
|
+
? firstItemOffset -
|
|
170
|
+
recyclerViewManager.getChildContainerDimensions().width
|
|
171
|
+
: firstItemOffset
|
|
162
172
|
);
|
|
163
173
|
}
|
|
164
174
|
});
|
|
@@ -167,18 +177,19 @@ const RecyclerViewComponent = <T,>(
|
|
|
167
177
|
* Effect to handle layout updates for list items
|
|
168
178
|
* This ensures proper positioning and recycling of items
|
|
169
179
|
*/
|
|
180
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
170
181
|
useLayoutEffect(() => {
|
|
171
182
|
if (pendingChildIds.size > 0) {
|
|
172
183
|
return;
|
|
173
184
|
}
|
|
174
185
|
const layoutInfo = Array.from(refHolder, ([index, viewHolderRef]) => {
|
|
175
|
-
const layout =
|
|
186
|
+
const layout = measureItemLayout(
|
|
176
187
|
viewHolderRef.current!,
|
|
177
188
|
recyclerViewManager.getLayout(index)
|
|
178
189
|
);
|
|
179
190
|
|
|
180
|
-
//comapre height with stored layout
|
|
181
|
-
//const storedLayout = recyclerViewManager.getLayout(index);
|
|
191
|
+
// comapre height with stored layout
|
|
192
|
+
// const storedLayout = recyclerViewManager.getLayout(index);
|
|
182
193
|
// if (
|
|
183
194
|
// storedLayout.height !== layout.height &&
|
|
184
195
|
// storedLayout.isHeightMeasured
|
|
@@ -199,8 +210,6 @@ const RecyclerViewComponent = <T,>(
|
|
|
199
210
|
// Trigger re-render if layout modifications were made
|
|
200
211
|
setRenderId((prev) => prev + 1);
|
|
201
212
|
} else {
|
|
202
|
-
//console.log("commitLayout");
|
|
203
|
-
// TODO: reduce perf impact of commitLayout
|
|
204
213
|
viewHolderCollectionRef.current?.commitLayout();
|
|
205
214
|
applyContentOffset();
|
|
206
215
|
}
|
|
@@ -211,30 +220,44 @@ const RecyclerViewComponent = <T,>(
|
|
|
211
220
|
*/
|
|
212
221
|
const onScrollHandler = useCallback(
|
|
213
222
|
(event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
214
|
-
|
|
223
|
+
if (recyclerViewManager.ignoreScrollEvents) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
|
|
215
227
|
let scrollOffset = horizontal
|
|
216
228
|
? event.nativeEvent.contentOffset.x
|
|
217
229
|
: event.nativeEvent.contentOffset.y;
|
|
218
230
|
|
|
219
231
|
// Handle RTL (Right-to-Left) layout adjustments
|
|
220
|
-
if (
|
|
232
|
+
if (isHorizontalRTL) {
|
|
221
233
|
scrollOffset = adjustOffsetForRTL(
|
|
222
234
|
scrollOffset,
|
|
223
235
|
event.nativeEvent.contentSize.width,
|
|
224
236
|
event.nativeEvent.layoutMeasurement.width
|
|
225
237
|
);
|
|
226
|
-
if (velocity) {
|
|
227
|
-
velocity = {
|
|
228
|
-
x: -velocity.x,
|
|
229
|
-
y: velocity.y,
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
238
|
}
|
|
233
239
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
240
|
+
velocityTracker.computeVelocity(
|
|
241
|
+
scrollOffset,
|
|
242
|
+
recyclerViewManager.getAbsoluteLastScrollOffset(),
|
|
243
|
+
Boolean(horizontal),
|
|
244
|
+
(velocity, isMomentumEnd) => {
|
|
245
|
+
if (recyclerViewManager.ignoreScrollEvents) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (isMomentumEnd) {
|
|
250
|
+
if (!recyclerViewManager.isOffsetProjectionEnabled) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
recyclerViewManager.resetVelocityCompute();
|
|
254
|
+
}
|
|
255
|
+
// Update scroll position and trigger re-render if needed
|
|
256
|
+
if (recyclerViewManager.updateScrollOffset(scrollOffset, velocity)) {
|
|
257
|
+
setRenderId((prev) => prev + 1);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
);
|
|
238
261
|
|
|
239
262
|
// Update sticky headers and check bounds
|
|
240
263
|
stickyHeaderRef.current?.reportScrollEvent(event.nativeEvent);
|
|
@@ -245,22 +268,31 @@ const RecyclerViewComponent = <T,>(
|
|
|
245
268
|
recyclerViewManager.computeItemViewability();
|
|
246
269
|
|
|
247
270
|
// Call user-provided onScroll handler
|
|
248
|
-
onScroll?.(event);
|
|
271
|
+
recyclerViewManager.props.onScroll?.(event);
|
|
249
272
|
},
|
|
250
|
-
[
|
|
273
|
+
[
|
|
274
|
+
checkBounds,
|
|
275
|
+
horizontal,
|
|
276
|
+
isHorizontalRTL,
|
|
277
|
+
recyclerViewManager,
|
|
278
|
+
velocityTracker,
|
|
279
|
+
]
|
|
251
280
|
);
|
|
252
281
|
|
|
253
282
|
// Create context for child components
|
|
254
|
-
const recyclerViewContext: RecyclerViewContext = useMemo(() => {
|
|
283
|
+
const recyclerViewContext: RecyclerViewContext<T> = useMemo(() => {
|
|
255
284
|
return {
|
|
256
285
|
layout: () => {
|
|
257
286
|
setLayoutTreeId((prev) => prev + 1);
|
|
258
287
|
},
|
|
259
288
|
getRef: () => {
|
|
260
|
-
|
|
289
|
+
if (recyclerViewManager.isDisposed) {
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
return handlerMethods;
|
|
261
293
|
},
|
|
262
294
|
getScrollViewRef: () => {
|
|
263
|
-
return scrollViewRef;
|
|
295
|
+
return scrollViewRef.current;
|
|
264
296
|
},
|
|
265
297
|
markChildLayoutAsPending: (id: string) => {
|
|
266
298
|
pendingChildIds.add(id);
|
|
@@ -272,7 +304,7 @@ const RecyclerViewComponent = <T,>(
|
|
|
272
304
|
}
|
|
273
305
|
},
|
|
274
306
|
};
|
|
275
|
-
}, [setLayoutTreeId]);
|
|
307
|
+
}, [handlerMethods, pendingChildIds, recyclerViewManager, setLayoutTreeId]);
|
|
276
308
|
|
|
277
309
|
const parentRecyclerViewContext = useRecyclerViewContext();
|
|
278
310
|
const recyclerViewId = useId();
|
|
@@ -307,7 +339,7 @@ const RecyclerViewComponent = <T,>(
|
|
|
307
339
|
recyclerViewContext.layout();
|
|
308
340
|
}
|
|
309
341
|
},
|
|
310
|
-
[recyclerViewManager]
|
|
342
|
+
[recyclerViewContext, recyclerViewManager]
|
|
311
343
|
);
|
|
312
344
|
|
|
313
345
|
// Get secondary props and components
|
|
@@ -347,7 +379,14 @@ const RecyclerViewComponent = <T,>(
|
|
|
347
379
|
);
|
|
348
380
|
}
|
|
349
381
|
return null;
|
|
350
|
-
}, [
|
|
382
|
+
}, [
|
|
383
|
+
data,
|
|
384
|
+
stickyHeaderIndices,
|
|
385
|
+
renderItem,
|
|
386
|
+
scrollY,
|
|
387
|
+
recyclerViewManager,
|
|
388
|
+
extraData,
|
|
389
|
+
]);
|
|
351
390
|
|
|
352
391
|
// Set up scroll event handling with animation support for sticky headers
|
|
353
392
|
const animatedEvent = useMemo(() => {
|
|
@@ -358,7 +397,7 @@ const RecyclerViewComponent = <T,>(
|
|
|
358
397
|
);
|
|
359
398
|
}
|
|
360
399
|
return onScrollHandler;
|
|
361
|
-
}, [onScrollHandler, stickyHeaders]);
|
|
400
|
+
}, [onScrollHandler, scrollY, stickyHeaders]);
|
|
362
401
|
|
|
363
402
|
const maintainVisibleContentPositionInternal = useMemo(() => {
|
|
364
403
|
if (maintainVisibleContentPosition?.disabled || horizontal) {
|
|
@@ -369,7 +408,7 @@ const RecyclerViewComponent = <T,>(
|
|
|
369
408
|
minIndexForVisible: 0,
|
|
370
409
|
};
|
|
371
410
|
}
|
|
372
|
-
}, [maintainVisibleContentPosition]);
|
|
411
|
+
}, [horizontal, maintainVisibleContentPosition]);
|
|
373
412
|
|
|
374
413
|
const shouldRenderFromBottom =
|
|
375
414
|
maintainVisibleContentPositionInternal?.startRenderingFromBottom ?? false;
|
|
@@ -393,18 +432,22 @@ const RecyclerViewComponent = <T,>(
|
|
|
393
432
|
width: horizontal ? 0 : undefined,
|
|
394
433
|
minHeight: shouldRenderFromBottom ? adjustmentMinHeight : undefined,
|
|
395
434
|
}}
|
|
396
|
-
ref={
|
|
435
|
+
ref={firstChildViewRef}
|
|
397
436
|
/>
|
|
398
437
|
);
|
|
399
438
|
}, [horizontal, shouldRenderFromBottom, adjustmentMinHeight]);
|
|
400
439
|
|
|
401
|
-
//console.log("render");
|
|
440
|
+
// console.log("render", recyclerViewManager.getRenderStack());
|
|
402
441
|
|
|
403
442
|
// Render the main RecyclerView structure
|
|
404
443
|
return (
|
|
405
444
|
<RecyclerViewContextProvider value={recyclerViewContext}>
|
|
406
445
|
<CompatView
|
|
407
|
-
style={{
|
|
446
|
+
style={{
|
|
447
|
+
flex: horizontal ? undefined : 1,
|
|
448
|
+
overflow: "hidden",
|
|
449
|
+
...style,
|
|
450
|
+
}}
|
|
408
451
|
ref={internalViewRef}
|
|
409
452
|
collapsable={false}
|
|
410
453
|
onLayout={(event) => {
|
|
@@ -433,7 +476,6 @@ const RecyclerViewComponent = <T,>(
|
|
|
433
476
|
horizontal={horizontal}
|
|
434
477
|
ref={scrollViewRef}
|
|
435
478
|
onScroll={animatedEvent}
|
|
436
|
-
// TODO: evaluate perf
|
|
437
479
|
maintainVisibleContentPosition={
|
|
438
480
|
maintainVisibleContentPositionInternal
|
|
439
481
|
}
|
|
@@ -444,8 +486,9 @@ const RecyclerViewComponent = <T,>(
|
|
|
444
486
|
{maintainVisibleContentPositionInternal && (
|
|
445
487
|
<ScrollAnchor scrollAnchorRef={scrollAnchorRef} />
|
|
446
488
|
)}
|
|
489
|
+
{isHorizontalRTL && viewToMeasureBoundedSize}
|
|
447
490
|
{renderHeader}
|
|
448
|
-
{viewToMeasureBoundedSize}
|
|
491
|
+
{!isHorizontalRTL && viewToMeasureBoundedSize}
|
|
449
492
|
{/* Main list content */}
|
|
450
493
|
<ViewHolderCollection
|
|
451
494
|
viewHolderCollectionRef={viewHolderCollectionRef}
|
|
@@ -465,10 +508,14 @@ const RecyclerViewComponent = <T,>(
|
|
|
465
508
|
onCommitLayoutEffect?.();
|
|
466
509
|
}}
|
|
467
510
|
onCommitEffect={() => {
|
|
511
|
+
renderTimeTracker.markRenderComplete();
|
|
512
|
+
recyclerViewManager.updateAverageRenderTime(
|
|
513
|
+
renderTimeTracker.getAverageRenderTime()
|
|
514
|
+
);
|
|
468
515
|
applyInitialScrollIndex();
|
|
469
516
|
checkBounds();
|
|
470
517
|
recyclerViewManager.computeItemViewability();
|
|
471
|
-
recyclerViewManager.disableRecycling
|
|
518
|
+
recyclerViewManager.disableRecycling(false);
|
|
472
519
|
}}
|
|
473
520
|
CellRendererComponent={CellRendererComponent}
|
|
474
521
|
ItemSeparatorComponent={ItemSeparatorComponent}
|
|
@@ -487,9 +534,12 @@ const RecyclerViewComponent = <T,>(
|
|
|
487
534
|
);
|
|
488
535
|
};
|
|
489
536
|
|
|
537
|
+
// Set displayName for the inner component
|
|
538
|
+
RecyclerViewComponent.displayName = "FlashList";
|
|
539
|
+
|
|
490
540
|
// Type definition for the RecyclerView component
|
|
491
541
|
type RecyclerViewType = <T>(
|
|
492
|
-
props: RecyclerViewProps<T> & { ref?: React.Ref<
|
|
542
|
+
props: RecyclerViewProps<T> & { ref?: React.Ref<FlashListRef<T>> }
|
|
493
543
|
) => React.JSX.Element;
|
|
494
544
|
|
|
495
545
|
// Create and export the memoized, forwarded ref component
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import { createContext, useContext } from "react";
|
|
2
|
+
|
|
3
|
+
import { FlashListRef } from "../FlashListRef";
|
|
4
|
+
|
|
2
5
|
import { CompatScroller } from "./components/CompatScroller";
|
|
3
6
|
|
|
4
|
-
export interface RecyclerViewContext {
|
|
7
|
+
export interface RecyclerViewContext<T> {
|
|
5
8
|
layout: () => void;
|
|
6
|
-
getRef: () =>
|
|
7
|
-
getScrollViewRef: () =>
|
|
9
|
+
getRef: () => FlashListRef<T> | null;
|
|
10
|
+
getScrollViewRef: () => CompatScroller | null;
|
|
8
11
|
markChildLayoutAsPending: (id: string) => void;
|
|
9
12
|
unmarkChildLayoutAsPending: (id: string) => void;
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
const RecyclerViewContextInstance = createContext<
|
|
13
|
-
RecyclerViewContext | undefined
|
|
16
|
+
RecyclerViewContext<unknown> | undefined
|
|
14
17
|
>(undefined);
|
|
15
18
|
|
|
16
19
|
export const RecyclerViewContextProvider = RecyclerViewContextInstance.Provider;
|
|
17
|
-
export function useRecyclerViewContext()
|
|
18
|
-
|
|
20
|
+
export function useRecyclerViewContext<T>():
|
|
21
|
+
| RecyclerViewContext<T>
|
|
22
|
+
| undefined {
|
|
23
|
+
return useContext(RecyclerViewContextInstance) as
|
|
24
|
+
| RecyclerViewContext<T>
|
|
25
|
+
| undefined;
|
|
19
26
|
}
|