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.
Files changed (142) hide show
  1. package/dist/components/CustomReferenceLineOverlay.d.ts +8 -1
  2. package/dist/components/CustomReferenceLineOverlay.d.ts.map +1 -1
  3. package/dist/components/CustomTooltipOverlay.d.ts +3 -2
  4. package/dist/components/CustomTooltipOverlay.d.ts.map +1 -1
  5. package/dist/components/LiveChart.d.ts +1 -1
  6. package/dist/components/LiveChart.d.ts.map +1 -1
  7. package/dist/components/LiveChartSeries.d.ts.map +1 -1
  8. package/dist/components/MultiSeriesDots.d.ts +1 -1
  9. package/dist/components/MultiSeriesDots.d.ts.map +1 -1
  10. package/dist/components/MultiSeriesValueLabels.d.ts +1 -1
  11. package/dist/components/MultiSeriesValueLabels.d.ts.map +1 -1
  12. package/dist/components/MultiSeriesValueLines.d.ts +1 -1
  13. package/dist/components/MultiSeriesValueLines.d.ts.map +1 -1
  14. package/dist/components/ReferenceLineOverlay.d.ts +4 -0
  15. package/dist/components/ReferenceLineOverlay.d.ts.map +1 -1
  16. package/dist/components/ReferenceValueBadge.d.ts +15 -0
  17. package/dist/components/ReferenceValueBadge.d.ts.map +1 -0
  18. package/dist/components/XAxisOverlay.d.ts +17 -0
  19. package/dist/components/XAxisOverlay.d.ts.map +1 -1
  20. package/dist/core/liveChartEngineTick.d.ts +4 -0
  21. package/dist/core/liveChartEngineTick.d.ts.map +1 -1
  22. package/dist/core/liveChartSeriesEngineTick.d.ts +15 -2
  23. package/dist/core/liveChartSeriesEngineTick.d.ts.map +1 -1
  24. package/dist/core/resolveConfig.d.ts +28 -1
  25. package/dist/core/resolveConfig.d.ts.map +1 -1
  26. package/dist/core/useLiveChartEngine.d.ts +9 -0
  27. package/dist/core/useLiveChartEngine.d.ts.map +1 -1
  28. package/dist/core/useLiveChartSeriesEngine.d.ts +18 -4
  29. package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
  30. package/dist/draw/grid.d.ts +6 -4
  31. package/dist/draw/grid.d.ts.map +1 -1
  32. package/dist/draw/line.d.ts +21 -3
  33. package/dist/draw/line.d.ts.map +1 -1
  34. package/dist/hooks/crosshairSeries.d.ts +2 -2
  35. package/dist/hooks/crosshairSeries.d.ts.map +1 -1
  36. package/dist/hooks/crosshairShared.d.ts +16 -1
  37. package/dist/hooks/crosshairShared.d.ts.map +1 -1
  38. package/dist/hooks/referenceBadgeFont.d.ts +5 -0
  39. package/dist/hooks/referenceBadgeFont.d.ts.map +1 -0
  40. package/dist/hooks/resolveChartLayout.d.ts +18 -2
  41. package/dist/hooks/resolveChartLayout.d.ts.map +1 -1
  42. package/dist/hooks/useBadge.d.ts +16 -1
  43. package/dist/hooks/useBadge.d.ts.map +1 -1
  44. package/dist/hooks/useChartSkiaFont.d.ts +1 -0
  45. package/dist/hooks/useChartSkiaFont.d.ts.map +1 -1
  46. package/dist/hooks/useCrosshair.d.ts +7 -2
  47. package/dist/hooks/useCrosshair.d.ts.map +1 -1
  48. package/dist/hooks/useCrosshairSeries.d.ts +6 -1
  49. package/dist/hooks/useCrosshairSeries.d.ts.map +1 -1
  50. package/dist/hooks/useLatestCallback.d.ts +6 -0
  51. package/dist/hooks/useLatestCallback.d.ts.map +1 -0
  52. package/dist/hooks/useMarkers.d.ts.map +1 -1
  53. package/dist/hooks/useMultiSeriesDegen.d.ts +1 -1
  54. package/dist/hooks/useMultiSeriesDegen.d.ts.map +1 -1
  55. package/dist/hooks/useMultiSeriesLinePaths.d.ts.map +1 -1
  56. package/dist/hooks/usePanScroll.d.ts +3 -1
  57. package/dist/hooks/usePanScroll.d.ts.map +1 -1
  58. package/dist/hooks/usePinchZoom.d.ts +7 -4
  59. package/dist/hooks/usePinchZoom.d.ts.map +1 -1
  60. package/dist/hooks/useReferenceDrag.d.ts +20 -5
  61. package/dist/hooks/useReferenceDrag.d.ts.map +1 -1
  62. package/dist/hooks/useReferenceLine.d.ts +24 -12
  63. package/dist/hooks/useReferenceLine.d.ts.map +1 -1
  64. package/dist/hooks/useReferenceLinePress.d.ts +4 -2
  65. package/dist/hooks/useReferenceLinePress.d.ts.map +1 -1
  66. package/dist/hooks/useReferenceTagStack.d.ts +31 -0
  67. package/dist/hooks/useReferenceTagStack.d.ts.map +1 -0
  68. package/dist/hooks/useScrubMarkers.d.ts +12 -0
  69. package/dist/hooks/useScrubMarkers.d.ts.map +1 -0
  70. package/dist/hooks/useXAxis.d.ts +1 -1
  71. package/dist/hooks/useXAxis.d.ts.map +1 -1
  72. package/dist/hooks/useYAxis.d.ts +1 -1
  73. package/dist/hooks/useYAxis.d.ts.map +1 -1
  74. package/dist/hooks/useYAxisLabelWidth.d.ts +6 -0
  75. package/dist/hooks/useYAxisLabelWidth.d.ts.map +1 -0
  76. package/dist/hooks/useYAxisScaleGesture.d.ts +34 -0
  77. package/dist/hooks/useYAxisScaleGesture.d.ts.map +1 -0
  78. package/dist/index.d.ts +1 -1
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/math/axisBadgeLayout.d.ts +16 -0
  81. package/dist/math/axisBadgeLayout.d.ts.map +1 -0
  82. package/dist/math/markers.d.ts +3 -0
  83. package/dist/math/markers.d.ts.map +1 -1
  84. package/dist/math/range.d.ts +1 -1
  85. package/dist/math/range.d.ts.map +1 -1
  86. package/dist/math/referenceLines.d.ts.map +1 -1
  87. package/dist/math/referenceTagStack.d.ts +36 -0
  88. package/dist/math/referenceTagStack.d.ts.map +1 -0
  89. package/dist/math/scrubMarkers.d.ts +12 -0
  90. package/dist/math/scrubMarkers.d.ts.map +1 -0
  91. package/dist/types.d.ts +262 -37
  92. package/dist/types.d.ts.map +1 -1
  93. package/package.json +1 -1
  94. package/src/components/CustomReferenceLineOverlay.tsx +50 -8
  95. package/src/components/CustomTooltipOverlay.tsx +5 -1
  96. package/src/components/LiveChart.tsx +580 -138
  97. package/src/components/LiveChartSeries.tsx +139 -19
  98. package/src/components/MultiSeriesDots.tsx +4 -2
  99. package/src/components/MultiSeriesValueLabels.tsx +4 -2
  100. package/src/components/MultiSeriesValueLines.tsx +4 -2
  101. package/src/components/ReferenceLineOverlay.tsx +62 -26
  102. package/src/components/ReferenceValueBadge.tsx +102 -0
  103. package/src/components/XAxisOverlay.tsx +104 -1
  104. package/src/core/liveChartEngineTick.ts +49 -4
  105. package/src/core/liveChartSeriesEngineTick.ts +107 -14
  106. package/src/core/resolveConfig.ts +103 -7
  107. package/src/core/useLiveChartEngine.ts +45 -9
  108. package/src/core/useLiveChartSeriesEngine.ts +47 -6
  109. package/src/draw/grid.ts +17 -13
  110. package/src/draw/line.ts +46 -5
  111. package/src/hooks/crosshairSeries.ts +37 -5
  112. package/src/hooks/crosshairShared.ts +56 -1
  113. package/src/hooks/referenceBadgeFont.ts +35 -0
  114. package/src/hooks/resolveChartLayout.ts +51 -3
  115. package/src/hooks/useBadge.ts +44 -5
  116. package/src/hooks/useChartSkiaFont.ts +1 -1
  117. package/src/hooks/useCrosshair.ts +444 -310
  118. package/src/hooks/useCrosshairSeries.ts +57 -20
  119. package/src/hooks/useLatestCallback.ts +15 -0
  120. package/src/hooks/useMarkers.ts +51 -39
  121. package/src/hooks/useMultiSeriesDegen.ts +10 -5
  122. package/src/hooks/useMultiSeriesLinePaths.ts +2 -0
  123. package/src/hooks/usePanScroll.ts +155 -127
  124. package/src/hooks/usePinchZoom.ts +94 -66
  125. package/src/hooks/useReferenceDrag.ts +409 -156
  126. package/src/hooks/useReferenceLine.ts +453 -277
  127. package/src/hooks/useReferenceLineGrouping.ts +1 -1
  128. package/src/hooks/useReferenceLinePress.ts +121 -53
  129. package/src/hooks/useReferenceTagStack.ts +81 -0
  130. package/src/hooks/useScrubMarkers.ts +79 -0
  131. package/src/hooks/useXAxis.ts +11 -2
  132. package/src/hooks/useYAxis.ts +1 -1
  133. package/src/hooks/useYAxisLabelWidth.ts +26 -0
  134. package/src/hooks/useYAxisScaleGesture.ts +263 -0
  135. package/src/index.ts +11 -0
  136. package/src/math/axisBadgeLayout.ts +37 -0
  137. package/src/math/markers.ts +28 -3
  138. package/src/math/range.ts +35 -0
  139. package/src/math/referenceLines.ts +5 -0
  140. package/src/math/referenceTagStack.ts +112 -0
  141. package/src/math/scrubMarkers.ts +55 -0
  142. 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
