react-native-livechart 4.26.0 → 4.28.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/MultiSeriesDots.d.ts +1 -1
- package/dist/components/MultiSeriesDots.d.ts.map +1 -1
- package/dist/components/MultiSeriesValueLabels.d.ts +1 -1
- package/dist/components/MultiSeriesValueLabels.d.ts.map +1 -1
- package/dist/components/MultiSeriesValueLines.d.ts +1 -1
- package/dist/components/MultiSeriesValueLines.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 +15 -2
- 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 +9 -0
- package/dist/core/useLiveChartEngine.d.ts.map +1 -1
- package/dist/core/useLiveChartSeriesEngine.d.ts +18 -4
- package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
- package/dist/draw/grid.d.ts +6 -4
- package/dist/draw/grid.d.ts.map +1 -1
- package/dist/draw/line.d.ts +21 -3
- package/dist/draw/line.d.ts.map +1 -1
- package/dist/hooks/crosshairSeries.d.ts +2 -2
- package/dist/hooks/crosshairSeries.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 +18 -2
- 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 +6 -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/useMultiSeriesDegen.d.ts +1 -1
- package/dist/hooks/useMultiSeriesDegen.d.ts.map +1 -1
- package/dist/hooks/useMultiSeriesLinePaths.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 +7 -4
- 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/useYAxis.d.ts +1 -1
- package/dist/hooks/useYAxis.d.ts.map +1 -1
- package/dist/hooks/useYAxisLabelWidth.d.ts +6 -0
- package/dist/hooks/useYAxisLabelWidth.d.ts.map +1 -0
- 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/referenceLines.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 +262 -37
- 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 +580 -138
- package/src/components/LiveChartSeries.tsx +139 -19
- package/src/components/MultiSeriesDots.tsx +4 -2
- package/src/components/MultiSeriesValueLabels.tsx +4 -2
- package/src/components/MultiSeriesValueLines.tsx +4 -2
- 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 +107 -14
- package/src/core/resolveConfig.ts +103 -7
- package/src/core/useLiveChartEngine.ts +45 -9
- package/src/core/useLiveChartSeriesEngine.ts +47 -6
- package/src/draw/grid.ts +17 -13
- package/src/draw/line.ts +46 -5
- package/src/hooks/crosshairSeries.ts +37 -5
- package/src/hooks/crosshairShared.ts +56 -1
- package/src/hooks/referenceBadgeFont.ts +35 -0
- package/src/hooks/resolveChartLayout.ts +51 -3
- 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 +57 -20
- package/src/hooks/useLatestCallback.ts +15 -0
- package/src/hooks/useMarkers.ts +51 -39
- package/src/hooks/useMultiSeriesDegen.ts +10 -5
- package/src/hooks/useMultiSeriesLinePaths.ts +2 -0
- package/src/hooks/usePanScroll.ts +155 -127
- package/src/hooks/usePinchZoom.ts +94 -66
- package/src/hooks/useReferenceDrag.ts +409 -156
- 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/useYAxis.ts +1 -1
- package/src/hooks/useYAxisLabelWidth.ts +26 -0
- package/src/hooks/useYAxisScaleGesture.ts +263 -0
- package/src/index.ts +11 -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/referenceLines.ts +5 -0
- package/src/math/referenceTagStack.ts +112 -0
- package/src/math/scrubMarkers.ts +55 -0
- package/src/types.ts +263 -37
|
@@ -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
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
1
2
|
import { Gesture } from "react-native-gesture-handler";
|
|
2
3
|
import {
|
|
3
4
|
cancelAnimation,
|
|
@@ -59,6 +60,8 @@ export interface UsePinchZoomOptions {
|
|
|
59
60
|
minTime: SharedValue<number>;
|
|
60
61
|
/** The configured `timeWindow` prop (seconds) — the anchor for the zoom bounds. */
|
|
61
62
|
timeWindow: number;
|
|
63
|
+
/** Current unzoomed history span, including breathing room; independent of retained samples. */
|
|
64
|
+
fullHistoryWindow?: SharedValue<number | null>;
|
|
62
65
|
/** Master switch. When false the gesture is disabled. */
|
|
63
66
|
enabled: boolean;
|
|
64
67
|
/** Tightest window (max zoom-in), seconds. Default `timeWindow / 8`. */
|
|
@@ -90,8 +93,9 @@ export function clampWindow(
|
|
|
90
93
|
|
|
91
94
|
/**
|
|
92
95
|
* Resolve the zoom bounds for a gesture. `maxWin` defaults to the data span but
|
|
93
|
-
*
|
|
94
|
-
* starting view); `minWin` defaults
|
|
96
|
+
* includes the configured window and authoritative full-history span (so you can
|
|
97
|
+
* restore the starting view). Explicit maxima take precedence; `minWin` defaults
|
|
98
|
+
* to an 8× zoom-in of the configured window.
|
|
95
99
|
* Guards against an inverted range (min ≤ max).
|
|
96
100
|
*/
|
|
97
101
|
export function zoomWindowBounds(
|
|
@@ -99,9 +103,10 @@ export function zoomWindowBounds(
|
|
|
99
103
|
span: number,
|
|
100
104
|
minCfg: number | undefined,
|
|
101
105
|
maxCfg: number | undefined,
|
|
106
|
+
fullHistoryWindow?: number | null,
|
|
102
107
|
): [number, number] {
|
|
103
108
|
"worklet";
|
|
104
|
-
const maxWin = Math.max(
|
|
109
|
+
const maxWin = maxCfg ?? Math.max(span, configWindow, fullHistoryWindow ?? 0);
|
|
105
110
|
let minWin = minCfg ?? configWindow / 8;
|
|
106
111
|
if (minWin > maxWin) minWin = maxWin;
|
|
107
112
|
return [minWin, maxWin];
|
|
@@ -157,6 +162,7 @@ export function usePinchZoom({
|
|
|
157
162
|
padding,
|
|
158
163
|
minTime,
|
|
159
164
|
timeWindow,
|
|
165
|
+
fullHistoryWindow,
|
|
160
166
|
enabled,
|
|
161
167
|
minTimeWindow,
|
|
162
168
|
maxTimeWindow,
|
|
@@ -174,69 +180,91 @@ export function usePinchZoom({
|
|
|
174
180
|
|
|
175
181
|
const wakeEngine = engine.wake;
|
|
176
182
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
183
|
+
return useMemo(() => {
|
|
184
|
+
const onStart =
|
|
185
|
+
/* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
|
|
186
|
+
() => {
|
|
187
|
+
"worklet";
|
|
188
|
+
wakeEngine?.();
|
|
189
|
+
cancelAnimation(viewEnd);
|
|
190
|
+
cancelAnimation(viewWindow);
|
|
191
|
+
const edge = liveEdge.get();
|
|
192
|
+
startWindow.set(displayWindow.get());
|
|
193
|
+
startViewEnd.set(viewEnd.get() ?? edge);
|
|
194
|
+
onZoomStart?.();
|
|
195
|
+
};
|
|
189
196
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
?
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
197
|
+
const onChange =
|
|
198
|
+
/* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
|
|
199
|
+
(e: { scale: number; focalX: number; numberOfPointers: number }) => {
|
|
200
|
+
"worklet";
|
|
201
|
+
// When a finger lifts at the end of the pinch, the recognizer's focal
|
|
202
|
+
// point jumps from the two-finger midpoint to the remaining finger. A
|
|
203
|
+
// change event computed from that jumped focal throws the window
|
|
204
|
+
// sideways (and can even snap it back to following live). Ignore
|
|
205
|
+
// change events once fewer than two pointers remain.
|
|
206
|
+
if (e.numberOfPointers < 2) return;
|
|
207
|
+
const chartW = canvasWidth.get() - padLeft - padRight;
|
|
208
|
+
if (chartW <= 0 || e.scale <= 0) return;
|
|
209
|
+
const edge = liveEdge.get();
|
|
210
|
+
const sWin = startWindow.get();
|
|
211
|
+
const sEnd = startViewEnd.get();
|
|
212
|
+
const span = edge - minTime.get();
|
|
213
|
+
const [minWin, maxWin] = zoomWindowBounds(
|
|
214
|
+
timeWindow,
|
|
215
|
+
span,
|
|
216
|
+
minTimeWindow,
|
|
217
|
+
maxTimeWindow,
|
|
218
|
+
fullHistoryWindow?.get(),
|
|
219
|
+
);
|
|
220
|
+
// Pinch out (scale > 1) ⇒ narrower window ⇒ zoom in.
|
|
221
|
+
const newWin = clampWindow(sWin / e.scale, minWin, maxWin);
|
|
222
|
+
// Time under the fingers, mapped through the START window so the anchor
|
|
223
|
+
// doesn't compound; the right edge then keeps it under the (live) focal.
|
|
224
|
+
const focalT = focalTime(e.focalX, padLeft, chartW, sEnd - sWin, sWin);
|
|
225
|
+
let newEnd = zoomViewEnd(focalT, e.focalX, padLeft, chartW, newWin);
|
|
226
|
+
const lo = panLowerBound(minTime.get(), newWin, edge, overscroll);
|
|
227
|
+
if (newEnd < lo) newEnd = lo;
|
|
228
|
+
const hi = overscroll > 0 ? panUpperBound(newWin, edge, overscroll) : edge;
|
|
229
|
+
if (newEnd > hi) newEnd = hi;
|
|
230
|
+
viewWindow.set(newWin);
|
|
231
|
+
// Track the displayed window 1:1 (bypass the frame-loop lerp lag) so the
|
|
232
|
+
// focal anchor is pixel-accurate during the gesture.
|
|
233
|
+
displayWindow.set(newWin);
|
|
234
|
+
// Unlike the pan (see nextViewEnd), snapping to `null` mid-gesture is safe
|
|
235
|
+
// here: the pinch maps cumulative scale/focal from a gesture-START snapshot
|
|
236
|
+
// (`startViewEnd`), not per-frame deltas, so a snap can't re-anchor it.
|
|
237
|
+
// With overscroll, snap within the FOLLOW_SNAP zone; without, at the edge.
|
|
238
|
+
viewEnd.set(
|
|
239
|
+
overscroll > 0
|
|
240
|
+
? Math.abs(newEnd - edge) <= newWin * FOLLOW_SNAP
|
|
241
|
+
? null
|
|
242
|
+
: newEnd
|
|
243
|
+
: newEnd >= edge
|
|
244
|
+
? null
|
|
245
|
+
: newEnd,
|
|
246
|
+
);
|
|
247
|
+
};
|
|
240
248
|
|
|
241
|
-
|
|
249
|
+
return Gesture.Pinch().enabled(enabled).onStart(onStart).onChange(onChange);
|
|
250
|
+
}, [
|
|
251
|
+
canvasWidth,
|
|
252
|
+
displayWindow,
|
|
253
|
+
enabled,
|
|
254
|
+
fullHistoryWindow,
|
|
255
|
+
liveEdge,
|
|
256
|
+
maxTimeWindow,
|
|
257
|
+
minTime,
|
|
258
|
+
minTimeWindow,
|
|
259
|
+
onZoomStart,
|
|
260
|
+
overscroll,
|
|
261
|
+
padLeft,
|
|
262
|
+
padRight,
|
|
263
|
+
startViewEnd,
|
|
264
|
+
startWindow,
|
|
265
|
+
timeWindow,
|
|
266
|
+
viewEnd,
|
|
267
|
+
viewWindow,
|
|
268
|
+
wakeEngine,
|
|
269
|
+
]);
|
|
242
270
|
}
|