react-native-livechart 4.25.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.
Files changed (125) 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/ReferenceLineOverlay.d.ts +4 -0
  9. package/dist/components/ReferenceLineOverlay.d.ts.map +1 -1
  10. package/dist/components/ReferenceValueBadge.d.ts +15 -0
  11. package/dist/components/ReferenceValueBadge.d.ts.map +1 -0
  12. package/dist/components/XAxisOverlay.d.ts +17 -0
  13. package/dist/components/XAxisOverlay.d.ts.map +1 -1
  14. package/dist/core/liveChartEngineTick.d.ts +6 -1
  15. package/dist/core/liveChartEngineTick.d.ts.map +1 -1
  16. package/dist/core/liveChartSeriesEngineTick.d.ts +4 -1
  17. package/dist/core/liveChartSeriesEngineTick.d.ts.map +1 -1
  18. package/dist/core/resolveConfig.d.ts +28 -1
  19. package/dist/core/resolveConfig.d.ts.map +1 -1
  20. package/dist/core/useLiveChartEngine.d.ts +10 -1
  21. package/dist/core/useLiveChartEngine.d.ts.map +1 -1
  22. package/dist/core/useLiveChartSeriesEngine.d.ts +5 -1
  23. package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
  24. package/dist/draw/grid.d.ts +2 -2
  25. package/dist/draw/line.d.ts +15 -1
  26. package/dist/draw/line.d.ts.map +1 -1
  27. package/dist/hooks/crosshairShared.d.ts +24 -1
  28. package/dist/hooks/crosshairShared.d.ts.map +1 -1
  29. package/dist/hooks/referenceBadgeFont.d.ts +5 -0
  30. package/dist/hooks/referenceBadgeFont.d.ts.map +1 -0
  31. package/dist/hooks/resolveChartLayout.d.ts +8 -0
  32. package/dist/hooks/resolveChartLayout.d.ts.map +1 -1
  33. package/dist/hooks/useBadge.d.ts +16 -1
  34. package/dist/hooks/useBadge.d.ts.map +1 -1
  35. package/dist/hooks/useChartSkiaFont.d.ts +1 -0
  36. package/dist/hooks/useChartSkiaFont.d.ts.map +1 -1
  37. package/dist/hooks/useCrosshair.d.ts +7 -2
  38. package/dist/hooks/useCrosshair.d.ts.map +1 -1
  39. package/dist/hooks/useCrosshairSeries.d.ts +4 -1
  40. package/dist/hooks/useCrosshairSeries.d.ts.map +1 -1
  41. package/dist/hooks/useLatestCallback.d.ts +6 -0
  42. package/dist/hooks/useLatestCallback.d.ts.map +1 -0
  43. package/dist/hooks/useMarkers.d.ts.map +1 -1
  44. package/dist/hooks/usePanScroll.d.ts +3 -1
  45. package/dist/hooks/usePanScroll.d.ts.map +1 -1
  46. package/dist/hooks/usePinchZoom.d.ts.map +1 -1
  47. package/dist/hooks/useReferenceDrag.d.ts +23 -7
  48. package/dist/hooks/useReferenceDrag.d.ts.map +1 -1
  49. package/dist/hooks/useReferenceLine.d.ts +24 -12
  50. package/dist/hooks/useReferenceLine.d.ts.map +1 -1
  51. package/dist/hooks/useReferenceLineGrouping.d.ts +19 -0
  52. package/dist/hooks/useReferenceLineGrouping.d.ts.map +1 -0
  53. package/dist/hooks/useReferenceLinePress.d.ts +4 -2
  54. package/dist/hooks/useReferenceLinePress.d.ts.map +1 -1
  55. package/dist/hooks/useReferenceTagStack.d.ts +31 -0
  56. package/dist/hooks/useReferenceTagStack.d.ts.map +1 -0
  57. package/dist/hooks/useScrubMarkers.d.ts +12 -0
  58. package/dist/hooks/useScrubMarkers.d.ts.map +1 -0
  59. package/dist/hooks/useXAxis.d.ts +1 -1
  60. package/dist/hooks/useXAxis.d.ts.map +1 -1
  61. package/dist/hooks/useYAxisScaleGesture.d.ts +34 -0
  62. package/dist/hooks/useYAxisScaleGesture.d.ts.map +1 -0
  63. package/dist/index.d.ts +1 -1
  64. package/dist/index.d.ts.map +1 -1
  65. package/dist/math/axisBadgeLayout.d.ts +16 -0
  66. package/dist/math/axisBadgeLayout.d.ts.map +1 -0
  67. package/dist/math/markers.d.ts +3 -0
  68. package/dist/math/markers.d.ts.map +1 -1
  69. package/dist/math/range.d.ts +1 -1
  70. package/dist/math/range.d.ts.map +1 -1
  71. package/dist/math/rangeAnimation.d.ts +4 -0
  72. package/dist/math/rangeAnimation.d.ts.map +1 -0
  73. package/dist/math/referenceDrag.d.ts +17 -5
  74. package/dist/math/referenceDrag.d.ts.map +1 -1
  75. package/dist/math/referenceGroup.d.ts +2 -2
  76. package/dist/math/referenceTagStack.d.ts +36 -0
  77. package/dist/math/referenceTagStack.d.ts.map +1 -0
  78. package/dist/math/scrubMarkers.d.ts +12 -0
  79. package/dist/math/scrubMarkers.d.ts.map +1 -0
  80. package/dist/types.d.ts +240 -30
  81. package/dist/types.d.ts.map +1 -1
  82. package/package.json +1 -1
  83. package/src/components/CustomReferenceLineOverlay.tsx +50 -8
  84. package/src/components/CustomTooltipOverlay.tsx +5 -1
  85. package/src/components/LiveChart.tsx +563 -200
  86. package/src/components/LiveChartSeries.tsx +117 -13
  87. package/src/components/ReferenceLineOverlay.tsx +62 -26
  88. package/src/components/ReferenceValueBadge.tsx +102 -0
  89. package/src/components/XAxisOverlay.tsx +104 -1
  90. package/src/core/liveChartEngineTick.ts +66 -10
  91. package/src/core/liveChartSeriesEngineTick.ts +55 -5
  92. package/src/core/resolveConfig.ts +95 -2
  93. package/src/core/useLiveChartEngine.ts +53 -11
  94. package/src/core/useLiveChartSeriesEngine.ts +11 -1
  95. package/src/draw/grid.ts +2 -2
  96. package/src/draw/line.ts +23 -1
  97. package/src/hooks/crosshairShared.ts +85 -1
  98. package/src/hooks/referenceBadgeFont.ts +35 -0
  99. package/src/hooks/resolveChartLayout.ts +17 -0
  100. package/src/hooks/useBadge.ts +44 -5
  101. package/src/hooks/useChartSkiaFont.ts +1 -1
  102. package/src/hooks/useCrosshair.ts +446 -300
  103. package/src/hooks/useCrosshairSeries.ts +29 -10
  104. package/src/hooks/useLatestCallback.ts +15 -0
  105. package/src/hooks/useMarkers.ts +51 -39
  106. package/src/hooks/usePanScroll.ts +155 -127
  107. package/src/hooks/usePinchZoom.ts +84 -63
  108. package/src/hooks/useReferenceDrag.ts +395 -146
  109. package/src/hooks/useReferenceLine.ts +453 -277
  110. package/src/hooks/useReferenceLineGrouping.ts +72 -0
  111. package/src/hooks/useReferenceLinePress.ts +121 -53
  112. package/src/hooks/useReferenceTagStack.ts +81 -0
  113. package/src/hooks/useScrubMarkers.ts +79 -0
  114. package/src/hooks/useXAxis.ts +11 -2
  115. package/src/hooks/useYAxisScaleGesture.ts +263 -0
  116. package/src/index.ts +11 -0
  117. package/src/math/axisBadgeLayout.ts +37 -0
  118. package/src/math/markers.ts +28 -3
  119. package/src/math/range.ts +35 -0
  120. package/src/math/rangeAnimation.ts +28 -0
  121. package/src/math/referenceDrag.ts +21 -4
  122. package/src/math/referenceGroup.ts +2 -2
  123. package/src/math/referenceTagStack.ts +112 -0
  124. package/src/math/scrubMarkers.ts +55 -0
  125. package/src/types.ts +246 -30
