@shopify/flash-list 2.0.3 → 2.1.0
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/dist/AnimatedFlashList.js +4 -6
- package/dist/AnimatedFlashList.js.map +1 -1
- package/dist/FlashList.js +1 -5
- package/dist/FlashList.js.map +1 -1
- package/dist/FlashListProps.d.ts +9 -1
- package/dist/FlashListProps.d.ts.map +1 -1
- package/dist/FlashListProps.js +1 -4
- package/dist/FlashListProps.js.map +1 -1
- package/dist/FlashListRef.js +1 -2
- package/dist/benchmark/AutoScrollHelper.js +22 -30
- package/dist/benchmark/AutoScrollHelper.js.map +1 -1
- package/dist/benchmark/JSFPSMonitor.js +27 -33
- package/dist/benchmark/JSFPSMonitor.js.map +1 -1
- package/dist/benchmark/roundToDecimalPlaces.js +2 -5
- package/dist/benchmark/roundToDecimalPlaces.js.map +1 -1
- package/dist/benchmark/useBenchmark.d.ts +9 -1
- package/dist/benchmark/useBenchmark.d.ts.map +1 -1
- package/dist/benchmark/useBenchmark.js +86 -95
- package/dist/benchmark/useBenchmark.js.map +1 -1
- package/dist/benchmark/useDataMultiplier.js +6 -10
- package/dist/benchmark/useDataMultiplier.js.map +1 -1
- package/dist/benchmark/useFlatListBenchmark.d.ts +4 -1
- package/dist/benchmark/useFlatListBenchmark.d.ts.map +1 -1
- package/dist/benchmark/useFlatListBenchmark.js +73 -81
- package/dist/benchmark/useFlatListBenchmark.js.map +1 -1
- package/dist/errors/ErrorMessages.js +1 -4
- package/dist/errors/ErrorMessages.js.map +1 -1
- package/dist/errors/WarningMessages.d.ts +1 -0
- package/dist/errors/WarningMessages.d.ts.map +1 -1
- package/dist/errors/WarningMessages.js +2 -4
- package/dist/errors/WarningMessages.js.map +1 -1
- package/dist/index.js +17 -35
- package/dist/index.js.map +1 -1
- package/dist/isNewArch.js +6 -9
- package/dist/isNewArch.js.map +1 -1
- package/dist/native/config/PlatformHelper.android.js +2 -5
- package/dist/native/config/PlatformHelper.android.js.map +1 -1
- package/dist/native/config/PlatformHelper.ios.js +2 -5
- package/dist/native/config/PlatformHelper.ios.js.map +1 -1
- package/dist/native/config/PlatformHelper.js +2 -5
- package/dist/native/config/PlatformHelper.js.map +1 -1
- package/dist/native/config/PlatformHelper.web.js +2 -5
- package/dist/native/config/PlatformHelper.web.js.map +1 -1
- package/dist/recyclerview/LayoutCommitObserver.js +20 -24
- package/dist/recyclerview/LayoutCommitObserver.js.map +1 -1
- package/dist/recyclerview/RecyclerView.d.ts.map +1 -1
- package/dist/recyclerview/RecyclerView.js +117 -107
- package/dist/recyclerview/RecyclerView.js.map +1 -1
- package/dist/recyclerview/RecyclerViewContextProvider.js +7 -12
- package/dist/recyclerview/RecyclerViewContextProvider.js.map +1 -1
- package/dist/recyclerview/RecyclerViewManager.d.ts +2 -0
- package/dist/recyclerview/RecyclerViewManager.d.ts.map +1 -1
- package/dist/recyclerview/RecyclerViewManager.js +146 -164
- package/dist/recyclerview/RecyclerViewManager.js.map +1 -1
- package/dist/recyclerview/RecyclerViewProps.js +1 -2
- package/dist/recyclerview/RenderStackManager.js +97 -188
- package/dist/recyclerview/RenderStackManager.js.map +1 -1
- package/dist/recyclerview/ViewHolder.js +16 -20
- package/dist/recyclerview/ViewHolder.js.map +1 -1
- package/dist/recyclerview/ViewHolderCollection.js +26 -30
- package/dist/recyclerview/ViewHolderCollection.js.map +1 -1
- package/dist/recyclerview/components/CompatScroller.js +6 -7
- package/dist/recyclerview/components/CompatScroller.js.map +1 -1
- package/dist/recyclerview/components/CompatView.js +6 -7
- package/dist/recyclerview/components/CompatView.js.map +1 -1
- package/dist/recyclerview/components/ScrollAnchor.js +10 -15
- package/dist/recyclerview/components/ScrollAnchor.js.map +1 -1
- package/dist/recyclerview/components/StickyHeaders.js +34 -40
- package/dist/recyclerview/components/StickyHeaders.js.map +1 -1
- package/dist/recyclerview/helpers/ConsecutiveNumbers.js +39 -66
- package/dist/recyclerview/helpers/ConsecutiveNumbers.js.map +1 -1
- package/dist/recyclerview/helpers/EngagedIndicesTracker.js +57 -63
- package/dist/recyclerview/helpers/EngagedIndicesTracker.js.map +1 -1
- package/dist/recyclerview/helpers/RenderTimeTracker.js +19 -24
- package/dist/recyclerview/helpers/RenderTimeTracker.js.map +1 -1
- package/dist/recyclerview/helpers/VelocityTracker.js +16 -22
- package/dist/recyclerview/helpers/VelocityTracker.js.map +1 -1
- package/dist/recyclerview/hooks/useBoundDetection.js +37 -40
- package/dist/recyclerview/hooks/useBoundDetection.js.map +1 -1
- package/dist/recyclerview/hooks/useLayoutState.js +9 -15
- package/dist/recyclerview/hooks/useLayoutState.js.map +1 -1
- package/dist/recyclerview/hooks/useMappingHelper.js +6 -10
- package/dist/recyclerview/hooks/useMappingHelper.js.map +1 -1
- package/dist/recyclerview/hooks/useOnLoad.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useOnLoad.js +17 -22
- package/dist/recyclerview/hooks/useOnLoad.js.map +1 -1
- package/dist/recyclerview/hooks/useRecyclerViewController.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useRecyclerViewController.js +169 -188
- package/dist/recyclerview/hooks/useRecyclerViewController.js.map +1 -1
- package/dist/recyclerview/hooks/useRecyclerViewManager.js +12 -17
- package/dist/recyclerview/hooks/useRecyclerViewManager.js.map +1 -1
- package/dist/recyclerview/hooks/useRecyclingState.js +10 -14
- package/dist/recyclerview/hooks/useRecyclingState.js.map +1 -1
- package/dist/recyclerview/hooks/useSecondaryProps.js +24 -30
- package/dist/recyclerview/hooks/useSecondaryProps.js.map +1 -1
- package/dist/recyclerview/hooks/useUnmountAwareCallbacks.js +17 -22
- package/dist/recyclerview/hooks/useUnmountAwareCallbacks.js.map +1 -1
- package/dist/recyclerview/hooks/useUnmountFlag.js +5 -9
- package/dist/recyclerview/hooks/useUnmountFlag.js.map +1 -1
- package/dist/recyclerview/layout-managers/GridLayoutManager.js +61 -80
- package/dist/recyclerview/layout-managers/GridLayoutManager.js.map +1 -1
- package/dist/recyclerview/layout-managers/LayoutManager.js +83 -123
- package/dist/recyclerview/layout-managers/LayoutManager.js.map +1 -1
- package/dist/recyclerview/layout-managers/LinearLayoutManager.js +51 -91
- package/dist/recyclerview/layout-managers/LinearLayoutManager.js.map +1 -1
- package/dist/recyclerview/layout-managers/MasonryLayoutManager.js +77 -96
- package/dist/recyclerview/layout-managers/MasonryLayoutManager.js.map +1 -1
- package/dist/recyclerview/utils/adjustOffsetForRTL.js +1 -4
- package/dist/recyclerview/utils/adjustOffsetForRTL.js.map +1 -1
- package/dist/recyclerview/utils/componentUtils.js +4 -9
- package/dist/recyclerview/utils/componentUtils.js.map +1 -1
- package/dist/recyclerview/utils/findVisibleIndex.js +9 -13
- package/dist/recyclerview/utils/findVisibleIndex.js.map +1 -1
- package/dist/recyclerview/utils/measureLayout.js +12 -20
- package/dist/recyclerview/utils/measureLayout.js.map +1 -1
- package/dist/recyclerview/utils/measureLayout.web.js +15 -23
- package/dist/recyclerview/utils/measureLayout.web.js.map +1 -1
- package/dist/recyclerview/viewability/ViewToken.js +1 -2
- package/dist/recyclerview/viewability/ViewabilityHelper.js +34 -41
- package/dist/recyclerview/viewability/ViewabilityHelper.js.map +1 -1
- package/dist/recyclerview/viewability/ViewabilityManager.js +48 -61
- package/dist/recyclerview/viewability/ViewabilityManager.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/AverageWindow.js +28 -39
- package/dist/utils/AverageWindow.js.map +1 -1
- package/package.json +4 -6
- package/src/FlashListProps.ts +8 -1
- package/src/benchmark/useBenchmark.ts +47 -4
- package/src/benchmark/useFlatListBenchmark.ts +38 -5
- package/src/errors/WarningMessages.ts +2 -0
- package/src/recyclerview/RecyclerView.tsx +18 -5
- package/src/recyclerview/RecyclerViewManager.ts +12 -0
- package/src/recyclerview/hooks/useOnLoad.ts +1 -0
- package/src/recyclerview/hooks/useRecyclerViewController.tsx +7 -4
- package/dist/__tests__/AverageWindow.test.d.ts +0 -2
- package/dist/__tests__/AverageWindow.test.d.ts.map +0 -1
- package/dist/__tests__/AverageWindow.test.js +0 -104
- package/dist/__tests__/AverageWindow.test.js.map +0 -1
- package/dist/__tests__/ConsecutiveNumbers.test.d.ts +0 -2
- package/dist/__tests__/ConsecutiveNumbers.test.d.ts.map +0 -1
- package/dist/__tests__/ConsecutiveNumbers.test.js +0 -224
- package/dist/__tests__/ConsecutiveNumbers.test.js.map +0 -1
- package/dist/__tests__/GridLayoutManager.test.d.ts +0 -2
- package/dist/__tests__/GridLayoutManager.test.d.ts.map +0 -1
- package/dist/__tests__/GridLayoutManager.test.js +0 -69
- package/dist/__tests__/GridLayoutManager.test.js.map +0 -1
- package/dist/__tests__/LayoutCommitObserver.test.d.ts +0 -2
- package/dist/__tests__/LayoutCommitObserver.test.d.ts.map +0 -1
- package/dist/__tests__/LayoutCommitObserver.test.js +0 -37
- package/dist/__tests__/LayoutCommitObserver.test.js.map +0 -1
- package/dist/__tests__/LinearLayoutManager.test.d.ts +0 -2
- package/dist/__tests__/LinearLayoutManager.test.d.ts.map +0 -1
- package/dist/__tests__/LinearLayoutManager.test.js +0 -140
- package/dist/__tests__/LinearLayoutManager.test.js.map +0 -1
- package/dist/__tests__/MasonryLayoutManager.test.d.ts +0 -2
- package/dist/__tests__/MasonryLayoutManager.test.d.ts.map +0 -1
- package/dist/__tests__/MasonryLayoutManager.test.js +0 -148
- package/dist/__tests__/MasonryLayoutManager.test.js.map +0 -1
- package/dist/__tests__/RecyclerView.test.d.ts +0 -2
- package/dist/__tests__/RecyclerView.test.d.ts.map +0 -1
- package/dist/__tests__/RecyclerView.test.js +0 -103
- package/dist/__tests__/RecyclerView.test.js.map +0 -1
- package/dist/__tests__/RenderStackManager.test.d.ts +0 -2
- package/dist/__tests__/RenderStackManager.test.d.ts.map +0 -1
- package/dist/__tests__/RenderStackManager.test.js +0 -485
- package/dist/__tests__/RenderStackManager.test.js.map +0 -1
- package/dist/__tests__/ViewabilityHelper.test.d.ts +0 -2
- package/dist/__tests__/ViewabilityHelper.test.d.ts.map +0 -1
- package/dist/__tests__/ViewabilityHelper.test.js +0 -186
- package/dist/__tests__/ViewabilityHelper.test.js.map +0 -1
- package/dist/__tests__/findVisibleIndex.test.d.ts +0 -2
- package/dist/__tests__/findVisibleIndex.test.d.ts.map +0 -1
- package/dist/__tests__/findVisibleIndex.test.js +0 -259
- package/dist/__tests__/findVisibleIndex.test.js.map +0 -1
- package/dist/__tests__/helpers/createLayoutManager.d.ts +0 -34
- package/dist/__tests__/helpers/createLayoutManager.d.ts.map +0 -1
- package/dist/__tests__/helpers/createLayoutManager.js +0 -110
- package/dist/__tests__/helpers/createLayoutManager.js.map +0 -1
- package/dist/__tests__/useUnmountAwareCallbacks.test.d.ts +0 -2
- package/dist/__tests__/useUnmountAwareCallbacks.test.d.ts.map +0 -1
- package/dist/__tests__/useUnmountAwareCallbacks.test.js +0 -185
- package/dist/__tests__/useUnmountAwareCallbacks.test.js.map +0 -1
- package/src/__tests__/AverageWindow.test.ts +0 -128
- package/src/__tests__/ConsecutiveNumbers.test.ts +0 -232
- package/src/__tests__/GridLayoutManager.test.ts +0 -113
- package/src/__tests__/LayoutCommitObserver.test.tsx +0 -63
- package/src/__tests__/LinearLayoutManager.test.ts +0 -227
- package/src/__tests__/MasonryLayoutManager.test.ts +0 -202
- package/src/__tests__/RecyclerView.test.tsx +0 -144
- package/src/__tests__/RenderStackManager.test.ts +0 -574
- package/src/__tests__/ViewabilityHelper.test.ts +0 -282
- package/src/__tests__/findVisibleIndex.test.ts +0 -369
- package/src/__tests__/helpers/createLayoutManager.ts +0 -141
- package/src/__tests__/useUnmountAwareCallbacks.test.tsx +0 -285
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var PlatformHelper_1 = require("../../native/config/PlatformHelper");
|
|
9
|
-
var WarningMessages_1 = require("../../errors/WarningMessages");
|
|
10
|
-
var useUnmountFlag_1 = require("./useUnmountFlag");
|
|
11
|
-
var useUnmountAwareCallbacks_1 = require("./useUnmountAwareCallbacks");
|
|
1
|
+
import { useCallback, useImperativeHandle, useMemo, useRef, useState, } from "react";
|
|
2
|
+
import { I18nManager } from "react-native";
|
|
3
|
+
import { adjustOffsetForRTL } from "../utils/adjustOffsetForRTL";
|
|
4
|
+
import { PlatformConfig } from "../../native/config/PlatformHelper";
|
|
5
|
+
import { WarningMessages } from "../../errors/WarningMessages";
|
|
6
|
+
import { useUnmountFlag } from "./useUnmountFlag";
|
|
7
|
+
import { useUnmountAwareTimeout } from "./useUnmountAwareCallbacks";
|
|
12
8
|
/**
|
|
13
9
|
* Comprehensive hook that manages RecyclerView scrolling behavior and provides
|
|
14
10
|
* imperative methods for controlling the RecyclerView.
|
|
@@ -25,19 +21,18 @@ var useUnmountAwareCallbacks_1 = require("./useUnmountAwareCallbacks");
|
|
|
25
21
|
* @param scrollAnchorRef - Reference to the scroll anchor component
|
|
26
22
|
* @param props - The RecyclerViewProps containing configuration
|
|
27
23
|
*/
|
|
28
|
-
function useRecyclerViewController(recyclerViewManager, ref, scrollViewRef, scrollAnchorRef) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
var setTimeout = (0, useUnmountAwareCallbacks_1.useUnmountAwareTimeout)().setTimeout;
|
|
24
|
+
export function useRecyclerViewController(recyclerViewManager, ref, scrollViewRef, scrollAnchorRef) {
|
|
25
|
+
const isUnmounted = useUnmountFlag();
|
|
26
|
+
const [_, setRenderId] = useState(0);
|
|
27
|
+
const pauseOffsetCorrection = useRef(false);
|
|
28
|
+
const initialScrollCompletedRef = useRef(false);
|
|
29
|
+
const lastDataLengthRef = useRef(recyclerViewManager.getDataLength());
|
|
30
|
+
const { setTimeout } = useUnmountAwareTimeout();
|
|
36
31
|
// Track the first visible item for maintaining scroll position
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
const firstVisibleItemKey = useRef(undefined);
|
|
33
|
+
const firstVisibleItemLayout = useRef(undefined);
|
|
39
34
|
// Queue to store callbacks that should be executed after scroll offset updates
|
|
40
|
-
|
|
35
|
+
const pendingScrollCallbacks = useRef([]);
|
|
41
36
|
// Handle initial scroll position when the list first loads
|
|
42
37
|
// useOnLoad(recyclerViewManager, () => {
|
|
43
38
|
// });
|
|
@@ -48,31 +43,33 @@ function useRecyclerViewController(recyclerViewManager, ref, scrollViewRef, scro
|
|
|
48
43
|
* @param offset - The new scroll offset to apply
|
|
49
44
|
* @param callback - Optional callback to execute after the update is applied
|
|
50
45
|
*/
|
|
51
|
-
|
|
46
|
+
const updateScrollOffsetWithCallback = useCallback((offset, callback) => {
|
|
52
47
|
// Attempt to update the scroll offset in the RecyclerViewManager
|
|
53
48
|
// This returns undefined if no update is needed
|
|
54
49
|
if (recyclerViewManager.updateScrollOffset(offset) !== undefined) {
|
|
55
50
|
// It will be executed after the next render
|
|
56
51
|
pendingScrollCallbacks.current.push(callback);
|
|
57
52
|
// Trigger a re-render to apply the scroll offset update
|
|
58
|
-
setRenderId(
|
|
53
|
+
setRenderId((prev) => prev + 1);
|
|
59
54
|
}
|
|
60
55
|
else {
|
|
61
56
|
// No update needed, execute callback immediately
|
|
62
57
|
callback();
|
|
63
58
|
}
|
|
64
59
|
}, [recyclerViewManager]);
|
|
65
|
-
|
|
60
|
+
const computeFirstVisibleIndexForOffsetCorrection = useCallback(() => {
|
|
66
61
|
if (recyclerViewManager.getIsFirstLayoutComplete() &&
|
|
67
62
|
recyclerViewManager.hasStableDataKeys() &&
|
|
68
63
|
recyclerViewManager.getDataLength() > 0 &&
|
|
69
64
|
recyclerViewManager.shouldMaintainVisibleContentPosition()) {
|
|
70
65
|
// Update the tracked first visible item
|
|
71
|
-
|
|
66
|
+
const firstVisibleIndex = Math.max(0, recyclerViewManager.computeVisibleIndices().startIndex);
|
|
72
67
|
if (firstVisibleIndex !== undefined && firstVisibleIndex >= 0) {
|
|
73
68
|
firstVisibleItemKey.current =
|
|
74
69
|
recyclerViewManager.getDataKey(firstVisibleIndex);
|
|
75
|
-
firstVisibleItemLayout.current =
|
|
70
|
+
firstVisibleItemLayout.current = {
|
|
71
|
+
...recyclerViewManager.getLayout(firstVisibleIndex),
|
|
72
|
+
};
|
|
76
73
|
}
|
|
77
74
|
}
|
|
78
75
|
}, [recyclerViewManager]);
|
|
@@ -81,52 +78,50 @@ function useRecyclerViewController(recyclerViewManager, ref, scrollViewRef, scro
|
|
|
81
78
|
* This is particularly useful for chat applications where we want to keep
|
|
82
79
|
* the user's current view position when new messages are added.
|
|
83
80
|
*/
|
|
84
|
-
|
|
81
|
+
const applyOffsetCorrection = useCallback(() => {
|
|
85
82
|
var _a, _b, _c;
|
|
86
|
-
|
|
83
|
+
const { horizontal, data } = recyclerViewManager.props;
|
|
87
84
|
// Execute all pending callbacks from previous scroll offset updates
|
|
88
85
|
// This ensures any scroll operations that were waiting for render are completed
|
|
89
|
-
|
|
86
|
+
const callbacks = pendingScrollCallbacks.current;
|
|
90
87
|
pendingScrollCallbacks.current = [];
|
|
91
|
-
callbacks.forEach(
|
|
92
|
-
|
|
88
|
+
callbacks.forEach((callback) => callback());
|
|
89
|
+
const currentDataLength = recyclerViewManager.getDataLength();
|
|
93
90
|
if (recyclerViewManager.getIsFirstLayoutComplete() &&
|
|
94
91
|
recyclerViewManager.hasStableDataKeys() &&
|
|
95
92
|
currentDataLength > 0 &&
|
|
96
93
|
recyclerViewManager.shouldMaintainVisibleContentPosition()) {
|
|
97
|
-
|
|
94
|
+
const hasDataChanged = currentDataLength !== lastDataLengthRef.current;
|
|
98
95
|
// If we have a tracked first visible item, maintain its position
|
|
99
96
|
if (firstVisibleItemKey.current) {
|
|
100
|
-
|
|
97
|
+
const currentIndexOfFirstVisibleItem = (_a = recyclerViewManager
|
|
101
98
|
.getEngagedIndices()
|
|
102
|
-
.findValue(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
? data === null || data === void 0 ? void 0 : data.findIndex(function (item, index) {
|
|
107
|
-
return recyclerViewManager.getDataKey(index) ===
|
|
108
|
-
firstVisibleItemKey.current;
|
|
109
|
-
})
|
|
99
|
+
.findValue((index) => recyclerViewManager.getDataKey(index) ===
|
|
100
|
+
firstVisibleItemKey.current)) !== null && _a !== void 0 ? _a : (hasDataChanged
|
|
101
|
+
? data === null || data === void 0 ? void 0 : data.findIndex((item, index) => recyclerViewManager.getDataKey(index) ===
|
|
102
|
+
firstVisibleItemKey.current)
|
|
110
103
|
: undefined);
|
|
111
104
|
if (currentIndexOfFirstVisibleItem !== undefined &&
|
|
112
105
|
currentIndexOfFirstVisibleItem >= 0) {
|
|
113
106
|
// Calculate the difference in position and apply the offset
|
|
114
|
-
|
|
107
|
+
const diff = horizontal
|
|
115
108
|
? recyclerViewManager.getLayout(currentIndexOfFirstVisibleItem).x -
|
|
116
109
|
firstVisibleItemLayout.current.x
|
|
117
110
|
: recyclerViewManager.getLayout(currentIndexOfFirstVisibleItem).y -
|
|
118
111
|
firstVisibleItemLayout.current.y;
|
|
119
|
-
firstVisibleItemLayout.current =
|
|
112
|
+
firstVisibleItemLayout.current = {
|
|
113
|
+
...recyclerViewManager.getLayout(currentIndexOfFirstVisibleItem),
|
|
114
|
+
};
|
|
120
115
|
if (diff !== 0 &&
|
|
121
116
|
!pauseOffsetCorrection.current &&
|
|
122
117
|
!recyclerViewManager.animationOptimizationsEnabled) {
|
|
123
118
|
// console.log("diff", diff, firstVisibleItemKey.current);
|
|
124
|
-
if (
|
|
119
|
+
if (PlatformConfig.supportsOffsetCorrection) {
|
|
125
120
|
// console.log("scrollBy", diff);
|
|
126
121
|
(_b = scrollAnchorRef.current) === null || _b === void 0 ? void 0 : _b.scrollBy(diff);
|
|
127
122
|
}
|
|
128
123
|
else {
|
|
129
|
-
|
|
124
|
+
const scrollToParams = horizontal
|
|
130
125
|
? {
|
|
131
126
|
x: recyclerViewManager.getAbsoluteLastScrollOffset() + diff,
|
|
132
127
|
animated: false,
|
|
@@ -138,9 +133,9 @@ function useRecyclerViewController(recyclerViewManager, ref, scrollViewRef, scro
|
|
|
138
133
|
(_c = scrollViewRef.current) === null || _c === void 0 ? void 0 : _c.scrollTo(scrollToParams);
|
|
139
134
|
}
|
|
140
135
|
if (hasDataChanged) {
|
|
141
|
-
updateScrollOffsetWithCallback(recyclerViewManager.getAbsoluteLastScrollOffset() + diff,
|
|
136
|
+
updateScrollOffsetWithCallback(recyclerViewManager.getAbsoluteLastScrollOffset() + diff, () => { });
|
|
142
137
|
recyclerViewManager.ignoreScrollEvents = true;
|
|
143
|
-
setTimeout(
|
|
138
|
+
setTimeout(() => {
|
|
144
139
|
recyclerViewManager.ignoreScrollEvents = false;
|
|
145
140
|
}, 100);
|
|
146
141
|
}
|
|
@@ -158,7 +153,7 @@ function useRecyclerViewController(recyclerViewManager, ref, scrollViewRef, scro
|
|
|
158
153
|
updateScrollOffsetWithCallback,
|
|
159
154
|
computeFirstVisibleIndexForOffsetCorrection,
|
|
160
155
|
]);
|
|
161
|
-
|
|
156
|
+
const handlerMethods = useMemo(() => {
|
|
162
157
|
return {
|
|
163
158
|
get props() {
|
|
164
159
|
return recyclerViewManager.props;
|
|
@@ -167,86 +162,72 @@ function useRecyclerViewController(recyclerViewManager, ref, scrollViewRef, scro
|
|
|
167
162
|
* Scrolls the list to a specific offset position.
|
|
168
163
|
* Handles RTL layouts and first item offset adjustments.
|
|
169
164
|
*/
|
|
170
|
-
scrollToOffset:
|
|
171
|
-
|
|
172
|
-
var horizontal = recyclerViewManager.props.horizontal;
|
|
165
|
+
scrollToOffset: ({ offset, animated, skipFirstItemOffset = true, }) => {
|
|
166
|
+
const { horizontal } = recyclerViewManager.props;
|
|
173
167
|
if (scrollViewRef.current) {
|
|
174
168
|
// Adjust offset for RTL layouts in horizontal mode
|
|
175
|
-
if (
|
|
169
|
+
if (I18nManager.isRTL && horizontal) {
|
|
176
170
|
// eslint-disable-next-line no-param-reassign
|
|
177
171
|
offset =
|
|
178
|
-
|
|
172
|
+
adjustOffsetForRTL(offset, recyclerViewManager.getChildContainerDimensions().width, recyclerViewManager.getWindowSize().width) +
|
|
179
173
|
(skipFirstItemOffset
|
|
180
174
|
? recyclerViewManager.firstItemOffset
|
|
181
175
|
: -recyclerViewManager.firstItemOffset);
|
|
182
176
|
}
|
|
183
177
|
// Calculate the final offset including first item offset if needed
|
|
184
|
-
|
|
178
|
+
const adjustedOffset = offset +
|
|
185
179
|
(skipFirstItemOffset ? 0 : recyclerViewManager.firstItemOffset);
|
|
186
|
-
|
|
180
|
+
const scrollTo = horizontal
|
|
187
181
|
? { x: adjustedOffset, y: 0 }
|
|
188
182
|
: { x: 0, y: adjustedOffset };
|
|
189
|
-
scrollViewRef.current.scrollTo(
|
|
183
|
+
scrollViewRef.current.scrollTo({
|
|
184
|
+
...scrollTo,
|
|
185
|
+
animated,
|
|
186
|
+
});
|
|
190
187
|
}
|
|
191
188
|
},
|
|
192
|
-
clearLayoutCacheOnUpdate:
|
|
189
|
+
clearLayoutCacheOnUpdate: () => {
|
|
193
190
|
recyclerViewManager.markLayoutManagerDirty();
|
|
194
191
|
},
|
|
195
192
|
// Expose native scroll view methods
|
|
196
|
-
flashScrollIndicators:
|
|
193
|
+
flashScrollIndicators: () => {
|
|
197
194
|
scrollViewRef.current.flashScrollIndicators();
|
|
198
195
|
},
|
|
199
|
-
getNativeScrollRef:
|
|
196
|
+
getNativeScrollRef: () => {
|
|
200
197
|
return scrollViewRef.current;
|
|
201
198
|
},
|
|
202
|
-
getScrollResponder:
|
|
199
|
+
getScrollResponder: () => {
|
|
203
200
|
return scrollViewRef.current.getScrollResponder();
|
|
204
201
|
},
|
|
205
|
-
getScrollableNode:
|
|
202
|
+
getScrollableNode: () => {
|
|
206
203
|
return scrollViewRef.current.getScrollableNode();
|
|
207
204
|
},
|
|
208
205
|
/**
|
|
209
206
|
* Scrolls to the end of the list.
|
|
210
207
|
*/
|
|
211
|
-
scrollToEnd:
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
208
|
+
scrollToEnd: async ({ animated } = {}) => {
|
|
209
|
+
const { data } = recyclerViewManager.props;
|
|
210
|
+
if (data && data.length > 0) {
|
|
211
|
+
const lastIndex = data.length - 1;
|
|
212
|
+
if (!recyclerViewManager.getEngagedIndices().includes(lastIndex)) {
|
|
213
|
+
await handlerMethods.scrollToIndex({
|
|
214
|
+
index: lastIndex,
|
|
215
|
+
animated,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
215
218
|
}
|
|
216
|
-
|
|
217
|
-
var
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
switch (_c.label) {
|
|
221
|
-
case 0:
|
|
222
|
-
data = recyclerViewManager.props.data;
|
|
223
|
-
if (!(data && data.length > 0)) return [3 /*break*/, 2];
|
|
224
|
-
lastIndex = data.length - 1;
|
|
225
|
-
if (!!recyclerViewManager.getEngagedIndices().includes(lastIndex)) return [3 /*break*/, 2];
|
|
226
|
-
return [4 /*yield*/, handlerMethods.scrollToIndex({
|
|
227
|
-
index: lastIndex,
|
|
228
|
-
animated: animated,
|
|
229
|
-
})];
|
|
230
|
-
case 1:
|
|
231
|
-
_c.sent();
|
|
232
|
-
_c.label = 2;
|
|
233
|
-
case 2:
|
|
234
|
-
setTimeout(function () {
|
|
235
|
-
scrollViewRef.current.scrollToEnd({ animated: animated });
|
|
236
|
-
}, 0);
|
|
237
|
-
return [2 /*return*/];
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
});
|
|
219
|
+
setTimeout(() => {
|
|
220
|
+
var _a;
|
|
221
|
+
(_a = scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollToEnd({ animated });
|
|
222
|
+
}, 0);
|
|
241
223
|
},
|
|
242
224
|
/**
|
|
243
225
|
* Scrolls to the beginning of the list.
|
|
244
226
|
*/
|
|
245
|
-
scrollToTop:
|
|
246
|
-
var _b = _a === void 0 ? {} : _a, animated = _b.animated;
|
|
227
|
+
scrollToTop: ({ animated } = {}) => {
|
|
247
228
|
handlerMethods.scrollToOffset({
|
|
248
229
|
offset: 0,
|
|
249
|
-
animated
|
|
230
|
+
animated,
|
|
250
231
|
});
|
|
251
232
|
},
|
|
252
233
|
/**
|
|
@@ -254,26 +235,25 @@ function useRecyclerViewController(recyclerViewManager, ref, scrollViewRef, scro
|
|
|
254
235
|
* Supports viewPosition and viewOffset for precise positioning.
|
|
255
236
|
* Returns a Promise that resolves when the scroll is complete.
|
|
256
237
|
*/
|
|
257
|
-
scrollToIndex:
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
var horizontal = recyclerViewManager.props.horizontal;
|
|
238
|
+
scrollToIndex: ({ index, animated, viewPosition, viewOffset, }) => {
|
|
239
|
+
return new Promise((resolve) => {
|
|
240
|
+
const { horizontal } = recyclerViewManager.props;
|
|
261
241
|
if (scrollViewRef.current &&
|
|
262
242
|
index >= 0 &&
|
|
263
243
|
index < recyclerViewManager.getDataLength()) {
|
|
264
244
|
// Pause the scroll offset adjustments
|
|
265
245
|
pauseOffsetCorrection.current = true;
|
|
266
246
|
recyclerViewManager.setOffsetProjectionEnabled(false);
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
247
|
+
const getFinalOffset = () => {
|
|
248
|
+
const layout = recyclerViewManager.getLayout(index);
|
|
249
|
+
const offset = horizontal ? layout.x : layout.y;
|
|
250
|
+
let finalOffset = offset;
|
|
271
251
|
// take viewPosition etc into account
|
|
272
252
|
if (viewPosition !== undefined || viewOffset !== undefined) {
|
|
273
|
-
|
|
253
|
+
const containerSize = horizontal
|
|
274
254
|
? recyclerViewManager.getWindowSize().width
|
|
275
255
|
: recyclerViewManager.getWindowSize().height;
|
|
276
|
-
|
|
256
|
+
const itemSize = horizontal ? layout.width : layout.height;
|
|
277
257
|
if (viewPosition !== undefined) {
|
|
278
258
|
// viewPosition: 0 = top, 0.5 = center, 1 = bottom
|
|
279
259
|
finalOffset =
|
|
@@ -285,81 +265,81 @@ function useRecyclerViewController(recyclerViewManager, ref, scrollViewRef, scro
|
|
|
285
265
|
}
|
|
286
266
|
return finalOffset + recyclerViewManager.firstItemOffset;
|
|
287
267
|
};
|
|
288
|
-
|
|
289
|
-
|
|
268
|
+
const lastAbsoluteScrollOffset = recyclerViewManager.getAbsoluteLastScrollOffset();
|
|
269
|
+
const bufferForScroll = horizontal
|
|
290
270
|
? recyclerViewManager.getWindowSize().width
|
|
291
271
|
: recyclerViewManager.getWindowSize().height;
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
272
|
+
const bufferForCompute = bufferForScroll * 2;
|
|
273
|
+
const getStartScrollOffset = () => {
|
|
274
|
+
let lastScrollOffset = lastAbsoluteScrollOffset;
|
|
275
|
+
const finalOffset = getFinalOffset();
|
|
296
276
|
if (finalOffset > lastScrollOffset) {
|
|
297
|
-
lastScrollOffset = Math.max(finalOffset -
|
|
277
|
+
lastScrollOffset = Math.max(finalOffset - bufferForCompute, lastScrollOffset);
|
|
298
278
|
recyclerViewManager.setScrollDirection("forward");
|
|
299
279
|
}
|
|
300
280
|
else {
|
|
301
|
-
lastScrollOffset = Math.min(finalOffset +
|
|
281
|
+
lastScrollOffset = Math.min(finalOffset + bufferForCompute, lastScrollOffset);
|
|
302
282
|
recyclerViewManager.setScrollDirection("backward");
|
|
303
283
|
}
|
|
304
284
|
return lastScrollOffset;
|
|
305
285
|
};
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
286
|
+
let initialTargetOffset = getFinalOffset();
|
|
287
|
+
let initialStartScrollOffset = getStartScrollOffset();
|
|
288
|
+
let finalOffset = initialTargetOffset;
|
|
289
|
+
let startScrollOffset = initialStartScrollOffset;
|
|
290
|
+
const steps = 5;
|
|
311
291
|
/**
|
|
312
292
|
* Recursively performs the scroll animation steps.
|
|
313
293
|
* This function replaces the async/await loop with callback-based execution.
|
|
314
294
|
*
|
|
315
295
|
* @param currentStep - The current step in the animation (0 to steps-1)
|
|
316
296
|
*/
|
|
317
|
-
|
|
297
|
+
const performScrollStep = (currentStep) => {
|
|
318
298
|
// Check if component is unmounted or we've completed all steps
|
|
319
299
|
if (isUnmounted.current) {
|
|
320
300
|
resolve();
|
|
321
301
|
return;
|
|
322
302
|
}
|
|
323
|
-
else if (currentStep >=
|
|
303
|
+
else if (currentStep >= steps) {
|
|
324
304
|
// All steps completed, perform final scroll
|
|
325
|
-
|
|
305
|
+
finishScrollToIndex();
|
|
326
306
|
return;
|
|
327
307
|
}
|
|
328
308
|
// Calculate the offset for this step
|
|
329
309
|
// For animated scrolls: interpolate from finalOffset to startScrollOffset
|
|
330
310
|
// For non-animated: interpolate from startScrollOffset to finalOffset
|
|
331
|
-
|
|
332
|
-
?
|
|
333
|
-
(
|
|
334
|
-
(currentStep / (
|
|
335
|
-
:
|
|
336
|
-
(
|
|
337
|
-
(currentStep / (
|
|
311
|
+
const nextOffset = animated
|
|
312
|
+
? finalOffset +
|
|
313
|
+
(startScrollOffset - finalOffset) *
|
|
314
|
+
(currentStep / (steps - 1))
|
|
315
|
+
: startScrollOffset +
|
|
316
|
+
(finalOffset - startScrollOffset) *
|
|
317
|
+
(currentStep / (steps - 1));
|
|
338
318
|
// Update scroll offset with a callback to continue to the next step
|
|
339
|
-
updateScrollOffsetWithCallback(nextOffset,
|
|
319
|
+
updateScrollOffsetWithCallback(nextOffset, () => {
|
|
340
320
|
// Check if the index is still valid after the update
|
|
341
321
|
if (index >= recyclerViewManager.getDataLength()) {
|
|
342
322
|
// Index out of bounds, scroll to end instead
|
|
343
|
-
handlerMethods.scrollToEnd({ animated
|
|
323
|
+
handlerMethods.scrollToEnd({ animated });
|
|
344
324
|
resolve(); // Resolve the promise as we're done
|
|
345
325
|
return;
|
|
346
326
|
}
|
|
347
327
|
// Check if the target position has changed significantly
|
|
348
|
-
|
|
349
|
-
if ((newFinalOffset <
|
|
350
|
-
newFinalOffset <
|
|
351
|
-
(newFinalOffset >
|
|
352
|
-
newFinalOffset >
|
|
328
|
+
const newFinalOffset = getFinalOffset();
|
|
329
|
+
if ((newFinalOffset < initialTargetOffset &&
|
|
330
|
+
newFinalOffset < initialStartScrollOffset) ||
|
|
331
|
+
(newFinalOffset > initialTargetOffset &&
|
|
332
|
+
newFinalOffset > initialStartScrollOffset)) {
|
|
353
333
|
// Target has moved, recalculate and restart from beginning
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
334
|
+
finalOffset = newFinalOffset;
|
|
335
|
+
startScrollOffset = getStartScrollOffset();
|
|
336
|
+
initialTargetOffset = newFinalOffset;
|
|
337
|
+
initialStartScrollOffset = startScrollOffset;
|
|
338
|
+
performScrollStep(0); // Restart from step 0
|
|
359
339
|
}
|
|
360
340
|
else {
|
|
361
341
|
// Continue to next step
|
|
362
|
-
|
|
342
|
+
performScrollStep(currentStep + 1);
|
|
363
343
|
}
|
|
364
344
|
});
|
|
365
345
|
};
|
|
@@ -367,37 +347,37 @@ function useRecyclerViewController(recyclerViewManager, ref, scrollViewRef, scro
|
|
|
367
347
|
* Completes the scroll to index operation by performing the final scroll
|
|
368
348
|
* and re-enabling offset correction after a delay.
|
|
369
349
|
*/
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
if (
|
|
374
|
-
|
|
350
|
+
const finishScrollToIndex = () => {
|
|
351
|
+
finalOffset = getFinalOffset();
|
|
352
|
+
const maxOffset = recyclerViewManager.getMaxScrollOffset();
|
|
353
|
+
if (finalOffset > maxOffset) {
|
|
354
|
+
finalOffset = maxOffset;
|
|
375
355
|
}
|
|
376
356
|
if (animated) {
|
|
377
357
|
// For animated scrolls, first jump to the start position
|
|
378
358
|
// We don't need to add firstItemOffset here as it's already added
|
|
379
359
|
handlerMethods.scrollToOffset({
|
|
380
|
-
offset:
|
|
360
|
+
offset: startScrollOffset,
|
|
381
361
|
animated: false,
|
|
382
362
|
skipFirstItemOffset: true,
|
|
383
363
|
});
|
|
384
364
|
}
|
|
385
365
|
// Perform the final scroll to the target position
|
|
386
366
|
handlerMethods.scrollToOffset({
|
|
387
|
-
offset:
|
|
388
|
-
animated
|
|
367
|
+
offset: finalOffset,
|
|
368
|
+
animated,
|
|
389
369
|
skipFirstItemOffset: true,
|
|
390
370
|
});
|
|
391
371
|
// Re-enable offset correction after a delay
|
|
392
372
|
// Longer delay for animated scrolls to allow animation to complete
|
|
393
|
-
setTimeout(
|
|
373
|
+
setTimeout(() => {
|
|
394
374
|
pauseOffsetCorrection.current = false;
|
|
395
375
|
recyclerViewManager.setOffsetProjectionEnabled(true);
|
|
396
376
|
resolve(); // Resolve the promise after re-enabling corrections
|
|
397
377
|
}, animated ? 300 : 200);
|
|
398
378
|
};
|
|
399
379
|
// Start the scroll animation process
|
|
400
|
-
|
|
380
|
+
performScrollStep(0);
|
|
401
381
|
}
|
|
402
382
|
else {
|
|
403
383
|
// Invalid parameters, resolve immediately
|
|
@@ -409,56 +389,55 @@ function useRecyclerViewController(recyclerViewManager, ref, scrollViewRef, scro
|
|
|
409
389
|
* Scrolls to a specific item in the list.
|
|
410
390
|
* Finds the item's index and uses scrollToIndex internally.
|
|
411
391
|
*/
|
|
412
|
-
scrollToItem:
|
|
413
|
-
|
|
414
|
-
var data = recyclerViewManager.props.data;
|
|
392
|
+
scrollToItem: ({ item, animated, viewPosition, viewOffset, }) => {
|
|
393
|
+
const { data } = recyclerViewManager.props;
|
|
415
394
|
if (scrollViewRef.current && data) {
|
|
416
395
|
// Find the index of the item in the data array
|
|
417
|
-
|
|
396
|
+
const index = data.findIndex((dataItem) => dataItem === item);
|
|
418
397
|
if (index >= 0) {
|
|
419
398
|
handlerMethods.scrollToIndex({
|
|
420
|
-
index
|
|
421
|
-
animated
|
|
422
|
-
viewPosition
|
|
423
|
-
viewOffset
|
|
399
|
+
index,
|
|
400
|
+
animated,
|
|
401
|
+
viewPosition,
|
|
402
|
+
viewOffset,
|
|
424
403
|
});
|
|
425
404
|
}
|
|
426
405
|
}
|
|
427
406
|
},
|
|
428
407
|
// Utility methods for measuring header height / top padding
|
|
429
|
-
getFirstItemOffset:
|
|
408
|
+
getFirstItemOffset: () => {
|
|
430
409
|
return recyclerViewManager.firstItemOffset;
|
|
431
410
|
},
|
|
432
|
-
getWindowSize:
|
|
411
|
+
getWindowSize: () => {
|
|
433
412
|
return recyclerViewManager.getWindowSize();
|
|
434
413
|
},
|
|
435
|
-
getLayout:
|
|
414
|
+
getLayout: (index) => {
|
|
436
415
|
return recyclerViewManager.tryGetLayout(index);
|
|
437
416
|
},
|
|
438
|
-
getAbsoluteLastScrollOffset:
|
|
417
|
+
getAbsoluteLastScrollOffset: () => {
|
|
439
418
|
return recyclerViewManager.getAbsoluteLastScrollOffset();
|
|
440
419
|
},
|
|
441
|
-
getChildContainerDimensions:
|
|
420
|
+
getChildContainerDimensions: () => {
|
|
442
421
|
return recyclerViewManager.getChildContainerDimensions();
|
|
443
422
|
},
|
|
444
|
-
recordInteraction:
|
|
423
|
+
recordInteraction: () => {
|
|
445
424
|
recyclerViewManager.recordInteraction();
|
|
446
425
|
},
|
|
447
|
-
computeVisibleIndices:
|
|
426
|
+
computeVisibleIndices: () => {
|
|
448
427
|
return recyclerViewManager.computeVisibleIndices();
|
|
449
428
|
},
|
|
450
|
-
getFirstVisibleIndex:
|
|
429
|
+
getFirstVisibleIndex: () => {
|
|
451
430
|
return recyclerViewManager.computeVisibleIndices().startIndex;
|
|
452
431
|
},
|
|
453
|
-
recomputeViewableItems:
|
|
432
|
+
recomputeViewableItems: () => {
|
|
454
433
|
recyclerViewManager.recomputeViewableItems();
|
|
455
434
|
},
|
|
456
435
|
/**
|
|
457
436
|
* Disables item recycling in preparation for layout animations.
|
|
458
437
|
*/
|
|
459
|
-
prepareForLayoutAnimationRender:
|
|
438
|
+
prepareForLayoutAnimationRender: () => {
|
|
460
439
|
if (!recyclerViewManager.props.keyExtractor) {
|
|
461
|
-
console.warn(
|
|
440
|
+
console.warn(WarningMessages.keyExtractorNotDefinedForAnimation);
|
|
462
441
|
}
|
|
463
442
|
recyclerViewManager.animationOptimizationsEnabled = true;
|
|
464
443
|
},
|
|
@@ -470,32 +449,34 @@ function useRecyclerViewController(recyclerViewManager, ref, scrollViewRef, scro
|
|
|
470
449
|
isUnmounted,
|
|
471
450
|
updateScrollOffsetWithCallback,
|
|
472
451
|
]);
|
|
473
|
-
|
|
474
|
-
var _a, _b;
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
452
|
+
const applyInitialScrollIndex = useCallback(() => {
|
|
453
|
+
var _a, _b, _c;
|
|
454
|
+
const { horizontal, data, initialScrollIndexParams } = recyclerViewManager.props;
|
|
455
|
+
const initialScrollIndex = (_a = recyclerViewManager.getInitialScrollIndex()) !== null && _a !== void 0 ? _a : -1;
|
|
456
|
+
const dataLength = (_b = data === null || data === void 0 ? void 0 : data.length) !== null && _b !== void 0 ? _b : 0;
|
|
478
457
|
if (initialScrollIndex >= 0 &&
|
|
479
458
|
initialScrollIndex < dataLength &&
|
|
480
459
|
!initialScrollCompletedRef.current &&
|
|
481
460
|
recyclerViewManager.getIsFirstLayoutComplete()) {
|
|
482
461
|
// Use setTimeout to ensure that we keep trying to scroll on first few renders
|
|
483
|
-
setTimeout(
|
|
462
|
+
setTimeout(() => {
|
|
484
463
|
initialScrollCompletedRef.current = true;
|
|
485
464
|
pauseOffsetCorrection.current = false;
|
|
486
465
|
}, 100);
|
|
487
466
|
pauseOffsetCorrection.current = true;
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
467
|
+
const additionalOffset = (_c = initialScrollIndexParams === null || initialScrollIndexParams === void 0 ? void 0 : initialScrollIndexParams.viewOffset) !== null && _c !== void 0 ? _c : 0;
|
|
468
|
+
const offset = horizontal
|
|
469
|
+
? recyclerViewManager.getLayout(initialScrollIndex).x + additionalOffset
|
|
470
|
+
: recyclerViewManager.getLayout(initialScrollIndex).y +
|
|
471
|
+
additionalOffset;
|
|
491
472
|
handlerMethods.scrollToOffset({
|
|
492
|
-
offset
|
|
473
|
+
offset,
|
|
493
474
|
animated: false,
|
|
494
475
|
skipFirstItemOffset: false,
|
|
495
476
|
});
|
|
496
|
-
setTimeout(
|
|
477
|
+
setTimeout(() => {
|
|
497
478
|
handlerMethods.scrollToOffset({
|
|
498
|
-
offset
|
|
479
|
+
offset,
|
|
499
480
|
animated: false,
|
|
500
481
|
skipFirstItemOffset: false,
|
|
501
482
|
});
|
|
@@ -503,12 +484,12 @@ function useRecyclerViewController(recyclerViewManager, ref, scrollViewRef, scro
|
|
|
503
484
|
}
|
|
504
485
|
}, [handlerMethods, recyclerViewManager, setTimeout]);
|
|
505
486
|
// Expose imperative methods through the ref
|
|
506
|
-
|
|
507
|
-
|
|
487
|
+
useImperativeHandle(ref, () => {
|
|
488
|
+
const imperativeApi = { ...scrollViewRef.current, ...handlerMethods };
|
|
508
489
|
// Without this the props getter from handlerMethods is evaluated during spread and
|
|
509
490
|
// future updates to props are not reflected in the ref
|
|
510
491
|
Object.defineProperty(imperativeApi, "props", {
|
|
511
|
-
get
|
|
492
|
+
get() {
|
|
512
493
|
return recyclerViewManager.props;
|
|
513
494
|
},
|
|
514
495
|
enumerable: true,
|
|
@@ -517,10 +498,10 @@ function useRecyclerViewController(recyclerViewManager, ref, scrollViewRef, scro
|
|
|
517
498
|
return imperativeApi;
|
|
518
499
|
}, [handlerMethods, scrollViewRef, recyclerViewManager]);
|
|
519
500
|
return {
|
|
520
|
-
applyOffsetCorrection
|
|
521
|
-
computeFirstVisibleIndexForOffsetCorrection
|
|
522
|
-
applyInitialScrollIndex
|
|
523
|
-
handlerMethods
|
|
501
|
+
applyOffsetCorrection,
|
|
502
|
+
computeFirstVisibleIndexForOffsetCorrection,
|
|
503
|
+
applyInitialScrollIndex,
|
|
504
|
+
handlerMethods,
|
|
524
505
|
};
|
|
525
506
|
}
|
|
526
507
|
//# sourceMappingURL=useRecyclerViewController.js.map
|