react-native-gesture-image-viewer 2.3.3 → 3.0.0-beta.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/README.md +5 -3
- package/lib/module/GestureViewer.js +88 -140
- package/lib/module/GestureViewer.js.map +1 -1
- package/lib/module/GestureViewerManager.js +49 -105
- package/lib/module/GestureViewerManager.js.map +1 -1
- package/lib/module/gestureViewerAnimation.js +18 -0
- package/lib/module/gestureViewerAnimation.js.map +1 -0
- package/lib/module/gestureViewerPaging.js +66 -0
- package/lib/module/gestureViewerPaging.js.map +1 -0
- package/lib/module/gestureViewerRenderWindow.js +29 -0
- package/lib/module/gestureViewerRenderWindow.js.map +1 -0
- package/lib/module/getWebContentProps.js +6 -0
- package/lib/module/getWebContentProps.js.map +1 -0
- package/lib/module/getWebContentProps.web.js +8 -0
- package/lib/module/getWebContentProps.web.js.map +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/platformTapGestures.js +4 -0
- package/lib/module/platformTapGestures.js.map +1 -0
- package/lib/module/platformTapGestures.web.js +4 -0
- package/lib/module/platformTapGestures.web.js.map +1 -0
- package/lib/module/renderWindow.js +160 -0
- package/lib/module/renderWindow.js.map +1 -0
- package/lib/module/useGestureViewer.js +386 -200
- package/lib/module/useGestureViewer.js.map +1 -1
- package/lib/module/useGestureViewerController.js +3 -3
- package/lib/module/useGestureViewerController.js.map +1 -1
- package/lib/module/useGestureViewerManagerBridge.js +85 -0
- package/lib/module/useGestureViewerManagerBridge.js.map +1 -0
- package/lib/module/useGestureViewerPaging.js +147 -65
- package/lib/module/useGestureViewerPaging.js.map +1 -1
- package/lib/module/useWebClickHandler.js +7 -0
- package/lib/module/useWebClickHandler.js.map +1 -0
- package/lib/module/useWebClickHandler.web.js +85 -0
- package/lib/module/useWebClickHandler.web.js.map +1 -0
- package/lib/module/useWebSingleTapTimer.js +12 -0
- package/lib/module/useWebSingleTapTimer.js.map +1 -0
- package/lib/module/useWebSingleTapTimer.web.js +25 -0
- package/lib/module/useWebSingleTapTimer.web.js.map +1 -0
- package/lib/module/utils/index.js +0 -77
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/tapZoom.js +4 -3
- package/lib/module/utils/tapZoom.js.map +1 -1
- package/lib/typescript/src/GestureViewer.d.ts +1 -1
- package/lib/typescript/src/GestureViewer.d.ts.map +1 -1
- package/lib/typescript/src/GestureViewerManager.d.ts +20 -20
- package/lib/typescript/src/GestureViewerManager.d.ts.map +1 -1
- package/lib/typescript/src/gestureViewerAnimation.d.ts +15 -0
- package/lib/typescript/src/gestureViewerAnimation.d.ts.map +1 -0
- package/lib/typescript/src/gestureViewerPaging.d.ts +13 -0
- package/lib/typescript/src/gestureViewerPaging.d.ts.map +1 -0
- package/lib/typescript/src/gestureViewerRenderWindow.d.ts +15 -0
- package/lib/typescript/src/gestureViewerRenderWindow.d.ts.map +1 -0
- package/lib/typescript/src/getWebContentProps.d.ts +3 -0
- package/lib/typescript/src/getWebContentProps.d.ts.map +1 -0
- package/lib/typescript/src/getWebContentProps.web.d.ts +5 -0
- package/lib/typescript/src/getWebContentProps.web.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/platformTapGestures.d.ts +2 -0
- package/lib/typescript/src/platformTapGestures.d.ts.map +1 -0
- package/lib/typescript/src/platformTapGestures.web.d.ts +2 -0
- package/lib/typescript/src/platformTapGestures.web.d.ts.map +1 -0
- package/lib/typescript/src/renderWindow.d.ts +44 -0
- package/lib/typescript/src/renderWindow.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +45 -52
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useGestureViewer.d.ts +9 -8
- package/lib/typescript/src/useGestureViewer.d.ts.map +1 -1
- package/lib/typescript/src/useGestureViewerController.d.ts +1 -1
- package/lib/typescript/src/useGestureViewerManagerBridge.d.ts +28 -0
- package/lib/typescript/src/useGestureViewerManagerBridge.d.ts.map +1 -0
- package/lib/typescript/src/useGestureViewerPaging.d.ts +31 -2
- package/lib/typescript/src/useGestureViewerPaging.d.ts.map +1 -1
- package/lib/typescript/src/useWebClickHandler.d.ts +35 -0
- package/lib/typescript/src/useWebClickHandler.d.ts.map +1 -0
- package/lib/typescript/src/useWebClickHandler.web.d.ts +36 -0
- package/lib/typescript/src/useWebClickHandler.web.d.ts.map +1 -0
- package/lib/typescript/src/useWebSingleTapTimer.d.ts +6 -0
- package/lib/typescript/src/useWebSingleTapTimer.d.ts.map +1 -0
- package/lib/typescript/src/useWebSingleTapTimer.web.d.ts +6 -0
- package/lib/typescript/src/useWebSingleTapTimer.web.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +0 -20
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/tapZoom.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/GestureViewer.tsx +104 -191
- package/src/GestureViewerManager.ts +77 -122
- package/src/gestureViewerAnimation.ts +18 -0
- package/src/gestureViewerPaging.ts +116 -0
- package/src/gestureViewerRenderWindow.ts +56 -0
- package/src/getWebContentProps.ts +5 -0
- package/src/getWebContentProps.web.ts +5 -0
- package/src/index.tsx +1 -0
- package/src/platformTapGestures.ts +1 -0
- package/src/platformTapGestures.web.ts +1 -0
- package/src/renderWindow.ts +253 -0
- package/src/types.ts +44 -99
- package/src/useGestureViewer.ts +557 -258
- package/src/useGestureViewerController.ts +3 -3
- package/src/useGestureViewerManagerBridge.ts +118 -0
- package/src/useGestureViewerPaging.ts +277 -98
- package/src/useWebClickHandler.ts +44 -0
- package/src/useWebClickHandler.web.ts +146 -0
- package/src/useWebSingleTapTimer.ts +10 -0
- package/src/useWebSingleTapTimer.web.ts +30 -0
- package/src/utils/index.ts +0 -102
- package/src/utils/tapZoom.ts +4 -3
- package/lib/module/WebPagingFixStyle.js +0 -25
- package/lib/module/WebPagingFixStyle.js.map +0 -1
- package/lib/module/scheduleInitialScroll.js +0 -21
- package/lib/module/scheduleInitialScroll.js.map +0 -1
- package/lib/module/useGestureViewerPaging.types.js +0 -4
- package/lib/module/useGestureViewerPaging.types.js.map +0 -1
- package/lib/module/useGestureViewerPaging.web.js +0 -275
- package/lib/module/useGestureViewerPaging.web.js.map +0 -1
- package/lib/module/utils/FlashList.js +0 -9
- package/lib/module/utils/FlashList.js.map +0 -1
- package/lib/module/utils/webScroll.js +0 -70
- package/lib/module/utils/webScroll.js.map +0 -1
- package/lib/typescript/src/WebPagingFixStyle.d.ts +0 -6
- package/lib/typescript/src/WebPagingFixStyle.d.ts.map +0 -1
- package/lib/typescript/src/scheduleInitialScroll.d.ts +0 -3
- package/lib/typescript/src/scheduleInitialScroll.d.ts.map +0 -1
- package/lib/typescript/src/useGestureViewerPaging.types.d.ts +0 -41
- package/lib/typescript/src/useGestureViewerPaging.types.d.ts.map +0 -1
- package/lib/typescript/src/useGestureViewerPaging.web.d.ts +0 -3
- package/lib/typescript/src/useGestureViewerPaging.web.d.ts.map +0 -1
- package/lib/typescript/src/utils/FlashList.d.ts +0 -2
- package/lib/typescript/src/utils/FlashList.d.ts.map +0 -1
- package/lib/typescript/src/utils/webScroll.d.ts +0 -18
- package/lib/typescript/src/utils/webScroll.d.ts.map +0 -1
- package/src/WebPagingFixStyle.tsx +0 -25
- package/src/scheduleInitialScroll.ts +0 -36
- package/src/useGestureViewerPaging.types.ts +0 -41
- package/src/useGestureViewerPaging.web.ts +0 -434
- package/src/utils/FlashList.ts +0 -7
- package/src/utils/webScroll.ts +0 -96
|
@@ -1,434 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef, type MouseEvent } from 'react';
|
|
2
|
-
import type { NativeScrollEvent, NativeSyntheticEvent } from 'react-native';
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
UseGestureViewerPagingArgs,
|
|
6
|
-
UseGestureViewerPagingResult,
|
|
7
|
-
WebClickTarget,
|
|
8
|
-
} from './useGestureViewerPaging.types';
|
|
9
|
-
import { applyTapZoomAtPoint } from './utils/tapZoom';
|
|
10
|
-
import {
|
|
11
|
-
getWebAutoPlayTargetPhysicalIndex,
|
|
12
|
-
getWebScrollPhysicalIndex,
|
|
13
|
-
resolveWebScrollFinalState,
|
|
14
|
-
} from './utils/webScroll';
|
|
15
|
-
|
|
16
|
-
type WebScrollActor = 'idle' | 'user' | 'autoplay';
|
|
17
|
-
|
|
18
|
-
type WebScrollRuntime = {
|
|
19
|
-
actor: WebScrollActor;
|
|
20
|
-
isAutoplayPausedByUser: boolean;
|
|
21
|
-
lastSettledPhysicalIndex: number;
|
|
22
|
-
latestOffsetX: number;
|
|
23
|
-
latestRawPhysicalIndex: number;
|
|
24
|
-
lastProgrammaticScrollVersion: number;
|
|
25
|
-
settleTimer: ReturnType<typeof setTimeout> | null;
|
|
26
|
-
resumeAutoplayTimer: ReturnType<typeof setTimeout> | null;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export function useGestureViewerPaging({
|
|
30
|
-
adjustedInitialIndex,
|
|
31
|
-
autoPlay,
|
|
32
|
-
autoPlayInterval,
|
|
33
|
-
currentIndex,
|
|
34
|
-
dataLength,
|
|
35
|
-
enableDoubleTapZoom,
|
|
36
|
-
enableHorizontalSwipe,
|
|
37
|
-
enableLoop,
|
|
38
|
-
height,
|
|
39
|
-
onSingleTap,
|
|
40
|
-
isRotated,
|
|
41
|
-
isZoomed,
|
|
42
|
-
itemSpacing,
|
|
43
|
-
manager,
|
|
44
|
-
maxZoomScale,
|
|
45
|
-
scale,
|
|
46
|
-
scrollTo,
|
|
47
|
-
syncCurrentIndex,
|
|
48
|
-
syncPendingIndex,
|
|
49
|
-
translateX,
|
|
50
|
-
translateY,
|
|
51
|
-
width,
|
|
52
|
-
}: UseGestureViewerPagingArgs): UseGestureViewerPagingResult {
|
|
53
|
-
const webSingleTapTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
54
|
-
|
|
55
|
-
const webScrollRuntimeRef = useRef<WebScrollRuntime>({
|
|
56
|
-
actor: 'idle',
|
|
57
|
-
isAutoplayPausedByUser: false,
|
|
58
|
-
lastSettledPhysicalIndex: adjustedInitialIndex,
|
|
59
|
-
latestOffsetX: adjustedInitialIndex * (width + itemSpacing),
|
|
60
|
-
latestRawPhysicalIndex: adjustedInitialIndex,
|
|
61
|
-
lastProgrammaticScrollVersion: 0,
|
|
62
|
-
settleTimer: null,
|
|
63
|
-
resumeAutoplayTimer: null,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const clearWebSingleTapTimer = useCallback(() => {
|
|
67
|
-
if (webSingleTapTimerRef.current) {
|
|
68
|
-
clearTimeout(webSingleTapTimerRef.current);
|
|
69
|
-
webSingleTapTimerRef.current = null;
|
|
70
|
-
}
|
|
71
|
-
}, []);
|
|
72
|
-
|
|
73
|
-
const clearWebSettleTimer = useCallback(() => {
|
|
74
|
-
const runtime = webScrollRuntimeRef.current;
|
|
75
|
-
|
|
76
|
-
if (runtime.settleTimer) {
|
|
77
|
-
clearTimeout(runtime.settleTimer);
|
|
78
|
-
runtime.settleTimer = null;
|
|
79
|
-
}
|
|
80
|
-
}, []);
|
|
81
|
-
|
|
82
|
-
const clearWebAutoplayResumeTimer = useCallback(() => {
|
|
83
|
-
const runtime = webScrollRuntimeRef.current;
|
|
84
|
-
|
|
85
|
-
if (runtime.resumeAutoplayTimer) {
|
|
86
|
-
clearTimeout(runtime.resumeAutoplayTimer);
|
|
87
|
-
runtime.resumeAutoplayTimer = null;
|
|
88
|
-
}
|
|
89
|
-
}, []);
|
|
90
|
-
|
|
91
|
-
const scheduleWebAutoplayResume = useCallback(() => {
|
|
92
|
-
const runtime = webScrollRuntimeRef.current;
|
|
93
|
-
|
|
94
|
-
clearWebAutoplayResumeTimer();
|
|
95
|
-
runtime.resumeAutoplayTimer = setTimeout(() => {
|
|
96
|
-
runtime.isAutoplayPausedByUser = false;
|
|
97
|
-
runtime.resumeAutoplayTimer = null;
|
|
98
|
-
}, 800);
|
|
99
|
-
}, [clearWebAutoplayResumeTimer]);
|
|
100
|
-
|
|
101
|
-
const pauseWebAutoplayWithoutPagingInteraction = useCallback(() => {
|
|
102
|
-
const runtime = webScrollRuntimeRef.current;
|
|
103
|
-
|
|
104
|
-
runtime.isAutoplayPausedByUser = true;
|
|
105
|
-
runtime.actor = 'idle';
|
|
106
|
-
clearWebAutoplayResumeTimer();
|
|
107
|
-
}, [clearWebAutoplayResumeTimer]);
|
|
108
|
-
|
|
109
|
-
const beginWebUserInteraction = useCallback(
|
|
110
|
-
(force = false) => {
|
|
111
|
-
const runtime = webScrollRuntimeRef.current;
|
|
112
|
-
|
|
113
|
-
if (!force && runtime.actor === 'autoplay') {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
runtime.actor = 'user';
|
|
118
|
-
runtime.isAutoplayPausedByUser = true;
|
|
119
|
-
clearWebAutoplayResumeTimer();
|
|
120
|
-
},
|
|
121
|
-
[clearWebAutoplayResumeTimer],
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
const beginWebAutoplayScroll = useCallback(() => {
|
|
125
|
-
const runtime = webScrollRuntimeRef.current;
|
|
126
|
-
|
|
127
|
-
runtime.actor = 'autoplay';
|
|
128
|
-
runtime.isAutoplayPausedByUser = false;
|
|
129
|
-
runtime.lastProgrammaticScrollVersion = manager?.getProgrammaticScrollVersion() ?? 0;
|
|
130
|
-
clearWebAutoplayResumeTimer();
|
|
131
|
-
}, [clearWebAutoplayResumeTimer, manager]);
|
|
132
|
-
|
|
133
|
-
const syncProgrammaticActorFromManager = useCallback(() => {
|
|
134
|
-
const runtime = webScrollRuntimeRef.current;
|
|
135
|
-
const nextVersion = manager?.getProgrammaticScrollVersion() ?? 0;
|
|
136
|
-
|
|
137
|
-
if (nextVersion === runtime.lastProgrammaticScrollVersion) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
runtime.actor = 'autoplay';
|
|
142
|
-
runtime.isAutoplayPausedByUser = false;
|
|
143
|
-
runtime.lastProgrammaticScrollVersion = nextVersion;
|
|
144
|
-
clearWebAutoplayResumeTimer();
|
|
145
|
-
}, [clearWebAutoplayResumeTimer, manager]);
|
|
146
|
-
|
|
147
|
-
const finalizeWebScroll = useCallback(
|
|
148
|
-
(offsetX: number, source: 'scroll' | 'momentum' = 'scroll') => {
|
|
149
|
-
if (!enableHorizontalSwipe || dataLength <= 0) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const runtime = webScrollRuntimeRef.current;
|
|
154
|
-
const settledByActor = runtime.actor;
|
|
155
|
-
|
|
156
|
-
clearWebSettleTimer();
|
|
157
|
-
runtime.latestOffsetX = offsetX;
|
|
158
|
-
|
|
159
|
-
const settledState = resolveWebScrollFinalState({
|
|
160
|
-
dataLength,
|
|
161
|
-
enableLoop,
|
|
162
|
-
lastSettledPhysicalIndex: runtime.lastSettledPhysicalIndex,
|
|
163
|
-
offsetX,
|
|
164
|
-
pageWidth: width + itemSpacing,
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
if (!settledState) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const { logicalIndex, rawPhysicalIndex, settledPhysicalIndex } = settledState;
|
|
172
|
-
|
|
173
|
-
if (source === 'scroll' && runtime.latestRawPhysicalIndex !== rawPhysicalIndex) {
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (rawPhysicalIndex !== settledPhysicalIndex) {
|
|
178
|
-
const crossedLoopBoundary =
|
|
179
|
-
enableLoop &&
|
|
180
|
-
dataLength > 1 &&
|
|
181
|
-
(rawPhysicalIndex === 0 || rawPhysicalIndex === dataLength + 1);
|
|
182
|
-
|
|
183
|
-
scrollTo(settledPhysicalIndex, !crossedLoopBoundary);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
runtime.lastSettledPhysicalIndex = settledPhysicalIndex;
|
|
187
|
-
runtime.latestOffsetX = settledPhysicalIndex * (width + itemSpacing);
|
|
188
|
-
runtime.actor = 'idle';
|
|
189
|
-
manager?.cancelPendingLoopTransition();
|
|
190
|
-
syncCurrentIndex(logicalIndex);
|
|
191
|
-
|
|
192
|
-
if (settledByActor === 'user') {
|
|
193
|
-
scheduleWebAutoplayResume();
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
[
|
|
197
|
-
clearWebSettleTimer,
|
|
198
|
-
dataLength,
|
|
199
|
-
enableHorizontalSwipe,
|
|
200
|
-
enableLoop,
|
|
201
|
-
itemSpacing,
|
|
202
|
-
manager,
|
|
203
|
-
scheduleWebAutoplayResume,
|
|
204
|
-
scrollTo,
|
|
205
|
-
syncCurrentIndex,
|
|
206
|
-
width,
|
|
207
|
-
],
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
const scheduleWebScrollSettle = useCallback(
|
|
211
|
-
(offsetX: number) => {
|
|
212
|
-
const runtime = webScrollRuntimeRef.current;
|
|
213
|
-
|
|
214
|
-
runtime.latestOffsetX = offsetX;
|
|
215
|
-
runtime.latestRawPhysicalIndex = getWebScrollPhysicalIndex(offsetX, width + itemSpacing);
|
|
216
|
-
clearWebSettleTimer();
|
|
217
|
-
runtime.settleTimer = setTimeout(() => {
|
|
218
|
-
finalizeWebScroll(runtime.latestOffsetX, 'scroll');
|
|
219
|
-
}, 180);
|
|
220
|
-
},
|
|
221
|
-
[clearWebSettleTimer, finalizeWebScroll, itemSpacing, width],
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
useEffect(() => {
|
|
225
|
-
const runtime = webScrollRuntimeRef.current;
|
|
226
|
-
|
|
227
|
-
runtime.actor = 'idle';
|
|
228
|
-
runtime.isAutoplayPausedByUser = false;
|
|
229
|
-
runtime.lastSettledPhysicalIndex = adjustedInitialIndex;
|
|
230
|
-
runtime.latestOffsetX = adjustedInitialIndex * (width + itemSpacing);
|
|
231
|
-
runtime.latestRawPhysicalIndex = adjustedInitialIndex;
|
|
232
|
-
runtime.lastProgrammaticScrollVersion = manager?.getProgrammaticScrollVersion() ?? 0;
|
|
233
|
-
clearWebSettleTimer();
|
|
234
|
-
clearWebAutoplayResumeTimer();
|
|
235
|
-
}, [
|
|
236
|
-
adjustedInitialIndex,
|
|
237
|
-
clearWebAutoplayResumeTimer,
|
|
238
|
-
clearWebSettleTimer,
|
|
239
|
-
itemSpacing,
|
|
240
|
-
manager,
|
|
241
|
-
width,
|
|
242
|
-
]);
|
|
243
|
-
|
|
244
|
-
useEffect(() => {
|
|
245
|
-
return () => {
|
|
246
|
-
clearWebSingleTapTimer();
|
|
247
|
-
clearWebSettleTimer();
|
|
248
|
-
clearWebAutoplayResumeTimer();
|
|
249
|
-
};
|
|
250
|
-
}, [clearWebAutoplayResumeTimer, clearWebSettleTimer, clearWebSingleTapTimer]);
|
|
251
|
-
|
|
252
|
-
useEffect(() => {
|
|
253
|
-
if (
|
|
254
|
-
!autoPlay ||
|
|
255
|
-
dataLength <= 1 ||
|
|
256
|
-
isZoomed ||
|
|
257
|
-
isRotated ||
|
|
258
|
-
(!enableLoop && currentIndex === dataLength - 1)
|
|
259
|
-
) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const intervalMs = Math.max(250, Math.floor(autoPlayInterval || 0));
|
|
264
|
-
|
|
265
|
-
if (!Number.isFinite(intervalMs)) {
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
const interval = setInterval(() => {
|
|
270
|
-
if (isZoomed || isRotated) {
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const runtime = webScrollRuntimeRef.current;
|
|
275
|
-
|
|
276
|
-
if (runtime.actor !== 'idle' || runtime.isAutoplayPausedByUser || runtime.settleTimer) {
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
const targetPhysicalIndex = getWebAutoPlayTargetPhysicalIndex({
|
|
281
|
-
currentIndex,
|
|
282
|
-
dataLength,
|
|
283
|
-
enableLoop,
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
if (targetPhysicalIndex === null) {
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
beginWebAutoplayScroll();
|
|
291
|
-
runtime.latestOffsetX = targetPhysicalIndex * (width + itemSpacing);
|
|
292
|
-
scrollTo(targetPhysicalIndex, true);
|
|
293
|
-
scheduleWebScrollSettle(runtime.latestOffsetX);
|
|
294
|
-
}, intervalMs);
|
|
295
|
-
|
|
296
|
-
return () => clearInterval(interval);
|
|
297
|
-
}, [
|
|
298
|
-
autoPlay,
|
|
299
|
-
autoPlayInterval,
|
|
300
|
-
beginWebAutoplayScroll,
|
|
301
|
-
currentIndex,
|
|
302
|
-
dataLength,
|
|
303
|
-
enableLoop,
|
|
304
|
-
isRotated,
|
|
305
|
-
isZoomed,
|
|
306
|
-
itemSpacing,
|
|
307
|
-
scheduleWebScrollSettle,
|
|
308
|
-
scrollTo,
|
|
309
|
-
width,
|
|
310
|
-
]);
|
|
311
|
-
|
|
312
|
-
const onScroll = useCallback(
|
|
313
|
-
(event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
314
|
-
if (!enableHorizontalSwipe) {
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
const offsetX = event.nativeEvent.contentOffset.x;
|
|
319
|
-
const runtime = webScrollRuntimeRef.current;
|
|
320
|
-
const pendingState = resolveWebScrollFinalState({
|
|
321
|
-
dataLength,
|
|
322
|
-
enableLoop,
|
|
323
|
-
lastSettledPhysicalIndex: runtime.lastSettledPhysicalIndex,
|
|
324
|
-
offsetX,
|
|
325
|
-
pageWidth: width + itemSpacing,
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
if (pendingState) {
|
|
329
|
-
syncPendingIndex(pendingState.logicalIndex);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
syncProgrammaticActorFromManager();
|
|
333
|
-
beginWebUserInteraction();
|
|
334
|
-
scheduleWebScrollSettle(offsetX);
|
|
335
|
-
},
|
|
336
|
-
[
|
|
337
|
-
beginWebUserInteraction,
|
|
338
|
-
dataLength,
|
|
339
|
-
enableHorizontalSwipe,
|
|
340
|
-
enableLoop,
|
|
341
|
-
itemSpacing,
|
|
342
|
-
scheduleWebScrollSettle,
|
|
343
|
-
syncPendingIndex,
|
|
344
|
-
syncProgrammaticActorFromManager,
|
|
345
|
-
width,
|
|
346
|
-
],
|
|
347
|
-
);
|
|
348
|
-
|
|
349
|
-
const onMomentumScrollEnd = useCallback(
|
|
350
|
-
(event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
351
|
-
if (!enableHorizontalSwipe) {
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
finalizeWebScroll(event.nativeEvent.contentOffset.x, 'momentum');
|
|
356
|
-
},
|
|
357
|
-
[enableHorizontalSwipe, finalizeWebScroll],
|
|
358
|
-
);
|
|
359
|
-
|
|
360
|
-
const onScrollBeginDrag = useCallback(() => {
|
|
361
|
-
beginWebUserInteraction(true);
|
|
362
|
-
clearWebSettleTimer();
|
|
363
|
-
manager?.handleScrollBeginDrag();
|
|
364
|
-
}, [beginWebUserInteraction, clearWebSettleTimer, manager]);
|
|
365
|
-
|
|
366
|
-
const onWebClick = useCallback(
|
|
367
|
-
(event: MouseEvent<WebClickTarget>) => {
|
|
368
|
-
const detail = event.detail;
|
|
369
|
-
const rect = event.currentTarget.getBoundingClientRect();
|
|
370
|
-
const resolvedX = event.clientX - rect.left;
|
|
371
|
-
const resolvedY = event.clientY - rect.top;
|
|
372
|
-
|
|
373
|
-
if (!enableDoubleTapZoom) {
|
|
374
|
-
if (!onSingleTap) {
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
clearWebSingleTapTimer();
|
|
379
|
-
onSingleTap(resolvedX, resolvedY);
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
if (detail === 2) {
|
|
384
|
-
clearWebSingleTapTimer();
|
|
385
|
-
|
|
386
|
-
pauseWebAutoplayWithoutPagingInteraction();
|
|
387
|
-
scheduleWebAutoplayResume();
|
|
388
|
-
|
|
389
|
-
applyTapZoomAtPoint({
|
|
390
|
-
x: resolvedX,
|
|
391
|
-
y: resolvedY,
|
|
392
|
-
width,
|
|
393
|
-
height,
|
|
394
|
-
maxZoomScale,
|
|
395
|
-
scale,
|
|
396
|
-
translateX,
|
|
397
|
-
translateY,
|
|
398
|
-
});
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
if (detail !== 1 || !onSingleTap) {
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
clearWebSingleTapTimer();
|
|
407
|
-
|
|
408
|
-
webSingleTapTimerRef.current = setTimeout(() => {
|
|
409
|
-
onSingleTap(resolvedX, resolvedY);
|
|
410
|
-
webSingleTapTimerRef.current = null;
|
|
411
|
-
}, 250);
|
|
412
|
-
},
|
|
413
|
-
[
|
|
414
|
-
clearWebSingleTapTimer,
|
|
415
|
-
enableDoubleTapZoom,
|
|
416
|
-
height,
|
|
417
|
-
maxZoomScale,
|
|
418
|
-
onSingleTap,
|
|
419
|
-
pauseWebAutoplayWithoutPagingInteraction,
|
|
420
|
-
scale,
|
|
421
|
-
scheduleWebAutoplayResume,
|
|
422
|
-
translateX,
|
|
423
|
-
translateY,
|
|
424
|
-
width,
|
|
425
|
-
],
|
|
426
|
-
);
|
|
427
|
-
|
|
428
|
-
return {
|
|
429
|
-
onMomentumScrollEnd,
|
|
430
|
-
onScroll,
|
|
431
|
-
onScrollBeginDrag,
|
|
432
|
-
onWebClick,
|
|
433
|
-
};
|
|
434
|
-
}
|
package/src/utils/FlashList.ts
DELETED
package/src/utils/webScroll.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
export const getWebScrollPhysicalIndex = (offsetX: number, pageWidth: number): number => {
|
|
2
|
-
if (!Number.isFinite(offsetX) || !Number.isFinite(pageWidth) || pageWidth <= 0) {
|
|
3
|
-
return 0;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
return Math.max(0, Math.round(offsetX / pageWidth));
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const resolveWebScrollFinalState = ({
|
|
10
|
-
dataLength,
|
|
11
|
-
enableLoop,
|
|
12
|
-
lastSettledPhysicalIndex,
|
|
13
|
-
offsetX,
|
|
14
|
-
pageWidth,
|
|
15
|
-
}: {
|
|
16
|
-
offsetX: number;
|
|
17
|
-
pageWidth: number;
|
|
18
|
-
lastSettledPhysicalIndex: number;
|
|
19
|
-
dataLength: number;
|
|
20
|
-
enableLoop: boolean;
|
|
21
|
-
}): { logicalIndex: number; rawPhysicalIndex: number; settledPhysicalIndex: number } | null => {
|
|
22
|
-
if (
|
|
23
|
-
dataLength <= 0 ||
|
|
24
|
-
!Number.isFinite(offsetX) ||
|
|
25
|
-
!Number.isFinite(pageWidth) ||
|
|
26
|
-
pageWidth <= 0
|
|
27
|
-
) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const maxPhysicalIndex = enableLoop && dataLength > 1 ? dataLength + 1 : dataLength - 1;
|
|
32
|
-
const rawPhysicalIndex = getWebScrollPhysicalIndex(offsetX, pageWidth);
|
|
33
|
-
|
|
34
|
-
if (enableLoop && dataLength > 1) {
|
|
35
|
-
const isWrappingBackward = lastSettledPhysicalIndex === 1 && rawPhysicalIndex >= dataLength;
|
|
36
|
-
const isWrappingForward = lastSettledPhysicalIndex === dataLength && rawPhysicalIndex <= 1;
|
|
37
|
-
|
|
38
|
-
if (isWrappingBackward || rawPhysicalIndex === 0) {
|
|
39
|
-
return {
|
|
40
|
-
logicalIndex: dataLength - 1,
|
|
41
|
-
rawPhysicalIndex,
|
|
42
|
-
settledPhysicalIndex: dataLength,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (isWrappingForward || rawPhysicalIndex >= dataLength + 1) {
|
|
47
|
-
return {
|
|
48
|
-
logicalIndex: 0,
|
|
49
|
-
rawPhysicalIndex,
|
|
50
|
-
settledPhysicalIndex: 1,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const targetPhysicalIndex = Math.max(0, Math.min(maxPhysicalIndex, rawPhysicalIndex));
|
|
56
|
-
|
|
57
|
-
if (enableLoop && dataLength > 1) {
|
|
58
|
-
return {
|
|
59
|
-
logicalIndex: targetPhysicalIndex - 1,
|
|
60
|
-
rawPhysicalIndex,
|
|
61
|
-
settledPhysicalIndex: targetPhysicalIndex,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
logicalIndex: targetPhysicalIndex,
|
|
67
|
-
rawPhysicalIndex,
|
|
68
|
-
settledPhysicalIndex: targetPhysicalIndex,
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export const getWebAutoPlayTargetPhysicalIndex = ({
|
|
73
|
-
currentIndex,
|
|
74
|
-
dataLength,
|
|
75
|
-
enableLoop,
|
|
76
|
-
}: {
|
|
77
|
-
currentIndex: number;
|
|
78
|
-
dataLength: number;
|
|
79
|
-
enableLoop: boolean;
|
|
80
|
-
}): number | null => {
|
|
81
|
-
if (dataLength <= 1) {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (enableLoop && currentIndex === dataLength - 1) {
|
|
86
|
-
return dataLength + 1;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const nextIndex = currentIndex + 1;
|
|
90
|
-
|
|
91
|
-
if (nextIndex >= dataLength) {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return enableLoop ? nextIndex + 1 : nextIndex;
|
|
96
|
-
};
|