react-native-vroom-chart 0.1.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/LICENSE +21 -0
- package/README.md +27 -0
- package/android/README.md +7 -0
- package/cpp/README.md +11 -0
- package/cpp/VroomChartHostObject.cpp +458 -0
- package/cpp/VroomChartHostObject.h +36 -0
- package/cpp/VroomJsiInstaller.cpp +69 -0
- package/cpp/VroomJsiInstaller.h +10 -0
- package/cpp/VroomSkiaContext.cpp +25 -0
- package/cpp/VroomSkiaContext.h +30 -0
- package/cpp/_core_include/vroom/vroom_chart.h +195 -0
- package/cpp/_core_src/candles.cpp +74 -0
- package/cpp/_core_src/candles.h +34 -0
- package/cpp/_core_src/chart.cpp +317 -0
- package/cpp/_core_src/chart.h +167 -0
- package/cpp/_core_src/chart_facade.cpp +570 -0
- package/cpp/_core_src/chart_internal.h +30 -0
- package/cpp/_core_src/crosshair.cpp +65 -0
- package/cpp/_core_src/crosshair.h +32 -0
- package/cpp/_core_src/fonts.cpp +22 -0
- package/cpp/_core_src/fonts.h +25 -0
- package/cpp/_core_src/labels.cpp +340 -0
- package/cpp/_core_src/labels.h +85 -0
- package/cpp/_core_src/ma.cpp +53 -0
- package/cpp/_core_src/ma.h +39 -0
- package/cpp/_core_src/ma_overlay.cpp +73 -0
- package/cpp/_core_src/ma_overlay.h +42 -0
- package/cpp/_core_src/macd.cpp +68 -0
- package/cpp/_core_src/macd.h +29 -0
- package/cpp/_core_src/macd_pane.cpp +199 -0
- package/cpp/_core_src/macd_pane.h +41 -0
- package/cpp/_core_src/price_indicator.cpp +106 -0
- package/cpp/_core_src/price_indicator.h +29 -0
- package/cpp/_core_src/rsi.cpp +70 -0
- package/cpp/_core_src/rsi.h +32 -0
- package/cpp/_core_src/rsi_pane.cpp +167 -0
- package/cpp/_core_src/rsi_pane.h +39 -0
- package/cpp/_core_src/theme.cpp +41 -0
- package/cpp/_core_src/theme.h +23 -0
- package/cpp/_core_src/ticks.cpp +49 -0
- package/cpp/_core_src/ticks.h +30 -0
- package/cpp/_core_src/viewport.cpp +141 -0
- package/cpp/_core_src/viewport.h +100 -0
- package/cpp/_core_src/volume.cpp +70 -0
- package/cpp/_core_src/volume.h +34 -0
- package/cpp/_core_src/vwap.cpp +51 -0
- package/cpp/_core_src/vwap.h +27 -0
- package/ios/README.md +7 -0
- package/ios/VroomChartModule.h +11 -0
- package/ios/VroomChartModule.mm +44 -0
- package/lib/index.d.mts +185 -0
- package/lib/index.d.ts +185 -0
- package/lib/index.js +429 -0
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +396 -0
- package/lib/index.mjs.map +1 -0
- package/package.json +75 -0
- package/react-native-vroom-chart.podspec +79 -0
- package/src/NativeVroomChart.ts +12 -0
- package/src/VroomChart.tsx +382 -0
- package/src/index.ts +14 -0
- package/src/jsi.d.ts +128 -0
- package/src/packCandles.ts +24 -0
- package/src/theme.ts +43 -0
- package/src/types.ts +27 -0
- package/src/useChartCore.ts +135 -0
package/lib/index.mjs
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
// src/VroomChart.tsx
|
|
2
|
+
import React, { useEffect as useEffect2, useRef as useRef2, useCallback, useState as useState2, useMemo } from "react";
|
|
3
|
+
import { View } from "react-native";
|
|
4
|
+
import { Canvas, Picture, Skia } from "@shopify/react-native-skia";
|
|
5
|
+
import {
|
|
6
|
+
Gesture,
|
|
7
|
+
GestureDetector,
|
|
8
|
+
GestureHandlerRootView
|
|
9
|
+
} from "react-native-gesture-handler";
|
|
10
|
+
import { useSharedValue } from "react-native-reanimated";
|
|
11
|
+
|
|
12
|
+
// src/useChartCore.ts
|
|
13
|
+
import { useEffect, useRef, useState } from "react";
|
|
14
|
+
|
|
15
|
+
// src/NativeVroomChart.ts
|
|
16
|
+
import { TurboModuleRegistry } from "react-native";
|
|
17
|
+
var NativeVroomChart_default = TurboModuleRegistry.getEnforcing("VroomChartModule");
|
|
18
|
+
|
|
19
|
+
// src/packCandles.ts
|
|
20
|
+
var BYTES_PER_CANDLE = 48;
|
|
21
|
+
function packCandles(candles) {
|
|
22
|
+
const buf = new ArrayBuffer(candles.length * BYTES_PER_CANDLE);
|
|
23
|
+
const view = new DataView(buf);
|
|
24
|
+
for (let i = 0; i < candles.length; i++) {
|
|
25
|
+
const c = candles[i];
|
|
26
|
+
const off = i * BYTES_PER_CANDLE;
|
|
27
|
+
view.setBigInt64(off, BigInt(c.timeMs), true);
|
|
28
|
+
view.setFloat64(off + 8, c.open, true);
|
|
29
|
+
view.setFloat64(off + 16, c.high, true);
|
|
30
|
+
view.setFloat64(off + 24, c.low, true);
|
|
31
|
+
view.setFloat64(off + 32, c.close, true);
|
|
32
|
+
view.setFloat64(off + 40, c.volume, true);
|
|
33
|
+
}
|
|
34
|
+
return buf;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/theme.ts
|
|
38
|
+
var COLOR_KEYS = {
|
|
39
|
+
background: 0,
|
|
40
|
+
// VROOM_COLOR_BACKGROUND
|
|
41
|
+
bull: 1,
|
|
42
|
+
// VROOM_COLOR_BULL
|
|
43
|
+
bear: 2,
|
|
44
|
+
// VROOM_COLOR_BEAR
|
|
45
|
+
grid: 4,
|
|
46
|
+
// VROOM_COLOR_GRID
|
|
47
|
+
axisText: 5,
|
|
48
|
+
// VROOM_COLOR_AXIS_TEXT
|
|
49
|
+
crosshair: 6,
|
|
50
|
+
// VROOM_COLOR_CROSSHAIR
|
|
51
|
+
crosshairTarget: 9
|
|
52
|
+
// VROOM_COLOR_CROSSHAIR_TARGET
|
|
53
|
+
};
|
|
54
|
+
function parseColor(value) {
|
|
55
|
+
if (typeof value === "number") {
|
|
56
|
+
return Number.isFinite(value) ? value >>> 0 : null;
|
|
57
|
+
}
|
|
58
|
+
let s = value.trim();
|
|
59
|
+
if (s.startsWith("#")) s = s.slice(1);
|
|
60
|
+
if (s.length === 6) s = `ff${s}`;
|
|
61
|
+
if (s.length !== 8 || !/^[0-9a-fA-F]{8}$/.test(s)) return null;
|
|
62
|
+
return parseInt(s, 16) >>> 0;
|
|
63
|
+
}
|
|
64
|
+
function applyTheme(handle, theme) {
|
|
65
|
+
Object.keys(COLOR_KEYS).forEach((field) => {
|
|
66
|
+
const value = theme[field];
|
|
67
|
+
if (value == null) return;
|
|
68
|
+
const argb = parseColor(value);
|
|
69
|
+
if (argb == null) return;
|
|
70
|
+
handle.setColor(COLOR_KEYS[field], argb);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/useChartCore.ts
|
|
75
|
+
var MA_SOURCES = [
|
|
76
|
+
"close",
|
|
77
|
+
"open",
|
|
78
|
+
"high",
|
|
79
|
+
"low",
|
|
80
|
+
"hl2",
|
|
81
|
+
"hlc3",
|
|
82
|
+
"ohlc4"
|
|
83
|
+
];
|
|
84
|
+
function overlayToNumeric(o) {
|
|
85
|
+
const srcIdx = o.source ? MA_SOURCES.indexOf(o.source) : 0;
|
|
86
|
+
return {
|
|
87
|
+
kind: o.kind === "ema" ? 1 : 0,
|
|
88
|
+
period: o.length,
|
|
89
|
+
source: srcIdx < 0 ? 0 : srcIdx,
|
|
90
|
+
color: (o.color != null ? parseColor(o.color) : null) ?? 4280902399,
|
|
91
|
+
width: o.width ?? 1.5
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
var installed = false;
|
|
95
|
+
function ensureInstalled() {
|
|
96
|
+
if (installed) return;
|
|
97
|
+
const ok = NativeVroomChart_default.install();
|
|
98
|
+
if (!ok) throw new Error("VroomChartModule.install() returned false");
|
|
99
|
+
if (typeof globalThis.VroomChartJSI === "undefined") {
|
|
100
|
+
throw new Error("global.VroomChartJSI undefined after install()");
|
|
101
|
+
}
|
|
102
|
+
installed = true;
|
|
103
|
+
}
|
|
104
|
+
function useChartCore(candles, size, visibleRange, theme, rsi, macd, movingAverages, vwap) {
|
|
105
|
+
const handleRef = useRef(null);
|
|
106
|
+
const [picture, setPicture] = useState(null);
|
|
107
|
+
if (!handleRef.current && size.width > 0 && size.height > 0) {
|
|
108
|
+
ensureInstalled();
|
|
109
|
+
handleRef.current = globalThis.VroomChartJSI.create();
|
|
110
|
+
}
|
|
111
|
+
const explicit = visibleRange != null;
|
|
112
|
+
const startMs = visibleRange?.startMs ?? 0;
|
|
113
|
+
const endMs = visibleRange?.endMs ?? 0;
|
|
114
|
+
const themeKey = theme ? JSON.stringify(theme) : "";
|
|
115
|
+
const rsiKey = rsi ? JSON.stringify(rsi) : "";
|
|
116
|
+
const macdKey = macd ? JSON.stringify(macd) : "";
|
|
117
|
+
const maKey = movingAverages ? JSON.stringify(movingAverages) : "";
|
|
118
|
+
const vwapKey = vwap ? JSON.stringify(vwap) : "";
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
const h = handleRef.current;
|
|
121
|
+
if (!h) return;
|
|
122
|
+
h.setSize(size.width, size.height, size.pxRatio ?? 1);
|
|
123
|
+
if (candles.length > 0) {
|
|
124
|
+
h.setCandles(packCandles(candles));
|
|
125
|
+
}
|
|
126
|
+
if (explicit) {
|
|
127
|
+
h.setVisibleRange(startMs, endMs);
|
|
128
|
+
}
|
|
129
|
+
if (theme) {
|
|
130
|
+
applyTheme(h, theme);
|
|
131
|
+
}
|
|
132
|
+
h.setRSI(
|
|
133
|
+
rsi?.enabled ?? false,
|
|
134
|
+
rsi?.period ?? 14,
|
|
135
|
+
rsi?.upperBand ?? 70,
|
|
136
|
+
rsi?.lowerBand ?? 30,
|
|
137
|
+
rsi?.maEnabled ?? true,
|
|
138
|
+
rsi?.maPeriod ?? 14
|
|
139
|
+
);
|
|
140
|
+
h.setMACD(
|
|
141
|
+
macd?.enabled ?? false,
|
|
142
|
+
macd?.fast ?? 12,
|
|
143
|
+
macd?.slow ?? 26,
|
|
144
|
+
macd?.signal ?? 9
|
|
145
|
+
);
|
|
146
|
+
h.setOverlays((movingAverages ?? []).map(overlayToNumeric));
|
|
147
|
+
h.setVWAP(
|
|
148
|
+
vwap?.enabled ?? false,
|
|
149
|
+
vwap?.resetMinutes ?? 0,
|
|
150
|
+
(vwap?.color != null ? parseColor(vwap.color) : null) ?? 4278238420,
|
|
151
|
+
vwap?.width ?? 1.5
|
|
152
|
+
);
|
|
153
|
+
setPicture(h.render());
|
|
154
|
+
}, [candles, size.width, size.height, size.pxRatio, explicit, startMs, endMs, themeKey, rsiKey, macdKey, maKey, vwapKey]);
|
|
155
|
+
return { handle: handleRef.current, picture };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/VroomChart.tsx
|
|
159
|
+
function VroomChart(props) {
|
|
160
|
+
const {
|
|
161
|
+
candles,
|
|
162
|
+
width: widthProp,
|
|
163
|
+
height: heightProp,
|
|
164
|
+
style,
|
|
165
|
+
visibleRange,
|
|
166
|
+
theme,
|
|
167
|
+
rsi,
|
|
168
|
+
macd,
|
|
169
|
+
movingAverages,
|
|
170
|
+
vwap,
|
|
171
|
+
crosshairOffset = 40,
|
|
172
|
+
onCrosshair,
|
|
173
|
+
onViewportChange
|
|
174
|
+
} = props;
|
|
175
|
+
const [measured, setMeasured] = useState2({ width: 0, height: 0 });
|
|
176
|
+
const width = widthProp ?? measured.width;
|
|
177
|
+
const height = heightProp ?? measured.height;
|
|
178
|
+
const onLayout = useCallback((e) => {
|
|
179
|
+
const w = Math.round(e.nativeEvent.layout.width);
|
|
180
|
+
const h = Math.round(e.nativeEvent.layout.height);
|
|
181
|
+
setMeasured(
|
|
182
|
+
(prev) => prev.width === w && prev.height === h ? prev : { width: w, height: h }
|
|
183
|
+
);
|
|
184
|
+
}, []);
|
|
185
|
+
const { handle, picture } = useChartCore(
|
|
186
|
+
candles,
|
|
187
|
+
{ width, height },
|
|
188
|
+
visibleRange,
|
|
189
|
+
theme,
|
|
190
|
+
rsi,
|
|
191
|
+
macd,
|
|
192
|
+
movingAverages,
|
|
193
|
+
vwap
|
|
194
|
+
);
|
|
195
|
+
const emptyPicture = useMemo(() => {
|
|
196
|
+
const rec = Skia.PictureRecorder();
|
|
197
|
+
rec.beginRecording(Skia.XYWHRect(0, 0, 1, 1));
|
|
198
|
+
return rec.finishRecordingAsPicture();
|
|
199
|
+
}, []);
|
|
200
|
+
const pictureSV = useSharedValue(emptyPicture);
|
|
201
|
+
const crosshairActive = useRef2(false);
|
|
202
|
+
const lastCrosshairTime = useRef2(null);
|
|
203
|
+
useEffect2(() => {
|
|
204
|
+
if (picture) pictureSV.value = picture;
|
|
205
|
+
}, [picture, pictureSV]);
|
|
206
|
+
const decayRaf = useRef2(null);
|
|
207
|
+
const cancelDecay = useCallback(() => {
|
|
208
|
+
if (decayRaf.current != null) {
|
|
209
|
+
cancelAnimationFrame(decayRaf.current);
|
|
210
|
+
decayRaf.current = null;
|
|
211
|
+
}
|
|
212
|
+
}, []);
|
|
213
|
+
useEffect2(() => cancelDecay, [cancelDecay]);
|
|
214
|
+
const animRaf = useRef2(null);
|
|
215
|
+
const animTick = useCallback(() => {
|
|
216
|
+
animRaf.current = null;
|
|
217
|
+
if (!handle) return;
|
|
218
|
+
const next = handle.render();
|
|
219
|
+
if (next) pictureSV.value = next;
|
|
220
|
+
if (handle.isAnimating()) {
|
|
221
|
+
animRaf.current = requestAnimationFrame(animTick);
|
|
222
|
+
}
|
|
223
|
+
}, [handle, pictureSV]);
|
|
224
|
+
const maybeStartAnim = useCallback(() => {
|
|
225
|
+
if (animRaf.current != null) return;
|
|
226
|
+
if (!handle?.isAnimating()) return;
|
|
227
|
+
animRaf.current = requestAnimationFrame(animTick);
|
|
228
|
+
}, [handle, animTick]);
|
|
229
|
+
useEffect2(() => {
|
|
230
|
+
return () => {
|
|
231
|
+
if (animRaf.current != null) {
|
|
232
|
+
cancelAnimationFrame(animRaf.current);
|
|
233
|
+
animRaf.current = null;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
}, []);
|
|
237
|
+
const hitAxis = useCallback(
|
|
238
|
+
(x, y) => {
|
|
239
|
+
if (!handle) return "chart";
|
|
240
|
+
const { yAxisWidth, xAxisHeight, indicatorHeight } = handle.getAxisMetrics();
|
|
241
|
+
if (x > width - yAxisWidth) return "price-axis";
|
|
242
|
+
if (y > height - xAxisHeight) return "time-axis";
|
|
243
|
+
if (indicatorHeight > 0 && y > height - xAxisHeight - indicatorHeight) {
|
|
244
|
+
return "indicator";
|
|
245
|
+
}
|
|
246
|
+
return "chart";
|
|
247
|
+
},
|
|
248
|
+
[handle, width, height]
|
|
249
|
+
);
|
|
250
|
+
const panMode = useRef2(
|
|
251
|
+
"chart"
|
|
252
|
+
);
|
|
253
|
+
const pan = Gesture.Pan().runOnJS(true).maxPointers(1).onStart((e) => {
|
|
254
|
+
cancelDecay();
|
|
255
|
+
panMode.current = hitAxis(e.x, e.y);
|
|
256
|
+
}).onChange((e) => {
|
|
257
|
+
if (!handle) return;
|
|
258
|
+
let next = null;
|
|
259
|
+
if (panMode.current === "price-axis") {
|
|
260
|
+
next = handle.scalePriceAxis(e.changeY);
|
|
261
|
+
} else if (panMode.current === "time-axis") {
|
|
262
|
+
next = handle.scaleTimeAxis(e.changeX);
|
|
263
|
+
} else if (panMode.current === "indicator") {
|
|
264
|
+
next = handle.pan(e.changeX, 0);
|
|
265
|
+
} else if (crosshairActive.current) {
|
|
266
|
+
const ch = handle.setCrosshair(e.x, e.y - crosshairOffset);
|
|
267
|
+
if (ch) pictureSV.value = ch;
|
|
268
|
+
const c = handle.getCrosshairCandle();
|
|
269
|
+
const t = c?.timeMs ?? null;
|
|
270
|
+
if (t !== lastCrosshairTime.current) {
|
|
271
|
+
lastCrosshairTime.current = t;
|
|
272
|
+
onCrosshair?.({ active: true, candle: c, reason: "move" });
|
|
273
|
+
}
|
|
274
|
+
return;
|
|
275
|
+
} else {
|
|
276
|
+
next = handle.translate(e.changeX, e.changeY);
|
|
277
|
+
}
|
|
278
|
+
if (next) pictureSV.value = next;
|
|
279
|
+
maybeStartAnim();
|
|
280
|
+
}).onEnd((e) => {
|
|
281
|
+
if (!handle) return;
|
|
282
|
+
if (panMode.current === "chart" && crosshairActive.current) return;
|
|
283
|
+
onViewportChange?.(0, 0);
|
|
284
|
+
if (panMode.current !== "chart" && panMode.current !== "indicator") return;
|
|
285
|
+
let velocity = e.velocityX;
|
|
286
|
+
const MIN_LAUNCH = 80;
|
|
287
|
+
const MIN_STOP = 8;
|
|
288
|
+
const HALF_LIFE_S = 0.35;
|
|
289
|
+
if (Math.abs(velocity) < MIN_LAUNCH) return;
|
|
290
|
+
let lastTime = performance.now();
|
|
291
|
+
const tick = () => {
|
|
292
|
+
const now = performance.now();
|
|
293
|
+
const dt = (now - lastTime) / 1e3;
|
|
294
|
+
lastTime = now;
|
|
295
|
+
velocity *= Math.pow(0.5, dt / HALF_LIFE_S);
|
|
296
|
+
const dx = velocity * dt;
|
|
297
|
+
const next = handle.pan(dx, 0);
|
|
298
|
+
if (next) pictureSV.value = next;
|
|
299
|
+
maybeStartAnim();
|
|
300
|
+
if (Math.abs(velocity) > MIN_STOP) {
|
|
301
|
+
decayRaf.current = requestAnimationFrame(tick);
|
|
302
|
+
} else {
|
|
303
|
+
decayRaf.current = null;
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
decayRaf.current = requestAnimationFrame(tick);
|
|
307
|
+
});
|
|
308
|
+
const MIN_SPAN = 24;
|
|
309
|
+
const AXIS_RATIO = 0.5;
|
|
310
|
+
const pinchStart = useRef2({
|
|
311
|
+
spanX: 1,
|
|
312
|
+
spanY: 1,
|
|
313
|
+
ratioX: 1,
|
|
314
|
+
ratioY: 1,
|
|
315
|
+
enableX: false,
|
|
316
|
+
enableY: false
|
|
317
|
+
});
|
|
318
|
+
const pinch = Gesture.Pinch().runOnJS(true).onTouchesDown((e) => {
|
|
319
|
+
if (e.numberOfTouches < 2) return;
|
|
320
|
+
const [a, b] = e.allTouches;
|
|
321
|
+
const spanX = Math.abs(a.x - b.x);
|
|
322
|
+
const spanY = Math.abs(a.y - b.y);
|
|
323
|
+
pinchStart.current = {
|
|
324
|
+
spanX,
|
|
325
|
+
spanY,
|
|
326
|
+
ratioX: 1,
|
|
327
|
+
ratioY: 1,
|
|
328
|
+
enableX: spanX >= MIN_SPAN && spanX >= spanY * AXIS_RATIO,
|
|
329
|
+
enableY: spanY >= MIN_SPAN && spanY >= spanX * AXIS_RATIO
|
|
330
|
+
};
|
|
331
|
+
}).onTouchesMove((e) => {
|
|
332
|
+
if (!handle || crosshairActive.current) return;
|
|
333
|
+
if (e.numberOfTouches < 2) return;
|
|
334
|
+
const [a, b] = e.allTouches;
|
|
335
|
+
const start = pinchStart.current;
|
|
336
|
+
const focalX = (a.x + b.x) * 0.5;
|
|
337
|
+
const focalY = (a.y + b.y) * 0.5;
|
|
338
|
+
let frameX = 1;
|
|
339
|
+
if (start.enableX) {
|
|
340
|
+
const ratioX = Math.max(Math.abs(a.x - b.x), MIN_SPAN) / start.spanX;
|
|
341
|
+
frameX = ratioX / start.ratioX;
|
|
342
|
+
start.ratioX = ratioX;
|
|
343
|
+
}
|
|
344
|
+
let frameY = 1;
|
|
345
|
+
if (start.enableY) {
|
|
346
|
+
const ratioY = Math.max(Math.abs(a.y - b.y), MIN_SPAN) / start.spanY;
|
|
347
|
+
frameY = ratioY / start.ratioY;
|
|
348
|
+
start.ratioY = ratioY;
|
|
349
|
+
}
|
|
350
|
+
if (frameX === 1 && frameY === 1) return;
|
|
351
|
+
const next = handle.zoom(frameX, frameY, focalX, focalY);
|
|
352
|
+
if (next) pictureSV.value = next;
|
|
353
|
+
maybeStartAnim();
|
|
354
|
+
});
|
|
355
|
+
const longPress = Gesture.LongPress().runOnJS(true).onStart((e) => {
|
|
356
|
+
if (!handle) return;
|
|
357
|
+
if (hitAxis(e.x, e.y) !== "chart") return;
|
|
358
|
+
cancelDecay();
|
|
359
|
+
crosshairActive.current = true;
|
|
360
|
+
const ch = handle.setCrosshair(e.x, e.y - crosshairOffset);
|
|
361
|
+
if (ch) pictureSV.value = ch;
|
|
362
|
+
const c = handle.getCrosshairCandle();
|
|
363
|
+
lastCrosshairTime.current = c?.timeMs ?? null;
|
|
364
|
+
onCrosshair?.({ active: true, candle: c, reason: "show" });
|
|
365
|
+
});
|
|
366
|
+
const tap = Gesture.Tap().runOnJS(true).onStart((e) => {
|
|
367
|
+
if (!handle || !crosshairActive.current) return;
|
|
368
|
+
if (hitAxis(e.x, e.y) !== "chart") return;
|
|
369
|
+
crosshairActive.current = false;
|
|
370
|
+
const ch = handle.clearCrosshair();
|
|
371
|
+
if (ch) pictureSV.value = ch;
|
|
372
|
+
lastCrosshairTime.current = null;
|
|
373
|
+
onCrosshair?.({ active: false, candle: null, reason: "hide" });
|
|
374
|
+
});
|
|
375
|
+
const gesture = Gesture.Simultaneous(pan, pinch, longPress, tap);
|
|
376
|
+
return /* @__PURE__ */ React.createElement(
|
|
377
|
+
GestureHandlerRootView,
|
|
378
|
+
{
|
|
379
|
+
onLayout,
|
|
380
|
+
style: [
|
|
381
|
+
{ width: widthProp, height: heightProp },
|
|
382
|
+
widthProp == null && heightProp == null ? { flex: 1 } : null,
|
|
383
|
+
style
|
|
384
|
+
]
|
|
385
|
+
},
|
|
386
|
+
/* @__PURE__ */ React.createElement(GestureDetector, { gesture }, /* @__PURE__ */ React.createElement(View, { style: { flex: 1 } }, /* @__PURE__ */ React.createElement(Canvas, { style: { flex: 1 } }, width > 0 && height > 0 ? (
|
|
387
|
+
// pictureSV is always a valid picture (seeded empty, never null),
|
|
388
|
+
// so RN-Skia's UI-thread reader never sees null.
|
|
389
|
+
/* @__PURE__ */ React.createElement(Picture, { picture: pictureSV })
|
|
390
|
+
) : null)))
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
export {
|
|
394
|
+
VroomChart
|
|
395
|
+
};
|
|
396
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/VroomChart.tsx","../src/useChartCore.ts","../src/NativeVroomChart.ts","../src/packCandles.ts","../src/theme.ts"],"sourcesContent":["// VroomChart — Phase 3.\n//\n// Owns a SharedValue<SkPicture> driven by:\n// - useChartCore's \"initial\" picture (when data/size/range change), AND\n// - Pan gesture callbacks that call handle.pan(dx, dy) → fresh picture.\n//\n// Reanimated 4 + RN-Skia 2 propagate SharedValue<SkPicture> changes to\n// <Picture> without a React re-render, so gesture-driven redraws are cheap.\n//\n// Gestures run on the JS thread for now (`runOnJS(true)`) — installing the\n// JSI bindings on the worklet runtime is a later perf optimization.\n\nimport React, { useEffect, useRef, useCallback, useState, useMemo } from 'react';\nimport { View, type LayoutChangeEvent } from 'react-native';\nimport { Canvas, Picture, Skia, type SkPicture } from '@shopify/react-native-skia';\nimport {\n Gesture,\n GestureDetector,\n GestureHandlerRootView,\n} from 'react-native-gesture-handler';\nimport { useSharedValue } from 'react-native-reanimated';\n\nimport { useChartCore } from './useChartCore';\nimport type { VroomChartProps } from './types';\nimport './jsi.d';\n\n/**\n * Skia-rendered candlestick chart. Pass OHLCV `candles` and size it via `style`\n * (it fills its parent by default). Pan to scroll, pinch to zoom, drag the\n * price/time axes to rescale, and long-press for the crosshair. Optional\n * indicators (`rsi`, `macd`, `movingAverages`, `vwap`), colors (`theme`), and\n * events (`onCrosshair`, `onViewportChange`) are configured through props.\n *\n * @see {@link VroomChartProps} for the full prop reference.\n */\nexport function VroomChart(props: VroomChartProps) {\n const {\n candles,\n width: widthProp,\n height: heightProp,\n style,\n visibleRange,\n theme,\n rsi,\n macd,\n movingAverages,\n vwap,\n crosshairOffset = 40,\n onCrosshair,\n onViewportChange,\n } = props;\n\n // Fill the parent by default: measure via onLayout. Explicit width/height\n // props (if given) win per-axis. Until the first layout, dims are 0 and we\n // render nothing (one frame).\n const [measured, setMeasured] = useState({ width: 0, height: 0 });\n const width = widthProp ?? measured.width;\n const height = heightProp ?? measured.height;\n\n const onLayout = useCallback((e: LayoutChangeEvent) => {\n const w = Math.round(e.nativeEvent.layout.width);\n const h = Math.round(e.nativeEvent.layout.height);\n setMeasured((prev) =>\n prev.width === w && prev.height === h ? prev : { width: w, height: h },\n );\n }, []);\n\n const { handle, picture } = useChartCore(\n candles,\n { width, height },\n visibleRange,\n theme,\n rsi,\n macd,\n movingAverages,\n vwap,\n );\n\n // RN-Skia's recorder reads this SharedValue on the UI/render runtime, a beat\n // behind JS-thread writes. If it ever reads null it throws (\"Invalid prop\n // value for SkTextBlob received\" — RN-Skia's mislabeled SkPicture error), so\n // we seed it with an empty picture and *never* assign null into it.\n const emptyPicture = useMemo(() => {\n const rec = Skia.PictureRecorder();\n rec.beginRecording(Skia.XYWHRect(0, 0, 1, 1));\n return rec.finishRecordingAsPicture();\n }, []);\n const pictureSV = useSharedValue<SkPicture>(emptyPicture);\n\n // When the crosshair is showing, pan moves it (instead of scrolling) and\n // pinch is disabled. A ref (not state) so gesture callbacks read it\n // synchronously without re-subscribing. Tap dismisses it.\n const crosshairActive = useRef(false);\n\n // timeMs of the candle last reported through onCrosshair, so a drag fires a\n // 'move' event only when it crosses into a *different* candle (one per\n // candle, not per frame). Null while the crosshair is hidden.\n const lastCrosshairTime = useRef<number | null>(null);\n\n // Sync the initial picture from useChartCore into the SV whenever it\n // refreshes (data load, size change, externally-controlled range change).\n // Only ever assign a non-null picture (see emptyPicture note above).\n useEffect(() => {\n if (picture) pictureSV.value = picture;\n }, [picture, pictureSV]);\n\n // Momentum scroll. After Pan ends with non-trivial velocity, we run a RAF\n // loop that calls handle.pan(dx, 0) each frame with an exponentially\n // decaying velocity. A new pan (or unmount) cancels the loop.\n const decayRaf = useRef<number | null>(null);\n const cancelDecay = useCallback(() => {\n if (decayRaf.current != null) {\n cancelAnimationFrame(decayRaf.current);\n decayRaf.current = null;\n }\n }, []);\n useEffect(() => cancelDecay, [cancelDecay]);\n\n // Axis-label fade animation loop. When a gesture changes which labels are\n // active, the C++ side starts ramping their opacities. We keep calling\n // render() on every frame until handle.isAnimating() returns false. The\n // loop is started by gesture callbacks (and the momentum tick) after they\n // update the picture, and self-stops when fades settle.\n const animRaf = useRef<number | null>(null);\n const animTick = useCallback(() => {\n animRaf.current = null;\n if (!handle) return;\n const next = handle.render();\n if (next) pictureSV.value = next;\n if (handle.isAnimating()) {\n animRaf.current = requestAnimationFrame(animTick);\n }\n }, [handle, pictureSV]);\n const maybeStartAnim = useCallback(() => {\n if (animRaf.current != null) return;\n if (!handle?.isAnimating()) return;\n animRaf.current = requestAnimationFrame(animTick);\n }, [handle, animTick]);\n useEffect(() => {\n return () => {\n if (animRaf.current != null) {\n cancelAnimationFrame(animRaf.current);\n animRaf.current = null;\n }\n };\n }, []);\n\n // Classifies a touch point into the candle area vs. an axis strip. Axis\n // strips always own their gesture (scale price/time) and take priority over\n // the crosshair: an axis touch never opens, moves, or dismisses it.\n const hitAxis = useCallback(\n (x: number, y: number): 'chart' | 'price-axis' | 'time-axis' | 'indicator' => {\n if (!handle) return 'chart';\n const { yAxisWidth, xAxisHeight, indicatorHeight } =\n handle.getAxisMetrics();\n if (x > width - yAxisWidth) return 'price-axis';\n if (y > height - xAxisHeight) return 'time-axis';\n // The indicator pane sits just above the time-axis strip. A drag here\n // scrolls the candles horizontally (no vertical price change).\n if (indicatorHeight > 0 && y > height - xAxisHeight - indicatorHeight) {\n return 'indicator';\n }\n return 'chart';\n },\n [handle, width, height],\n );\n\n // Pan routes to different C++ mutators depending on where it started: the\n // candle area (chart scroll / crosshair move), the y-axis strip (price\n // scale), the x-axis strip (time scale), or the indicator pane (horizontal\n // scroll only). We classify on onStart.\n const panMode = useRef<'chart' | 'price-axis' | 'time-axis' | 'indicator'>(\n 'chart',\n );\n\n const pan = Gesture.Pan()\n .runOnJS(true)\n .maxPointers(1) // don't fight Pinch's two-finger gesture\n .onStart((e) => {\n cancelDecay();\n // Always classify — an axis drag controls the axis even while the\n // crosshair is up. Only a chart-area drag interacts with the crosshair.\n panMode.current = hitAxis(e.x, e.y);\n })\n .onChange((e) => {\n if (!handle) return;\n let next: ReturnType<typeof handle.pan> = null;\n if (panMode.current === 'price-axis') {\n next = handle.scalePriceAxis(e.changeY);\n } else if (panMode.current === 'time-axis') {\n next = handle.scaleTimeAxis(e.changeX);\n } else if (panMode.current === 'indicator') {\n // Drag in an indicator pane scrolls the candles horizontally only —\n // no vertical price slide (the pane's scale is fixed).\n next = handle.pan(e.changeX, 0);\n } else if (crosshairActive.current) {\n // Chart area + crosshair up → the drag moves the crosshair instead of\n // scrolling. Vertical line tracks the finger x; the dot/horizontal line\n // stay lifted `crosshairOffset` px above the fingertip.\n const ch = handle.setCrosshair(e.x, e.y - crosshairOffset);\n if (ch) pictureSV.value = ch;\n // The line follows the finger every frame (above), but only notify the\n // host when the snapped candle actually changes.\n const c = handle.getCrosshairCandle();\n const t = c?.timeMs ?? null;\n if (t !== lastCrosshairTime.current) {\n lastCrosshairTime.current = t;\n onCrosshair?.({ active: true, candle: c, reason: 'move' });\n }\n return;\n } else {\n // Chart area: 1-finger drag translates both axes. Horizontal\n // component scrolls time, vertical component slides price bounds\n // (axes follow). Diagonal works naturally.\n next = handle.translate(e.changeX, e.changeY);\n }\n if (next) pictureSV.value = next;\n maybeStartAnim();\n })\n .onEnd((e) => {\n if (!handle) return;\n // A chart-area drag with the crosshair up just moved the crosshair —\n // nothing about the viewport changed, and no momentum.\n if (panMode.current === 'chart' && crosshairActive.current) return;\n onViewportChange?.(0, 0);\n\n // Axis drags don't get momentum — they're a precise size adjustment.\n // Chart and indicator-pane drags both get horizontal fling momentum.\n if (panMode.current !== 'chart' && panMode.current !== 'indicator') return;\n\n let velocity = e.velocityX; // px/s\n const MIN_LAUNCH = 80; // ignore tiny flicks\n const MIN_STOP = 8; // px/s — stop threshold\n const HALF_LIFE_S = 0.35; // velocity halves every 0.35s\n if (Math.abs(velocity) < MIN_LAUNCH) return;\n\n let lastTime = performance.now();\n const tick = () => {\n const now = performance.now();\n const dt = (now - lastTime) / 1000;\n lastTime = now;\n\n // Frame-time-independent exponential decay.\n velocity *= Math.pow(0.5, dt / HALF_LIFE_S);\n const dx = velocity * dt;\n const next = handle.pan(dx, 0);\n if (next) pictureSV.value = next;\n maybeStartAnim();\n\n if (Math.abs(velocity) > MIN_STOP) {\n decayRaf.current = requestAnimationFrame(tick);\n } else {\n decayRaf.current = null;\n }\n };\n decayRaf.current = requestAnimationFrame(tick);\n });\n\n // Directional pinch. A single Pinch scale is uniform, so we read the two\n // touch points and track their horizontal/vertical spans independently: a\n // vertical pinch scales price (y), a horizontal pinch scales the time window\n // (x), and a diagonal pinch does both. An axis whose initial span is tiny\n // (fingers ~collinear on that axis) is left alone.\n // Lock the scalable axes at gesture start by orientation: an axis only\n // scales if its initial span is meaningful AND at least AXIS_RATIO of the\n // other axis. This keeps a vertical pinch from ever touching x (and vice\n // versa) — critical because during a vertical pinch the fingers' x-coords\n // drift and cross, sending spanX through ~0 and otherwise exploding frameX.\n const MIN_SPAN = 24; // px — minimum span for an axis to scale at all\n const AXIS_RATIO = 0.5; // axis scales only if its span ≥ this × the other's\n const pinchStart = useRef({\n spanX: 1,\n spanY: 1,\n ratioX: 1,\n ratioY: 1,\n enableX: false,\n enableY: false,\n });\n const pinch = Gesture.Pinch()\n .runOnJS(true)\n .onTouchesDown((e) => {\n if (e.numberOfTouches < 2) return;\n const [a, b] = e.allTouches;\n const spanX = Math.abs(a.x - b.x);\n const spanY = Math.abs(a.y - b.y);\n pinchStart.current = {\n spanX,\n spanY,\n ratioX: 1,\n ratioY: 1,\n enableX: spanX >= MIN_SPAN && spanX >= spanY * AXIS_RATIO,\n enableY: spanY >= MIN_SPAN && spanY >= spanX * AXIS_RATIO,\n };\n })\n .onTouchesMove((e) => {\n if (!handle || crosshairActive.current) return;\n if (e.numberOfTouches < 2) return;\n const [a, b] = e.allTouches;\n const start = pinchStart.current;\n const focalX = (a.x + b.x) * 0.5;\n const focalY = (a.y + b.y) * 0.5;\n\n // Per-frame factor = current cumulative ratio / previous. Floor the\n // current span at MIN_SPAN so a near-zero span (fingers crossing on that\n // axis) can't blow the ratio up.\n let frameX = 1;\n if (start.enableX) {\n const ratioX = Math.max(Math.abs(a.x - b.x), MIN_SPAN) / start.spanX;\n frameX = ratioX / start.ratioX;\n start.ratioX = ratioX;\n }\n let frameY = 1;\n if (start.enableY) {\n const ratioY = Math.max(Math.abs(a.y - b.y), MIN_SPAN) / start.spanY;\n frameY = ratioY / start.ratioY;\n start.ratioY = ratioY;\n }\n if (frameX === 1 && frameY === 1) return;\n\n const next = handle.zoom(frameX, frameY, focalX, focalY);\n if (next) pictureSV.value = next;\n maybeStartAnim();\n });\n\n // Long press shows the crosshair at the press point. A stationary hold never\n // activates `pan` (it needs movement first), so the chart won't scroll under\n // the hold. The dot/horizontal line are lifted above the fingertip.\n const longPress = Gesture.LongPress()\n .runOnJS(true)\n .onStart((e) => {\n if (!handle) return;\n // A long press on an axis strip controls the axis, never the crosshair.\n if (hitAxis(e.x, e.y) !== 'chart') return;\n cancelDecay();\n crosshairActive.current = true;\n const ch = handle.setCrosshair(e.x, e.y - crosshairOffset);\n if (ch) pictureSV.value = ch;\n const c = handle.getCrosshairCandle();\n lastCrosshairTime.current = c?.timeMs ?? null;\n onCrosshair?.({ active: true, candle: c, reason: 'show' });\n });\n\n // A tap dismisses the crosshair while it's up; otherwise it's a no-op (so it\n // never interferes with normal pan/pinch).\n const tap = Gesture.Tap()\n .runOnJS(true)\n .onStart((e) => {\n if (!handle || !crosshairActive.current) return;\n // A tap on an axis strip controls the axis, never dismisses the crosshair.\n if (hitAxis(e.x, e.y) !== 'chart') return;\n crosshairActive.current = false;\n const ch = handle.clearCrosshair();\n if (ch) pictureSV.value = ch;\n lastCrosshairTime.current = null;\n onCrosshair?.({ active: false, candle: null, reason: 'hide' });\n });\n\n const gesture = Gesture.Simultaneous(pan, pinch, longPress, tap);\n\n return (\n <GestureHandlerRootView\n onLayout={onLayout}\n style={[\n { width: widthProp, height: heightProp },\n widthProp == null && heightProp == null ? { flex: 1 } : null,\n style,\n ]}\n >\n <GestureDetector gesture={gesture}>\n <View style={{ flex: 1 }}>\n <Canvas style={{ flex: 1 }}>\n {width > 0 && height > 0 ? (\n // pictureSV is always a valid picture (seeded empty, never null),\n // so RN-Skia's UI-thread reader never sees null.\n <Picture picture={pictureSV} />\n ) : null}\n </Canvas>\n </View>\n </GestureDetector>\n </GestureHandlerRootView>\n );\n}\n","import { useEffect, useRef, useState } from 'react';\nimport type { SkPicture } from '@shopify/react-native-skia';\n\nimport NativeVroomChart from './NativeVroomChart';\nimport type { ChartHandle } from './jsi.d';\nimport { packCandles } from './packCandles';\nimport { applyTheme, parseColor } from './theme';\nimport type {\n Candle,\n MACDConfig,\n MovingAverageOverlay,\n RSIConfig,\n VisibleRange,\n VroomTheme,\n VWAPConfig,\n} from './types';\n\n// Mirrors vroom::ma::Source order in packages/core/src/ma.h.\nconst MA_SOURCES = [\n 'close',\n 'open',\n 'high',\n 'low',\n 'hl2',\n 'hlc3',\n 'ohlc4',\n] as const;\n\nfunction overlayToNumeric(o: MovingAverageOverlay) {\n const srcIdx = o.source ? MA_SOURCES.indexOf(o.source) : 0;\n return {\n kind: o.kind === 'ema' ? 1 : 0,\n period: o.length,\n source: srcIdx < 0 ? 0 : srcIdx,\n color: (o.color != null ? parseColor(o.color) : null) ?? 0xff2962ff,\n width: o.width ?? 1.5,\n };\n}\n\nlet installed = false;\nfunction ensureInstalled(): void {\n if (installed) return;\n const ok = NativeVroomChart.install();\n if (!ok) throw new Error('VroomChartModule.install() returned false');\n if (typeof globalThis.VroomChartJSI === 'undefined') {\n throw new Error('global.VroomChartJSI undefined after install()');\n }\n installed = true;\n}\n\nexport type ChartCoreState = {\n handle: ChartHandle | null;\n /** Picture freshly rendered after the latest data/size/range push. */\n picture: SkPicture | null;\n};\n\n// Owns a ChartHandle and produces an \"initial\" picture whenever data, size,\n// or the externally-controlled visible range changes. Gesture-driven updates\n// happen outside this hook by calling handle.pan(...) directly and assigning\n// the result into a SharedValue.\nexport function useChartCore(\n candles: Candle[],\n size: { width: number; height: number; pxRatio?: number },\n visibleRange?: VisibleRange,\n theme?: VroomTheme,\n rsi?: RSIConfig,\n macd?: MACDConfig,\n movingAverages?: MovingAverageOverlay[],\n vwap?: VWAPConfig,\n): ChartCoreState {\n const handleRef = useRef<ChartHandle | null>(null);\n const [picture, setPicture] = useState<SkPicture | null>(null);\n\n if (!handleRef.current && size.width > 0 && size.height > 0) {\n ensureInstalled();\n handleRef.current = globalThis.VroomChartJSI!.create();\n }\n\n // When no visibleRange is provided, leave the range entirely to the C++\n // side (which defaults to a sensible recent window on first setCandles).\n // Only push setVisibleRange when the caller is actively controlling it,\n // so it doesn't clobber the default or fight gesture-driven pans.\n const explicit = visibleRange != null;\n const startMs = visibleRange?.startMs ?? 0;\n const endMs = visibleRange?.endMs ?? 0;\n\n // Stable deps so inline `theme={{...}}` / `rsi={{...}}` literals don't re-run\n // the effect every render — only when the actual values change.\n const themeKey = theme ? JSON.stringify(theme) : '';\n const rsiKey = rsi ? JSON.stringify(rsi) : '';\n const macdKey = macd ? JSON.stringify(macd) : '';\n const maKey = movingAverages ? JSON.stringify(movingAverages) : '';\n const vwapKey = vwap ? JSON.stringify(vwap) : '';\n\n useEffect(() => {\n const h = handleRef.current;\n if (!h) return;\n h.setSize(size.width, size.height, size.pxRatio ?? 1);\n if (candles.length > 0) {\n h.setCandles(packCandles(candles));\n }\n if (explicit) {\n h.setVisibleRange(startMs, endMs);\n }\n if (theme) {\n applyTheme(h, theme);\n }\n h.setRSI(\n rsi?.enabled ?? false,\n rsi?.period ?? 14,\n rsi?.upperBand ?? 70,\n rsi?.lowerBand ?? 30,\n rsi?.maEnabled ?? true,\n rsi?.maPeriod ?? 14,\n );\n h.setMACD(\n macd?.enabled ?? false,\n macd?.fast ?? 12,\n macd?.slow ?? 26,\n macd?.signal ?? 9,\n );\n h.setOverlays((movingAverages ?? []).map(overlayToNumeric));\n h.setVWAP(\n vwap?.enabled ?? false,\n vwap?.resetMinutes ?? 0,\n (vwap?.color != null ? parseColor(vwap.color) : null) ?? 0xff00bcd4,\n vwap?.width ?? 1.5,\n );\n setPicture(h.render());\n // theme/rsi/macd/movingAverages/vwap are represented by their *Key deps.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [candles, size.width, size.height, size.pxRatio, explicit, startMs, endMs, themeKey, rsiKey, macdKey, maKey, vwapKey]);\n\n return { handle: handleRef.current, picture };\n}\n","import type { TurboModule } from 'react-native';\nimport { TurboModuleRegistry } from 'react-native';\n\n// TurboModule spec consumed by codegen. The only method is `install`, which\n// the native side uses to install the `global.VroomChartJSI` host object the\n// first time it's called from JS. All real chart operations go through that\n// host object, not through the TurboModule itself.\nexport interface Spec extends TurboModule {\n install(): boolean;\n}\n\nexport default TurboModuleRegistry.getEnforcing<Spec>('VroomChartModule');\n","import type { Candle } from './types';\n\n// Wire format must match `VroomCandle` in packages/core/include/vroom/vroom_chart.h:\n// int64_t time_ms; double open, high, low, close, volume;\n// = 48 bytes per candle, 8-byte aligned, little-endian on iOS/Android.\nexport const BYTES_PER_CANDLE = 48;\n\n// Serializes candles into the packed little-endian buffer the C++ core expects.\n// Pure (no native/Skia deps) so it can be unit-tested in isolation.\nexport function packCandles(candles: Candle[]): ArrayBuffer {\n const buf = new ArrayBuffer(candles.length * BYTES_PER_CANDLE);\n const view = new DataView(buf);\n for (let i = 0; i < candles.length; i++) {\n const c = candles[i]!;\n const off = i * BYTES_PER_CANDLE;\n view.setBigInt64(off, BigInt(c.timeMs), true);\n view.setFloat64(off + 8, c.open, true);\n view.setFloat64(off + 16, c.high, true);\n view.setFloat64(off + 24, c.low, true);\n view.setFloat64(off + 32, c.close, true);\n view.setFloat64(off + 40, c.volume, true);\n }\n return buf;\n}\n","import type { ChartHandle } from './jsi.d';\nimport type { VroomColor, VroomTheme } from './types';\n\n// Maps each VroomTheme field to its VroomColorKey index in the C++ enum\n// (packages/core/include/vroom/vroom_chart.h). Keep in sync with that enum;\n// new keys are appended there so existing indices never shift.\nexport const COLOR_KEYS: Record<keyof VroomTheme, number> = {\n background: 0, // VROOM_COLOR_BACKGROUND\n bull: 1, // VROOM_COLOR_BULL\n bear: 2, // VROOM_COLOR_BEAR\n grid: 4, // VROOM_COLOR_GRID\n axisText: 5, // VROOM_COLOR_AXIS_TEXT\n crosshair: 6, // VROOM_COLOR_CROSSHAIR\n crosshairTarget: 9, // VROOM_COLOR_CROSSHAIR_TARGET\n};\n\n// Parses a color into a packed 0xAARRGGBB integer (Skia's ARGB order).\n// - number → taken as already-packed ARGB\n// - '#rgb'-style 6-digit hex → opaque (alpha forced to ff)\n// - 8-digit hex → interpreted as AARRGGBB\n// Returns null for anything malformed so the caller can skip it.\nexport function parseColor(value: VroomColor): number | null {\n if (typeof value === 'number') {\n return Number.isFinite(value) ? value >>> 0 : null;\n }\n let s = value.trim();\n if (s.startsWith('#')) s = s.slice(1);\n if (s.length === 6) s = `ff${s}`; // assume opaque\n if (s.length !== 8 || !/^[0-9a-fA-F]{8}$/.test(s)) return null;\n return parseInt(s, 16) >>> 0;\n}\n\n// Pushes every provided theme color into the chart core via handle.setColor.\n// Unspecified or unparseable colors are skipped (they keep their default).\nexport function applyTheme(handle: ChartHandle, theme: VroomTheme): void {\n (Object.keys(COLOR_KEYS) as (keyof VroomTheme)[]).forEach((field) => {\n const value = theme[field];\n if (value == null) return;\n const argb = parseColor(value);\n if (argb == null) return;\n handle.setColor(COLOR_KEYS[field], argb);\n });\n}\n"],"mappings":";AAYA,OAAO,SAAS,aAAAA,YAAW,UAAAC,SAAQ,aAAa,YAAAC,WAAU,eAAe;AACzE,SAAS,YAAoC;AAC7C,SAAS,QAAQ,SAAS,YAA4B;AACtD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;;;ACpB/B,SAAS,WAAW,QAAQ,gBAAgB;;;ACC5C,SAAS,2BAA2B;AAUpC,IAAO,2BAAQ,oBAAoB,aAAmB,kBAAkB;;;ACNjE,IAAM,mBAAmB;AAIzB,SAAS,YAAY,SAAgC;AAC1D,QAAM,MAAM,IAAI,YAAY,QAAQ,SAAS,gBAAgB;AAC7D,QAAM,OAAO,IAAI,SAAS,GAAG;AAC7B,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,UAAM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AO,CAAC;AAAA,EAC/D,CAAC;AAEH,QAAM,UAAU,QAAQ,aAAa,KAAK,OAAO,WAAW,GAAG;AAE/D,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,OAAO;AAAA,QACL,EAAE,OAAO,WAAW,QAAQ,WAAW;AAAA,QACvC,aAAa,QAAQ,cAAc,OAAO,EAAE,MAAM,EAAE,IAAI;AAAA,QACxD;AAAA,MACF;AAAA;AAAA,IAEA,oCAAC,mBAAgB,WACf,oCAAC,QAAK,OAAO,EAAE,MAAM,EAAE,KACrB,oCAAC,UAAO,OAAO,EAAE,MAAM,EAAE,KACtB,QAAQ,KAAK,SAAS;AAAA;AAAA;AAAA,MAGrB,oCAAC,WAAQ,SAAS,WAAW;AAAA,QAC3B,IACN,CACF,CACF;AAAA,EACF;AAEJ;","names":["useEffect","useRef","useState","useState","useRef","useEffect"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-vroom-chart",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Mobile-first Skia candlestick chart for React Native",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Darion Welch",
|
|
7
|
+
"homepage": "https://github.com/darionwelch/vroom#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/darionwelch/vroom.git",
|
|
11
|
+
"directory": "packages/react-native"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"react-native",
|
|
15
|
+
"chart",
|
|
16
|
+
"candlestick",
|
|
17
|
+
"skia",
|
|
18
|
+
"finance",
|
|
19
|
+
"trading",
|
|
20
|
+
"charting",
|
|
21
|
+
"ios"
|
|
22
|
+
],
|
|
23
|
+
"main": "lib/index.js",
|
|
24
|
+
"module": "lib/index.mjs",
|
|
25
|
+
"types": "lib/index.d.ts",
|
|
26
|
+
"react-native": "src/index.ts",
|
|
27
|
+
"source": "src/index.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"lib",
|
|
30
|
+
"src",
|
|
31
|
+
"cpp",
|
|
32
|
+
"ios",
|
|
33
|
+
"android",
|
|
34
|
+
"react-native-vroom-chart.podspec",
|
|
35
|
+
"!**/__tests__",
|
|
36
|
+
"!**/*.test.ts",
|
|
37
|
+
"!**/.*"
|
|
38
|
+
],
|
|
39
|
+
"codegenConfig": {
|
|
40
|
+
"name": "VroomChartSpec",
|
|
41
|
+
"type": "modules",
|
|
42
|
+
"jsSrcsDir": "src",
|
|
43
|
+
"android": {
|
|
44
|
+
"javaPackageName": "com.vroom.chart"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@shopify/react-native-skia": ">=2.0.0",
|
|
52
|
+
"react": "*",
|
|
53
|
+
"react-native": "*",
|
|
54
|
+
"react-native-gesture-handler": ">=2.16.0",
|
|
55
|
+
"react-native-reanimated": ">=4.0.0"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@types/react": "~19.1.0",
|
|
59
|
+
"react": "19.1.0",
|
|
60
|
+
"react-native": "0.81.5",
|
|
61
|
+
"typescript": "~5.9.2",
|
|
62
|
+
"@shopify/react-native-skia": "2.2.12",
|
|
63
|
+
"react-native-gesture-handler": "~2.28.0",
|
|
64
|
+
"react-native-reanimated": "~4.1.1",
|
|
65
|
+
"tsup": "^8.5.1",
|
|
66
|
+
"vitest": "^2.1.9",
|
|
67
|
+
"@vroomchart/types": "0.0.1"
|
|
68
|
+
},
|
|
69
|
+
"scripts": {
|
|
70
|
+
"typecheck": "tsc --noEmit",
|
|
71
|
+
"test": "vitest run",
|
|
72
|
+
"build": "tsup",
|
|
73
|
+
"vendor:core": "node scripts/vendor-core.mjs"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
# Resolve the absolute path to the @shopify/react-native-skia source.
|
|
6
|
+
# We need it because RN-Skia ships its Skia headers via `#include "include/core/SkPicture.h"`,
|
|
7
|
+
# which only resolves when the include path points at the source `cpp/` and `cpp/skia/`
|
|
8
|
+
# directories — CocoaPods' flat Headers/Public/ layout loses the `include/...` prefix.
|
|
9
|
+
skia_pkg_json = `node --print "require.resolve('@shopify/react-native-skia/package.json')"`.strip
|
|
10
|
+
skia_src_dir = File.dirname(skia_pkg_json)
|
|
11
|
+
skia_cpp_dir = File.join(skia_src_dir, "cpp")
|
|
12
|
+
skia_skia_dir = File.join(skia_src_dir, "cpp", "skia")
|
|
13
|
+
|
|
14
|
+
Pod::Spec.new do |s|
|
|
15
|
+
s.name = "react-native-vroom-chart"
|
|
16
|
+
s.version = package["version"]
|
|
17
|
+
s.summary = package["description"]
|
|
18
|
+
s.homepage = "https://github.com/darionwelch/vroom"
|
|
19
|
+
s.license = { :type => "MIT" }
|
|
20
|
+
s.authors = { "vroom" => "noreply@example.com" }
|
|
21
|
+
s.platforms = { :ios => "14.0" }
|
|
22
|
+
s.source = { :git => "" }
|
|
23
|
+
|
|
24
|
+
s.requires_arc = true
|
|
25
|
+
|
|
26
|
+
# CocoaPods source_files globs (a) refuse paths outside the spec's source
|
|
27
|
+
# root and (b) don't follow symlinks. We mirror the core sources into a
|
|
28
|
+
# sibling directory inside this pod.
|
|
29
|
+
#
|
|
30
|
+
# In the monorepo (../core present) we re-mirror on every spec evaluation so
|
|
31
|
+
# edits to packages/core/ propagate on the next `pod install`. In a published
|
|
32
|
+
# install there is no ../core — the cpp/_core_{src,include} copies were already
|
|
33
|
+
# vendored into the tarball at publish time (scripts/vendor-core.mjs), so we
|
|
34
|
+
# leave them in place.
|
|
35
|
+
# (Using `prepare_command` doesn't work because CocoaPods caches it per
|
|
36
|
+
# pod version and doesn't re-run for local pods on subsequent installs.)
|
|
37
|
+
require "fileutils"
|
|
38
|
+
spec_dir = __dir__
|
|
39
|
+
core_root = File.join(spec_dir, "..", "core")
|
|
40
|
+
if File.directory?(core_root)
|
|
41
|
+
["src", "include"].each do |sub|
|
|
42
|
+
src = File.join(core_root, sub)
|
|
43
|
+
dst = File.join(spec_dir, "cpp", "_core_#{sub}")
|
|
44
|
+
FileUtils.rm_rf(dst)
|
|
45
|
+
FileUtils.cp_r(src, dst)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
s.source_files = [
|
|
50
|
+
"ios/**/*.{h,m,mm}",
|
|
51
|
+
"cpp/**/*.{h,cpp}",
|
|
52
|
+
"cpp/_core_src/**/*.{h,cpp}",
|
|
53
|
+
"cpp/_core_include/**/*.h",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
s.pod_target_xcconfig = {
|
|
57
|
+
"HEADER_SEARCH_PATHS" => [
|
|
58
|
+
'"$(PODS_TARGET_SRCROOT)/cpp/_core_include"',
|
|
59
|
+
'"$(PODS_TARGET_SRCROOT)/cpp/_core_src"',
|
|
60
|
+
'"$(PODS_TARGET_SRCROOT)/cpp"',
|
|
61
|
+
"\"#{skia_cpp_dir}\"",
|
|
62
|
+
"\"#{skia_skia_dir}\"",
|
|
63
|
+
].join(" "),
|
|
64
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
|
|
65
|
+
# Match RN-Skia's Skia build flags so our SkCanvas/SkPicture code sees the
|
|
66
|
+
# same SK_METAL / SK_GANESH defines and doesn't mis-link.
|
|
67
|
+
"GCC_PREPROCESSOR_DEFINITIONS" =>
|
|
68
|
+
"$(inherited) SK_METAL=1 SK_GANESH=1 SK_DISABLE_LEGACY_SHAPER_FACTORY=1",
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
s.dependency "React-Core"
|
|
72
|
+
s.dependency "react-native-skia"
|
|
73
|
+
|
|
74
|
+
# Standard new-arch codegen hookup — generates VroomChartSpec from
|
|
75
|
+
# src/NativeVroomChart.ts.
|
|
76
|
+
if defined?(install_modules_dependencies)
|
|
77
|
+
install_modules_dependencies(s)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
|
|
4
|
+
// TurboModule spec consumed by codegen. The only method is `install`, which
|
|
5
|
+
// the native side uses to install the `global.VroomChartJSI` host object the
|
|
6
|
+
// first time it's called from JS. All real chart operations go through that
|
|
7
|
+
// host object, not through the TurboModule itself.
|
|
8
|
+
export interface Spec extends TurboModule {
|
|
9
|
+
install(): boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('VroomChartModule');
|