react-native-livechart 4.26.0 → 4.27.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/components/CustomReferenceLineOverlay.d.ts +8 -1
- package/dist/components/CustomReferenceLineOverlay.d.ts.map +1 -1
- package/dist/components/CustomTooltipOverlay.d.ts +3 -2
- package/dist/components/CustomTooltipOverlay.d.ts.map +1 -1
- package/dist/components/LiveChart.d.ts +1 -1
- package/dist/components/LiveChart.d.ts.map +1 -1
- package/dist/components/LiveChartSeries.d.ts.map +1 -1
- package/dist/components/ReferenceLineOverlay.d.ts +4 -0
- package/dist/components/ReferenceLineOverlay.d.ts.map +1 -1
- package/dist/components/ReferenceValueBadge.d.ts +15 -0
- package/dist/components/ReferenceValueBadge.d.ts.map +1 -0
- package/dist/components/XAxisOverlay.d.ts +17 -0
- package/dist/components/XAxisOverlay.d.ts.map +1 -1
- package/dist/core/liveChartEngineTick.d.ts +4 -0
- package/dist/core/liveChartEngineTick.d.ts.map +1 -1
- package/dist/core/liveChartSeriesEngineTick.d.ts +2 -0
- package/dist/core/liveChartSeriesEngineTick.d.ts.map +1 -1
- package/dist/core/resolveConfig.d.ts +28 -1
- package/dist/core/resolveConfig.d.ts.map +1 -1
- package/dist/core/useLiveChartEngine.d.ts +7 -0
- package/dist/core/useLiveChartEngine.d.ts.map +1 -1
- package/dist/core/useLiveChartSeriesEngine.d.ts +2 -0
- package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
- package/dist/draw/grid.d.ts +2 -2
- package/dist/draw/line.d.ts +15 -1
- package/dist/draw/line.d.ts.map +1 -1
- package/dist/hooks/crosshairShared.d.ts +16 -1
- package/dist/hooks/crosshairShared.d.ts.map +1 -1
- package/dist/hooks/referenceBadgeFont.d.ts +5 -0
- package/dist/hooks/referenceBadgeFont.d.ts.map +1 -0
- package/dist/hooks/resolveChartLayout.d.ts +8 -0
- package/dist/hooks/resolveChartLayout.d.ts.map +1 -1
- package/dist/hooks/useBadge.d.ts +16 -1
- package/dist/hooks/useBadge.d.ts.map +1 -1
- package/dist/hooks/useChartSkiaFont.d.ts +1 -0
- package/dist/hooks/useChartSkiaFont.d.ts.map +1 -1
- package/dist/hooks/useCrosshair.d.ts +7 -2
- package/dist/hooks/useCrosshair.d.ts.map +1 -1
- package/dist/hooks/useCrosshairSeries.d.ts +4 -1
- package/dist/hooks/useCrosshairSeries.d.ts.map +1 -1
- package/dist/hooks/useLatestCallback.d.ts +6 -0
- package/dist/hooks/useLatestCallback.d.ts.map +1 -0
- package/dist/hooks/useMarkers.d.ts.map +1 -1
- package/dist/hooks/usePanScroll.d.ts +3 -1
- package/dist/hooks/usePanScroll.d.ts.map +1 -1
- package/dist/hooks/usePinchZoom.d.ts.map +1 -1
- package/dist/hooks/useReferenceDrag.d.ts +20 -5
- package/dist/hooks/useReferenceDrag.d.ts.map +1 -1
- package/dist/hooks/useReferenceLine.d.ts +24 -12
- package/dist/hooks/useReferenceLine.d.ts.map +1 -1
- package/dist/hooks/useReferenceLinePress.d.ts +4 -2
- package/dist/hooks/useReferenceLinePress.d.ts.map +1 -1
- package/dist/hooks/useReferenceTagStack.d.ts +31 -0
- package/dist/hooks/useReferenceTagStack.d.ts.map +1 -0
- package/dist/hooks/useScrubMarkers.d.ts +12 -0
- package/dist/hooks/useScrubMarkers.d.ts.map +1 -0
- package/dist/hooks/useXAxis.d.ts +1 -1
- package/dist/hooks/useXAxis.d.ts.map +1 -1
- package/dist/hooks/useYAxisScaleGesture.d.ts +34 -0
- package/dist/hooks/useYAxisScaleGesture.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/math/axisBadgeLayout.d.ts +16 -0
- package/dist/math/axisBadgeLayout.d.ts.map +1 -0
- package/dist/math/markers.d.ts +3 -0
- package/dist/math/markers.d.ts.map +1 -1
- package/dist/math/range.d.ts +1 -1
- package/dist/math/range.d.ts.map +1 -1
- package/dist/math/referenceTagStack.d.ts +36 -0
- package/dist/math/referenceTagStack.d.ts.map +1 -0
- package/dist/math/scrubMarkers.d.ts +12 -0
- package/dist/math/scrubMarkers.d.ts.map +1 -0
- package/dist/types.d.ts +202 -32
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/CustomReferenceLineOverlay.tsx +50 -8
- package/src/components/CustomTooltipOverlay.tsx +5 -1
- package/src/components/LiveChart.tsx +560 -138
- package/src/components/LiveChartSeries.tsx +113 -13
- package/src/components/ReferenceLineOverlay.tsx +62 -26
- package/src/components/ReferenceValueBadge.tsx +102 -0
- package/src/components/XAxisOverlay.tsx +104 -1
- package/src/core/liveChartEngineTick.ts +49 -4
- package/src/core/liveChartSeriesEngineTick.ts +37 -0
- package/src/core/resolveConfig.ts +95 -2
- package/src/core/useLiveChartEngine.ts +43 -9
- package/src/core/useLiveChartSeriesEngine.ts +5 -0
- package/src/draw/grid.ts +2 -2
- package/src/draw/line.ts +23 -1
- package/src/hooks/crosshairShared.ts +56 -1
- package/src/hooks/referenceBadgeFont.ts +35 -0
- package/src/hooks/resolveChartLayout.ts +17 -0
- package/src/hooks/useBadge.ts +44 -5
- package/src/hooks/useChartSkiaFont.ts +1 -1
- package/src/hooks/useCrosshair.ts +444 -310
- package/src/hooks/useCrosshairSeries.ts +29 -10
- package/src/hooks/useLatestCallback.ts +15 -0
- package/src/hooks/useMarkers.ts +51 -39
- package/src/hooks/usePanScroll.ts +155 -127
- package/src/hooks/usePinchZoom.ts +84 -63
- package/src/hooks/useReferenceDrag.ts +390 -155
- package/src/hooks/useReferenceLine.ts +453 -277
- package/src/hooks/useReferenceLineGrouping.ts +1 -1
- package/src/hooks/useReferenceLinePress.ts +121 -53
- package/src/hooks/useReferenceTagStack.ts +81 -0
- package/src/hooks/useScrubMarkers.ts +79 -0
- package/src/hooks/useXAxis.ts +11 -2
- package/src/hooks/useYAxisScaleGesture.ts +263 -0
- package/src/index.ts +10 -0
- package/src/math/axisBadgeLayout.ts +37 -0
- package/src/math/markers.ts +28 -3
- package/src/math/range.ts +35 -0
- package/src/math/referenceTagStack.ts +112 -0
- package/src/math/scrubMarkers.ts +55 -0
- package/src/types.ts +207 -32
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
resetDelayedPanGuard,
|
|
38
38
|
shouldStartDelayedPan,
|
|
39
39
|
} from "./delayedPanGuard";
|
|
40
|
+
import { useScrubMarkers, type ScrubMarkerOptions } from "./useScrubMarkers";
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
43
|
* LiveChartSeries crosshair + scrub. The optional per-series tooltip is
|
|
@@ -73,6 +74,9 @@ export function useCrosshairSeries(
|
|
|
73
74
|
* drags to those bounds. Default `false`.
|
|
74
75
|
*/
|
|
75
76
|
clampToPlot = false,
|
|
77
|
+
markerOptions?: ScrubMarkerOptions,
|
|
78
|
+
/** Price-axis ownership also guards against stale native long-press events. */
|
|
79
|
+
axisScaleActive?: SharedValue<boolean>,
|
|
76
80
|
): CrosshairState {
|
|
77
81
|
const scrubX = useSharedValue(-1);
|
|
78
82
|
const scrubActive = useSharedValue(false);
|
|
@@ -169,6 +173,10 @@ export function useCrosshairSeries(
|
|
|
169
173
|
onGestureEnd?.();
|
|
170
174
|
}
|
|
171
175
|
|
|
176
|
+
const scrubMarkers = useScrubMarkers(
|
|
177
|
+
markerOptions, scrubActive, scrubTime, engine.timestamp, engine.displayWindow,
|
|
178
|
+
engine.canvasWidth, padding.left + padding.right,
|
|
179
|
+
);
|
|
172
180
|
const hasOnScrub = onScrub != null;
|
|
173
181
|
const hasOnGestureStart = onGestureStart != null;
|
|
174
182
|
const hasOnGestureEnd = onGestureEnd != null;
|
|
@@ -192,26 +200,33 @@ export function useCrosshairSeries(
|
|
|
192
200
|
padding.top,
|
|
193
201
|
padding.bottom,
|
|
194
202
|
);
|
|
195
|
-
return
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
203
|
+
return {
|
|
204
|
+
point: JSON.stringify({
|
|
205
|
+
time,
|
|
206
|
+
x,
|
|
207
|
+
y: dotY,
|
|
208
|
+
primary: r.primary,
|
|
209
|
+
series: r.seriesValues,
|
|
210
|
+
}),
|
|
211
|
+
markers: markerOptions ? scrubMarkers.get() : undefined,
|
|
212
|
+
};
|
|
202
213
|
},
|
|
203
214
|
(curr, prev) => {
|
|
204
215
|
"worklet";
|
|
205
216
|
if (!hasOnScrub) return;
|
|
206
217
|
if (curr === "__inactive__") {
|
|
207
|
-
onScrub!(null);
|
|
218
|
+
if (curr !== prev) onScrub!(null);
|
|
208
219
|
return;
|
|
209
220
|
}
|
|
210
221
|
if (curr === "__idle__" || curr === "__pending__") {
|
|
222
|
+
if (markerOptions && curr === "__pending__" && prev && typeof prev === "object") {
|
|
223
|
+
onScrub!(null);
|
|
224
|
+
}
|
|
211
225
|
return;
|
|
212
226
|
}
|
|
213
|
-
|
|
214
|
-
|
|
227
|
+
const previous = typeof prev === "object" ? prev : null;
|
|
228
|
+
if (curr.point === previous?.point && curr.markers === previous?.markers) return;
|
|
229
|
+
const p = JSON.parse(curr.point) as {
|
|
215
230
|
time: number;
|
|
216
231
|
x: number;
|
|
217
232
|
y: number;
|
|
@@ -224,6 +239,7 @@ export function useCrosshairSeries(
|
|
|
224
239
|
x: p.x,
|
|
225
240
|
y: p.y,
|
|
226
241
|
seriesValues: p.series,
|
|
242
|
+
...(markerOptions ? { markers: curr.markers } : {}),
|
|
227
243
|
});
|
|
228
244
|
},
|
|
229
245
|
);
|
|
@@ -286,6 +302,7 @@ export function useCrosshairSeries(
|
|
|
286
302
|
.onStart(
|
|
287
303
|
/* istanbul ignore next */ (e) => {
|
|
288
304
|
"worklet";
|
|
305
|
+
if (axisScaleActive?.get()) return;
|
|
289
306
|
if (
|
|
290
307
|
!shouldStartDelayedPan(
|
|
291
308
|
panGestureDelay,
|
|
@@ -313,6 +330,7 @@ export function useCrosshairSeries(
|
|
|
313
330
|
.onUpdate(
|
|
314
331
|
/* istanbul ignore next */ (e) => {
|
|
315
332
|
"worklet";
|
|
333
|
+
if (axisScaleActive?.get()) return;
|
|
316
334
|
if (!enabled) return;
|
|
317
335
|
updatePlainScrub(
|
|
318
336
|
e.x,
|
|
@@ -354,6 +372,7 @@ export function useCrosshairSeries(
|
|
|
354
372
|
if (scrubHitSlop) gesture = gesture.hitSlop(scrubHitSlop);
|
|
355
373
|
|
|
356
374
|
return {
|
|
375
|
+
scrubMarkers,
|
|
357
376
|
scrubX,
|
|
358
377
|
scrubActive,
|
|
359
378
|
scrubTime,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
/** Stable JS-thread dispatcher for callbacks scheduled by gesture worklets.
|
|
4
|
+
* Commit the new callback in an effect; an abandoned render must not replace it.
|
|
5
|
+
* Never call this dispatcher directly from the UI thread — use scheduleOnRN.
|
|
6
|
+
*/
|
|
7
|
+
export function useLatestCallback<Args extends unknown[], Result>(
|
|
8
|
+
callback: (...args: Args) => Result,
|
|
9
|
+
): (...args: Args) => Result {
|
|
10
|
+
const latest = useRef(callback);
|
|
11
|
+
useLayoutEffect(() => {
|
|
12
|
+
latest.current = callback;
|
|
13
|
+
}, [callback]);
|
|
14
|
+
return useCallback((...args: Args) => latest.current(...args), []);
|
|
15
|
+
}
|
package/src/hooks/useMarkers.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
1
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
2
2
|
import { Gesture } from "react-native-gesture-handler";
|
|
3
3
|
import {
|
|
4
4
|
useAnimatedReaction,
|
|
@@ -23,6 +23,8 @@ import type {
|
|
|
23
23
|
SeriesConfig,
|
|
24
24
|
} from "../types";
|
|
25
25
|
|
|
26
|
+
import { useLatestCallback } from "./useLatestCallback";
|
|
27
|
+
|
|
26
28
|
const ANCHORED_CLUSTER: ResolvedMarkerCluster = {
|
|
27
29
|
mode: "anchored",
|
|
28
30
|
direction: "horizontal",
|
|
@@ -76,11 +78,12 @@ export function useMarkers(
|
|
|
76
78
|
cacheRef.current = { a: [] as ProjectedMarker[], b: [] as ProjectedMarker[], tick: false };
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
const emitPress =
|
|
81
|
+
const emitPress = useLatestCallback(
|
|
80
82
|
/* istanbul ignore next -- invoked only from the UI-thread tap worklet */
|
|
81
83
|
(event: MarkerPressEvent | null) => {
|
|
82
84
|
onMarkerPress?.(event);
|
|
83
|
-
}
|
|
85
|
+
},
|
|
86
|
+
);
|
|
84
87
|
|
|
85
88
|
const project =
|
|
86
89
|
/* istanbul ignore next -- worklet runs on UI thread, not in Jest */ () => {
|
|
@@ -133,43 +136,52 @@ export function useMarkers(
|
|
|
133
136
|
markerFrameCallback.setActive(legacyActive);
|
|
134
137
|
}, [legacyActive, markerFrameCallback]);
|
|
135
138
|
|
|
136
|
-
const tapGesture =
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
139
|
+
const { tapGesture, hitTest } = useMemo(() => {
|
|
140
|
+
const tapGesture = Gesture.Tap().onEnd(
|
|
141
|
+
/* istanbul ignore next -- gesture worklet runs on UI thread, not in Jest */ (
|
|
142
|
+
e,
|
|
143
|
+
) => {
|
|
144
|
+
"worklet";
|
|
145
|
+
const proj = projected.get();
|
|
146
|
+
const idx = nearestMarkerIndex(proj, e.x, e.y, hitRadius);
|
|
147
|
+
if (idx < 0) {
|
|
148
|
+
runOnJS(emitPress)(null);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const ms = markers.get();
|
|
152
|
+
const m = ms[idx];
|
|
153
|
+
const p = proj[idx];
|
|
154
|
+
const isGrouped = p.isGrouped;
|
|
155
|
+
// Collapsed cluster: surface the whole bucket so the consumer can list it.
|
|
156
|
+
const members = isGrouped ? clusterMembers(ms, proj, idx) : undefined;
|
|
157
|
+
runOnJS(emitPress)({
|
|
158
|
+
marker: m,
|
|
159
|
+
point: { x: p.x, y: p.y },
|
|
160
|
+
index: idx,
|
|
161
|
+
isGrouped,
|
|
162
|
+
members,
|
|
163
|
+
});
|
|
164
|
+
},
|
|
165
|
+
);
|
|
162
166
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
167
|
+
// Lets a coexisting gesture (e.g. the scrub-action tap) defer to a marker
|
|
168
|
+
// under the finger instead of acting on it.
|
|
169
|
+
const hitTest =
|
|
170
|
+
/* istanbul ignore next -- worklet, runs on the UI thread, not in Jest */ (
|
|
171
|
+
x: number,
|
|
172
|
+
y: number,
|
|
173
|
+
) => {
|
|
174
|
+
"worklet";
|
|
175
|
+
return nearestMarkerIndex(projected.get(), x, y, hitRadius) >= 0;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
return { tapGesture, hitTest };
|
|
179
|
+
}, [
|
|
180
|
+
emitPress,
|
|
181
|
+
hitRadius,
|
|
182
|
+
markers,
|
|
183
|
+
projected,
|
|
184
|
+
]);
|
|
173
185
|
|
|
174
186
|
return { projected, tapGesture, hitTest };
|
|
175
187
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
1
2
|
import { Gesture } from "react-native-gesture-handler";
|
|
2
3
|
import {
|
|
3
4
|
cancelAnimation,
|
|
@@ -90,6 +91,8 @@ export interface UsePanScrollOptions {
|
|
|
90
91
|
* (see `resolveFling`). Default `true`.
|
|
91
92
|
*/
|
|
92
93
|
fling?: boolean;
|
|
94
|
+
/** Re-clamp parked state on config changes. False for an app-owned viewport. Default true. */
|
|
95
|
+
clampOnOverscrollChange?: boolean;
|
|
93
96
|
}
|
|
94
97
|
|
|
95
98
|
/**
|
|
@@ -228,6 +231,7 @@ export function usePanScroll({
|
|
|
228
231
|
scrubActive,
|
|
229
232
|
overscroll = 0,
|
|
230
233
|
fling = true,
|
|
234
|
+
clampOnOverscrollChange = true,
|
|
231
235
|
}: UsePanScrollOptions): ReturnType<typeof Gesture.Pan> {
|
|
232
236
|
const { viewEnd, liveEdge, displayWindow, canvasWidth, canvasHeight } = engine;
|
|
233
237
|
const padLeft = padding.left;
|
|
@@ -249,6 +253,7 @@ export function usePanScroll({
|
|
|
249
253
|
() => overscrollSV.value,
|
|
250
254
|
/* istanbul ignore next -- UI-thread config reaction; pure clamp is unit-tested */
|
|
251
255
|
(nextOverscroll) => {
|
|
256
|
+
if (!clampOnOverscrollChange) return;
|
|
252
257
|
const cur = viewEnd.get();
|
|
253
258
|
if (cur == null) return;
|
|
254
259
|
const next = clampViewEndForOverscroll(
|
|
@@ -267,142 +272,165 @@ export function usePanScroll({
|
|
|
267
272
|
|
|
268
273
|
const wakeEngine = engine.wake;
|
|
269
274
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
275
|
+
return useMemo(() => {
|
|
276
|
+
const onStart =
|
|
277
|
+
/* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
|
|
278
|
+
() => {
|
|
279
|
+
"worklet";
|
|
280
|
+
wakeEngine?.();
|
|
281
|
+
// Stop an in-flight fling FIRST. `withDecay` keeps writing `viewEnd` after
|
|
282
|
+
// the finger lifts, and `Gesture.Race` declares no relation between the two
|
|
283
|
+
// pans, so this can run while a scrub is already engaged. Bailing out below
|
|
284
|
+
// without cancelling left the decay sliding the window underneath the
|
|
285
|
+
// crosshair — the opposite of the lock the scrub is meant to hold.
|
|
286
|
+
cancelAnimation(viewEnd);
|
|
287
|
+
// An engaged scrub locks the chart: the finger moves the price indicator
|
|
288
|
+
// across a fixed window, so a scroll that activates underneath it must do
|
|
289
|
+
// nothing further (and must not claim the touch via `scrollActive`).
|
|
290
|
+
if (scrubActive?.get()) return;
|
|
291
|
+
scrollActive?.set(true);
|
|
292
|
+
// Keep `null` while following live. `onChange` resolves it to the current
|
|
293
|
+
// live edge before applying the first delta. Materializing that same edge
|
|
294
|
+
// here would falsely signal "scrolled back" between start and change,
|
|
295
|
+
// briefly collapsing the floating-axis gutter on a forward-only overdrag.
|
|
296
|
+
onScrollStart?.();
|
|
297
|
+
};
|
|
292
298
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
299
|
+
const onChange =
|
|
300
|
+
/* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
|
|
301
|
+
(e: { changeX: number }) => {
|
|
302
|
+
"worklet";
|
|
303
|
+
if (scrubActive?.get()) return;
|
|
304
|
+
const win = displayWindow.get();
|
|
305
|
+
const chartW = canvasWidth.get() - padLeft - padRight;
|
|
306
|
+
if (chartW <= 0) return;
|
|
307
|
+
const edge = liveEdge.get();
|
|
308
|
+
const cur = viewEnd.get() ?? edge;
|
|
309
|
+
const lo = panLowerBound(minTime.get(), win, edge, overscroll);
|
|
310
|
+
viewEnd.set(nextViewEnd(cur, e.changeX, chartW, win, edge, lo, overscroll));
|
|
311
|
+
};
|
|
306
312
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
313
|
+
const onEnd =
|
|
314
|
+
/* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
|
|
315
|
+
(e: { velocityX: number }) => {
|
|
316
|
+
"worklet";
|
|
317
|
+
if (scrubActive?.get()) return;
|
|
318
|
+
if (viewEnd.get() == null) return;
|
|
319
|
+
const win = displayWindow.get();
|
|
320
|
+
const chartW = canvasWidth.get() - padLeft - padRight;
|
|
321
|
+
if (chartW <= 0) return;
|
|
322
|
+
const edge = liveEdge.get();
|
|
323
|
+
const lo = panLowerBound(minTime.get(), win, edge, overscroll);
|
|
324
|
+
const hi = overscroll > 0 ? panUpperBound(win, edge, overscroll) : edge;
|
|
325
|
+
// With overscroll the snap-to-follow zone widens from the exact live edge
|
|
326
|
+
// to FOLLOW_SNAP of the window around it — this release callback is the
|
|
327
|
+
// ONLY place that re-attaches to live (never mid-drag, see nextViewEnd).
|
|
328
|
+
const snapZone = overscroll > 0 ? win * FOLLOW_SNAP : 1e-3;
|
|
329
|
+
// `fling: false` → zero velocity: the decay resolves immediately where
|
|
330
|
+
// the finger lifted, and the completion callback below still re-attaches
|
|
331
|
+
// to live when the release lands inside the snap zone.
|
|
332
|
+
const velocity = fling ? flingVelocity(e.velocityX, chartW, win) : 0;
|
|
333
|
+
cancelAnimation(viewEnd);
|
|
334
|
+
viewEnd.set(
|
|
335
|
+
withDecay({ velocity, clamp: [lo, hi] }, (finished) => {
|
|
336
|
+
"worklet";
|
|
337
|
+
// Landed near the live edge → resume following; stopped short (or
|
|
338
|
+
// past, with overscroll) → stay frozen where inertia died.
|
|
339
|
+
if (finished && Math.abs((viewEnd.get() ?? edge) - edge) <= snapZone) {
|
|
340
|
+
viewEnd.set(null);
|
|
341
|
+
}
|
|
342
|
+
}),
|
|
343
|
+
);
|
|
344
|
+
};
|
|
339
345
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
346
|
+
// Release the touch claim on every terminal state (END, FAIL, CANCEL), not just
|
|
347
|
+
// onEnd — a scroll that fails its offset clamps never reaches onEnd, and a
|
|
348
|
+
// stuck `scrollActive` would block scrub for the rest of the session.
|
|
349
|
+
const onFinalize =
|
|
350
|
+
/* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
|
|
351
|
+
() => {
|
|
352
|
+
"worklet";
|
|
353
|
+
scrollActive?.set(false);
|
|
354
|
+
};
|
|
349
355
|
|
|
350
|
-
|
|
356
|
+
if (mode === "axisDrag") {
|
|
357
|
+
return Gesture.Pan()
|
|
358
|
+
.enabled(enabled)
|
|
359
|
+
.maxPointers(1)
|
|
360
|
+
// Position-gate a one-finger pan: only a drag that starts in the bottom
|
|
361
|
+
// axis band scrolls; everything else fails fast so scrub/parent gestures run.
|
|
362
|
+
.manualActivation(true)
|
|
363
|
+
.onTouchesDown(
|
|
364
|
+
/* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
|
|
365
|
+
(e, manager) => {
|
|
366
|
+
"worklet";
|
|
367
|
+
const t = e.changedTouches[0];
|
|
368
|
+
if (!t) return;
|
|
369
|
+
if (t.y < axisBandTop(canvasHeight.get(), padBottom)) {
|
|
370
|
+
armed.set(false);
|
|
371
|
+
manager.fail();
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
armed.set(true);
|
|
375
|
+
startX.set(t.x);
|
|
376
|
+
startY.set(t.y);
|
|
377
|
+
},
|
|
378
|
+
)
|
|
379
|
+
.onTouchesMove(
|
|
380
|
+
/* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
|
|
381
|
+
(e, manager) => {
|
|
382
|
+
"worklet";
|
|
383
|
+
if (!armed.get()) return;
|
|
384
|
+
const t = e.allTouches[0];
|
|
385
|
+
if (!t) return;
|
|
386
|
+
const dx = Math.abs(t.x - startX.get());
|
|
387
|
+
const dy = Math.abs(t.y - startY.get());
|
|
388
|
+
if (dx > AXIS_ACTIVATE_PX && dx >= dy) {
|
|
389
|
+
manager.activate(); // horizontal intent → take the gesture
|
|
390
|
+
} else if (dy > AXIS_ACTIVATE_PX) {
|
|
391
|
+
manager.fail(); // vertical intent → release to parent/scroll
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
)
|
|
395
|
+
.onStart(onStart)
|
|
396
|
+
.onChange(onChange)
|
|
397
|
+
.onEnd(onEnd)
|
|
398
|
+
.onFinalize(onFinalize);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// holdToScrub (default): a one-finger drag anywhere scrolls. Activate on
|
|
402
|
+
// horizontal travel so a quick one-finger drag scrolls; a still press-hold
|
|
403
|
+
// crosses no offset and falls through to the scrub gesture (which owns the
|
|
404
|
+
// long-press). Vertical travel fails it so a parent vertical scroll wins.
|
|
351
405
|
return Gesture.Pan()
|
|
352
406
|
.enabled(enabled)
|
|
353
407
|
.maxPointers(1)
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
.manualActivation(true)
|
|
357
|
-
.onTouchesDown(
|
|
358
|
-
/* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
|
|
359
|
-
(e, manager) => {
|
|
360
|
-
"worklet";
|
|
361
|
-
const t = e.changedTouches[0];
|
|
362
|
-
if (!t) return;
|
|
363
|
-
if (t.y < axisBandTop(canvasHeight.get(), padBottom)) {
|
|
364
|
-
armed.set(false);
|
|
365
|
-
manager.fail();
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
armed.set(true);
|
|
369
|
-
startX.set(t.x);
|
|
370
|
-
startY.set(t.y);
|
|
371
|
-
},
|
|
372
|
-
)
|
|
373
|
-
.onTouchesMove(
|
|
374
|
-
/* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
|
|
375
|
-
(e, manager) => {
|
|
376
|
-
"worklet";
|
|
377
|
-
if (!armed.get()) return;
|
|
378
|
-
const t = e.allTouches[0];
|
|
379
|
-
if (!t) return;
|
|
380
|
-
const dx = Math.abs(t.x - startX.get());
|
|
381
|
-
const dy = Math.abs(t.y - startY.get());
|
|
382
|
-
if (dx > AXIS_ACTIVATE_PX && dx >= dy) {
|
|
383
|
-
manager.activate(); // horizontal intent → take the gesture
|
|
384
|
-
} else if (dy > AXIS_ACTIVATE_PX) {
|
|
385
|
-
manager.fail(); // vertical intent → release to parent/scroll
|
|
386
|
-
}
|
|
387
|
-
},
|
|
388
|
-
)
|
|
408
|
+
.activeOffsetX([-AXIS_ACTIVATE_PX, AXIS_ACTIVATE_PX])
|
|
409
|
+
.failOffsetY([-HOLD_SCRUB_FAIL_Y_PX, HOLD_SCRUB_FAIL_Y_PX])
|
|
389
410
|
.onStart(onStart)
|
|
390
411
|
.onChange(onChange)
|
|
391
412
|
.onEnd(onEnd)
|
|
392
413
|
.onFinalize(onFinalize);
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
414
|
+
}, [
|
|
415
|
+
armed,
|
|
416
|
+
canvasHeight,
|
|
417
|
+
canvasWidth,
|
|
418
|
+
displayWindow,
|
|
419
|
+
enabled,
|
|
420
|
+
fling,
|
|
421
|
+
liveEdge,
|
|
422
|
+
minTime,
|
|
423
|
+
mode,
|
|
424
|
+
onScrollStart,
|
|
425
|
+
overscroll,
|
|
426
|
+
padBottom,
|
|
427
|
+
padLeft,
|
|
428
|
+
padRight,
|
|
429
|
+
scrollActive,
|
|
430
|
+
scrubActive,
|
|
431
|
+
startX,
|
|
432
|
+
startY,
|
|
433
|
+
viewEnd,
|
|
434
|
+
wakeEngine,
|
|
435
|
+
]);
|
|
408
436
|
}
|