@delacour/react-native-charts 0.2.0-alpha.20261021211439 → 0.2.0-alpha.20261022200024
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delacour/react-native-charts",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.20261022200024",
|
|
4
4
|
"description": "Headless Skia charting primitives for React Native \u2014 no tokens, no className",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"d3-shape": "^3.2.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"react-native-skia": ">=3",
|
|
46
|
+
"react-native-skia": ">=3.7.3",
|
|
47
47
|
"react": ">=19",
|
|
48
48
|
"react-native": ">=0.81",
|
|
49
49
|
"react-native-gesture-handler": ">=2.28",
|
|
@@ -2,7 +2,6 @@ import { type ReactElement, useEffect, useMemo } from "react";
|
|
|
2
2
|
import { StyleSheet, View } from "react-native";
|
|
3
3
|
import { useSharedValue } from "react-native-reanimated";
|
|
4
4
|
import { Canvas } from "react-native-skia";
|
|
5
|
-
import "../skia/native-id";
|
|
6
5
|
import type { ChartRow } from "../core/chart.types";
|
|
7
6
|
import { buildLinePath } from "../core/curve/build-line";
|
|
8
7
|
import { toCurvePath } from "../core/interaction/path-segments";
|
|
@@ -2,7 +2,6 @@ import { type ReactElement, useMemo, useRef } from "react";
|
|
|
2
2
|
import { StyleSheet, View } from "react-native";
|
|
3
3
|
import { Gesture, type GestureType } from "react-native-gesture-handler";
|
|
4
4
|
import { Canvas } from "react-native-skia";
|
|
5
|
-
import "../skia/native-id";
|
|
6
5
|
import { useCanvasSize } from "../cartesian/hooks/use-canvas-size";
|
|
7
6
|
import type { ChartRow } from "../core/chart.types";
|
|
8
7
|
import { sliceIndexAt } from "../core/polar/slice-index-at";
|
package/src/skia/AGENTS.md
CHANGED
|
@@ -13,8 +13,6 @@ files and nothing else.
|
|
|
13
13
|
| --- | --- |
|
|
14
14
|
| `build-path.ts` | An SVG path string from `core/curve` into an `SkPath` |
|
|
15
15
|
| `font.ts` | A system font, label advance widths, and line height |
|
|
16
|
-
| `native-id.ts` | Seeds Skia's canvas-id counter per JS runtime, imported for its effect by both chart roots |
|
|
17
|
-
| `native-id.test.ts` | The seed: floor, spacing between runtimes, idempotence, the 32-bit bound |
|
|
18
16
|
|
|
19
17
|
## Design
|
|
20
18
|
|
|
@@ -39,11 +37,3 @@ files and nothing else.
|
|
|
39
37
|
- **Line height comes from the font's metrics, not its point size.** An axis
|
|
40
38
|
gutter has to reserve the full glyph box — ascent plus descent — and the
|
|
41
39
|
nominal size is neither.
|
|
42
|
-
|
|
43
|
-
- **Each JS runtime numbers its canvases from somewhere new.** Skia's counter restarts at 1000 on
|
|
44
|
-
every reload while its native view registry outlives the runtime, so the reloaded app's first
|
|
45
|
-
canvases reused ids the old views had tombstoned and drew nothing until they re-rendered — a
|
|
46
|
-
chart came up empty after a dev reload or an OTA `Updates.reloadAsync`. `native-id.ts` moves the
|
|
47
|
-
counter to a random range on import, before any canvas asks for an id. It reaches
|
|
48
|
-
`SkiaViewNativeId` by path because the package root does not export it; `react-native-ui` holds
|
|
49
|
-
an identical copy for `Flow` and `Sketch`.
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import { resolveSkiaNativeId, SKIA_NATIVE_ID_FLOOR } from "./native-id";
|
|
3
|
-
|
|
4
|
-
describe("resolveSkiaNativeId", () => {
|
|
5
|
-
test("moves a fresh runtime's counter off Skia's starting id", () => {
|
|
6
|
-
expect(resolveSkiaNativeId(1000, 0)).toBe(SKIA_NATIVE_ID_FLOOR);
|
|
7
|
-
expect(resolveSkiaNativeId(1000, 0.5)).toBeGreaterThan(SKIA_NATIVE_ID_FLOOR);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
test("keeps the ids a runtime already handed out behind the new counter", () => {
|
|
11
|
-
expect(resolveSkiaNativeId(1003, 0)).toBe(SKIA_NATIVE_ID_FLOOR + 3);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test("leaves a counter that is already seeded alone, so two copies seed once", () => {
|
|
15
|
-
const seeded = resolveSkiaNativeId(1000, 0.25);
|
|
16
|
-
expect(resolveSkiaNativeId(seeded, 0.75)).toBe(seeded);
|
|
17
|
-
expect(resolveSkiaNativeId(seeded + 12, 0.75)).toBe(seeded + 12);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test("spreads runtimes far enough apart that one's ids never reach the next's", () => {
|
|
21
|
-
const a = resolveSkiaNativeId(1000, 0.1);
|
|
22
|
-
const b = resolveSkiaNativeId(1000, 0.1 + 1 / 100_000);
|
|
23
|
-
expect(b - a).toBeGreaterThanOrEqual(10_000);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test("stays inside a signed 32-bit int, which Skia's native side casts ids to", () => {
|
|
27
|
-
expect(resolveSkiaNativeId(1000, 0.999_999_999)).toBeLessThan(2 ** 31 - 1_000_000);
|
|
28
|
-
});
|
|
29
|
-
});
|
package/src/skia/native-id.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { SkiaViewNativeId } from "react-native-skia/src/views/SkiaViewNativeId";
|
|
2
|
-
|
|
3
|
-
/** Skia's counter starts at 1000; anything at or above this has been seeded. */
|
|
4
|
-
export const SKIA_NATIVE_ID_FLOOR = 10_000;
|
|
5
|
-
|
|
6
|
-
/** Ids a runtime may hand out before it reaches the next runtime's range. */
|
|
7
|
-
const SKIA_NATIVE_ID_SPAN = 10_000;
|
|
8
|
-
|
|
9
|
-
/** How many ranges a runtime can land in — 1e9 at the top, inside a signed 32-bit int. */
|
|
10
|
-
const SKIA_NATIVE_ID_SLOTS = 100_000;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Where a JS runtime's Skia canvas ids should start, given the counter as it stands and a number
|
|
14
|
-
* in `[0, 1)`. A counter already at or above the floor is returned as it is, so every copy of this
|
|
15
|
-
* module in an app can run it and only the first moves anything.
|
|
16
|
-
*/
|
|
17
|
-
export function resolveSkiaNativeId(current: number, random: number): number {
|
|
18
|
-
if (current >= SKIA_NATIVE_ID_FLOOR) return current;
|
|
19
|
-
const slot = Math.floor(random * SKIA_NATIVE_ID_SLOTS);
|
|
20
|
-
return SKIA_NATIVE_ID_FLOOR + slot * SKIA_NATIVE_ID_SPAN + (current - 1000);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Starts this runtime's canvas ids somewhere the last runtime's never were.
|
|
25
|
-
*
|
|
26
|
-
* **A canvas mounted after a JS reload drew nothing until it re-rendered.** Skia numbers canvases
|
|
27
|
-
* from a module-level counter that restarts at 1000 in every runtime, while its native
|
|
28
|
-
* `ViewRegistry` is a process-wide singleton that outlives the reload. The old runtime's views are
|
|
29
|
-
* torn down after the new one has started, and each leaves a tombstone for its id; the new
|
|
30
|
-
* runtime's first canvases reuse those ids, their pictures are handed to a throwaway entry, and the
|
|
31
|
-
* view registers to an empty one. Nothing draws until the next React commit sends the picture again.
|
|
32
|
-
* A dev-menu reload hits it, and so does `Updates.reloadAsync` after an OTA update.
|
|
33
|
-
* Reported upstream as wcandillon/react-native-skia#4312; drop this once a release fixes it.
|
|
34
|
-
*
|
|
35
|
-
* Evaluated once per runtime, on import, before any canvas has asked for an id. `SkiaViewNativeId`
|
|
36
|
-
* is not exported from the package root, so this reaches it by path — the same file Metro resolves
|
|
37
|
-
* `Canvas` from through the package's `react-native` field.
|
|
38
|
-
*
|
|
39
|
-
* `@delacour/react-native-ui` keeps an identical copy in `src/lib/skia-native-id.ts` for `Flow` and
|
|
40
|
-
* `Sketch`, which do not depend on this package; change both together.
|
|
41
|
-
*/
|
|
42
|
-
SkiaViewNativeId.current = resolveSkiaNativeId(SkiaViewNativeId.current, Math.random());
|