- const onStart =
271
- /* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
272
- () => {
273
- "worklet";
274
- wakeEngine?.();
275
- // Stop an in-flight fling FIRST. `withDecay` keeps writing `viewEnd` after
276
- // the finger lifts, and `Gesture.Race` declares no relation between the two
277
- // pans, so this can run while a scrub is already engaged. Bailing out below
278
- // without cancelling left the decay sliding the window underneath the
279
- // crosshair — the opposite of the lock the scrub is meant to hold.
280
- cancelAnimation(viewEnd);
281
- // An engaged scrub locks the chart: the finger moves the price indicator
282
- // across a fixed window, so a scroll that activates underneath it must do
283
- // nothing further (and must not claim the touch via `scrollActive`).
284
- if (scrubActive?.get()) return;
285
- scrollActive?.set(true);
286
- // Keep `null` while following live. `onChange` resolves it to the current
287
- // live edge before applying the first delta. Materializing that same edge
288
- // here would falsely signal "scrolled back" between start and change,
289
- // briefly collapsing the floating-axis gutter on a forward-only overdrag.
290
- onScrollStart?.();
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
- const onChange =
294
- /* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
295
- (e: { changeX: number }) => {
296
- "worklet";
297
- if (scrubActive?.get()) return;
298
- const win = displayWindow.get();
299
- const chartW = canvasWidth.get() - padLeft - padRight;
300
- if (chartW <= 0) return;
301
- const edge = liveEdge.get();
302
- const cur = viewEnd.get() ?? edge;
303
- const lo = panLowerBound(minTime.get(), win, edge, overscroll);
304
- viewEnd.set(nextViewEnd(cur, e.changeX, chartW, win, edge, lo, overscroll));
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
- const onEnd =
308
- /* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
309
- (e: { velocityX: number }) => {
310
- "worklet";
311
- if (scrubActive?.get()) return;
312
- if (viewEnd.get() == null) return;
313
- const win = displayWindow.get();
314
- const chartW = canvasWidth.get() - padLeft - padRight;
315
- if (chartW <= 0) return;
316
- const edge = liveEdge.get();
317
- const lo = panLowerBound(minTime.get(), win, edge, overscroll);
318
- const hi = overscroll > 0 ? panUpperBound(win, edge, overscroll) : edge;
319
- // With overscroll the snap-to-follow zone widens from the exact live edge
320
- // to FOLLOW_SNAP of the window around it — this release callback is the
321
- // ONLY place that re-attaches to live (never mid-drag, see nextViewEnd).
322
- const snapZone = overscroll > 0 ? win * FOLLOW_SNAP : 1e-3;
323
- // `fling: false` → zero velocity: the decay resolves immediately where
324
- // the finger lifted, and the completion callback below still re-attaches
325
- // to live when the release lands inside the snap zone.
326
- const velocity = fling ? flingVelocity(e.velocityX, chartW, win) : 0;
327
- cancelAnimation(viewEnd);
328
- viewEnd.set(
329
- withDecay({ velocity, clamp: [lo, hi] }, (finished) => {
330
- "worklet";
331
- // Landed near the live edge → resume following; stopped short (or
332
- // past, with overscroll) → stay frozen where inertia died.
333
- if (finished && Math.abs((viewEnd.get() ?? edge) - edge) <= snapZone) {
334
- viewEnd.set(null);
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
- // Release the touch claim on every terminal state (END, FAIL, CANCEL), not just
341
- // onEnd — a scroll that fails its offset clamps never reaches onEnd, and a
342
- // stuck `scrollActive` would block scrub for the rest of the session.
343
- const onFinalize =
344
- /* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
345
- () => {
346
- "worklet";
347
- scrollActive?.set(false);
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
- if (mode === "axisDrag") {
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
- // Position-gate a one-finger pan: only a drag that starts in the bottom
355
- // axis band scrolls; everything else fails fast so scrub/parent gestures run.
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
- // holdToScrub (default): a one-finger drag anywhere scrolls. Activate on
396
- // horizontal travel so a quick one-finger drag scrolls; a still press-hold
397
- // crosses no offset and falls through to the scrub gesture (which owns the
398
- // long-press). Vertical travel fails it so a parent vertical scroll wins.
399
- return Gesture.Pan()
400
- .enabled(enabled)
401
- .maxPointers(1)
402
- .activeOffsetX([-AXIS_ACTIVATE_PX, AXIS_ACTIVATE_PX])
403
- .failOffsetY([-HOLD_SCRUB_FAIL_Y_PX, HOLD_SCRUB_FAIL_Y_PX])
404
- .onStart(onStart)
405
- .onChange(onChange)
406
- .onEnd(onEnd)
407
- .onFinalize(onFinalize);
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
- * never goes below the configured window (so you can always zoom back out to the
94
- * starting view); `minWin` defaults to an 8× zoom-in of the configured window.
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(maxCfg ?? span, configWindow);
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
- const onStart =
178
- /* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
179
- () => {
180
- "worklet";
181
- wakeEngine?.();
182
- cancelAnimation(viewEnd);
183
- cancelAnimation(viewWindow);
184
- const edge = liveEdge.get();
185
- startWindow.set(viewWindow.get() ?? timeWindow);
186
- startViewEnd.set(viewEnd.get() ?? edge);
187
- onZoomStart?.();
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
- const onChange =
191
- /* istanbul ignore next -- gesture worklet runs on the UI thread, not in Jest */
192
- (e: { scale: number; focalX: number; numberOfPointers: number }) => {
193
- "worklet";
194
- // When a finger lifts at the end of the pinch, the recognizer's focal
195
- // point jumps from the two-finger midpoint to the remaining finger. A
196
- // change event computed from that jumped focal throws the window
197
- // sideways (and can even snap it back to following live). Ignore
198
- // change events once fewer than two pointers remain.
199
- if (e.numberOfPointers < 2) return;
200
- const chartW = canvasWidth.get() - padLeft - padRight;
201
- if (chartW <= 0 || e.scale <= 0) return;
202
- const edge = liveEdge.get();
203
- const sWin = startWindow.get();
204
- const sEnd = startViewEnd.get();
205
- const span = edge - minTime.get();
206
- const [minWin, maxWin] = zoomWindowBounds(
207
- timeWindow,
208
- span,
209
- minTimeWindow,
210
- maxTimeWindow,
211
- );
212
- // Pinch out (scale > 1) ⇒ narrower window ⇒ zoom in.
213
- const newWin = clampWindow(sWin / e.scale, minWin, maxWin);
214
- // Time under the fingers, mapped through the START window so the anchor
215
- // doesn't compound; the right edge then keeps it under the (live) focal.
216
- const focalT = focalTime(e.focalX, padLeft, chartW, sEnd - sWin, sWin);
217
- let newEnd = zoomViewEnd(focalT, e.focalX, padLeft, chartW, newWin);
218
- const lo = panLowerBound(minTime.get(), newWin, edge, overscroll);
219
- if (newEnd < lo) newEnd = lo;
220
- const hi = overscroll > 0 ? panUpperBound(newWin, edge, overscroll) : edge;
221
- if (newEnd > hi) newEnd = hi;
222
- viewWindow.set(newWin);
223
- // Track the displayed window 1:1 (bypass the frame-loop lerp lag) so the
224
- // focal anchor is pixel-accurate during the gesture.
225
- displayWindow.set(newWin);
226
- // Unlike the pan (see nextViewEnd), snapping to `null` mid-gesture is safe
227
- // here: the pinch maps cumulative scale/focal from a gesture-START snapshot
228
- // (`startViewEnd`), not per-frame deltas, so a snap can't re-anchor it.
229
- // With overscroll, snap within the FOLLOW_SNAP zone; without, at the edge.
230
- viewEnd.set(
231
- overscroll > 0
232
- ? Math.abs(newEnd - edge) <= newWin * FOLLOW_SNAP
233
- ? null
234
- : newEnd
235
- : newEnd >= edge
236
- ? null
237
- : newEnd,
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
- return Gesture.Pinch().enabled(enabled).onStart(onStart).onChange(onChange);
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
  }