@@ -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 JSON.stringify({
196
- time,
197
- x,
198
- y: dotY,
199
- primary: r.primary,
200
- series: r.seriesValues,
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
- if (curr === prev) return;
214
- const p = JSON.parse(curr) as {
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
+ }
@@ -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 = Gesture.Tap().onEnd(
137
- /* istanbul ignore next -- gesture worklet runs on UI thread, not in Jest */ (
138
- e,
139
- ) => {
140
- "worklet";
141
- const proj = projected.get();
142
- const idx = nearestMarkerIndex(proj, e.x, e.y, hitRadius);
143
- if (idx < 0) {
144
- runOnJS(emitPress)(null);
145
- return;
146
- }
147
- const ms = markers.get();
148
- const m = ms[idx];
149
- const p = proj[idx];
150
- const isGrouped = p.isGrouped;
151
- // Collapsed cluster: surface the whole bucket so the consumer can list it.
152
- const members = isGrouped ? clusterMembers(ms, proj, idx) : undefined;
153
- runOnJS(emitPress)({
154
- marker: m,
155
- point: { x: p.x, y: p.y },
156
- index: idx,
157
- isGrouped,
158
- members,
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
- // Lets a coexisting gesture (e.g. the scrub-action tap) defer to a marker
164
- // under the finger instead of acting on it.
165
- const hitTest =
166
- /* istanbul ignore next -- worklet, runs on the UI thread, not in Jest */ (
167
- x: number,
168
- y: number,
169
- ) => {
170
- "worklet";
171
- return nearestMarkerIndex(projected.get(), x, y, hitRadius) >= 0;
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
- 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
  }