embedded-react 0.12.0 → 0.13.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/README.md +144 -5
- package/aot/compile.mjs +1222 -72
- package/aot/style-map.mjs +10 -5
- package/assets/bake-font.mjs +104 -12
- package/assets/bake-svg.mjs +11 -1
- package/assets/build-builtin-font.mjs +6 -12
- package/assets/emit-c.mjs +10 -2
- package/assets/font-config.mjs +49 -0
- package/assets/font-sizes.mjs +652 -0
- package/assets/glyph-coverage.mjs +281 -0
- package/assets/index.mjs +29 -5
- package/build.mjs +11 -21
- package/cli.mjs +13 -1
- package/compile-bin.mjs +71 -0
- package/hotreload/pack-app.mjs +8 -21
- package/hotreload/pack-split.mjs +12 -27
- package/pack-container.mjs +10 -47
- package/package.json +2 -1
- package/sim/embedded-react.wasm +0 -0
- package/sim/index.html +32 -3
- package/sim-server.mjs +33 -27
- package/src/embedded-react/Animated.js +23 -9
- package/src/embedded-react/Button.js +98 -0
- package/src/embedded-react/FlatList.js +88 -0
- package/src/embedded-react/ImageBackground.js +67 -0
- package/src/embedded-react/PanResponder.js +326 -0
- package/src/embedded-react/SectionList.js +148 -0
- package/src/embedded-react/TouchableOpacity.js +152 -0
- package/src/embedded-react/components.js +4 -3
- package/src/embedded-react/index.d.ts +866 -60
- package/src/embedded-react/index.js +7 -2
- package/src/embedded-react/list-child.js +54 -0
- package/src/embedded-react/svg-ops.js +220 -72
- package/src/embedded-react/warn-props.js +80 -0
- package/src/host-config.js +98 -3
- package/src/props.js +38 -0
|
@@ -26,13 +26,12 @@ export {
|
|
|
26
26
|
Text,
|
|
27
27
|
Image,
|
|
28
28
|
ScrollView,
|
|
29
|
-
FlatList,
|
|
30
29
|
Pressable,
|
|
31
|
-
TouchableOpacity,
|
|
32
30
|
TextInput,
|
|
33
31
|
Switch,
|
|
34
32
|
ActivityIndicator,
|
|
35
33
|
Modal,
|
|
34
|
+
Dial,
|
|
36
35
|
Svg,
|
|
37
36
|
Path,
|
|
38
37
|
Circle,
|
|
@@ -42,11 +41,17 @@ export {
|
|
|
42
41
|
G,
|
|
43
42
|
Arc,
|
|
44
43
|
} from './components.js';
|
|
44
|
+
export {Button} from './Button.js';
|
|
45
|
+
export {TouchableOpacity} from './TouchableOpacity.js';
|
|
46
|
+
export {FlatList} from './FlatList.js';
|
|
47
|
+
export {ImageBackground} from './ImageBackground.js';
|
|
48
|
+
export {SectionList} from './SectionList.js';
|
|
45
49
|
export {updateVector, updateText, setKeyboardConfig} from './imperative.js';
|
|
46
50
|
export {StyleSheet} from './StyleSheet.js';
|
|
47
51
|
export {Platform} from './Platform.js';
|
|
48
52
|
export {AppRegistry} from './AppRegistry.js';
|
|
49
53
|
export {Animated, useAnimatedValue} from './Animated.js';
|
|
54
|
+
export {PanResponder} from './PanResponder.js';
|
|
50
55
|
export {usePersistentState} from './usePersistentState.js';
|
|
51
56
|
export {useHostValue} from './useHostValue.js';
|
|
52
57
|
export {Easing} from './Easing.js';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Cory Lamming
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// Shared row handling for the list wrappers (<FlatList>, <SectionList>). Both turn a render callback's
|
|
18
|
+
// result into a keyed child of one <ScrollView>, and the awkward cases are the same for both: a row
|
|
19
|
+
// that renders to nothing, and a row that isn't an element at all.
|
|
20
|
+
import {cloneElement} from 'react';
|
|
21
|
+
|
|
22
|
+
/** True for a render result that puts nothing on screen — the `{cond && <Row/>}` of a row callback. */
|
|
23
|
+
export const rendersNothing = node =>
|
|
24
|
+
node === null || node === undefined || node === false;
|
|
25
|
+
|
|
26
|
+
/** True for something cloneElement can key — a React element, as opposed to a string/number row. */
|
|
27
|
+
export const isElement = node =>
|
|
28
|
+
node !== null && typeof node === 'object' && node.$$typeof !== undefined;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Appends one rendered row to `out`, keyed, or drops it if it rendered nothing.
|
|
32
|
+
*
|
|
33
|
+
* Callers own the key because they know what makes one unique (a SectionList's rows are siblings
|
|
34
|
+
* across sections, a FlatList's are not). A row that is not an element goes in untouched: there is no
|
|
35
|
+
* key to attach to a raw string, and a plain `.map` wouldn't have attached one either.
|
|
36
|
+
*
|
|
37
|
+
* The key arrives as a FUNCTION, not a value, and that is the point: it is called only for a node that
|
|
38
|
+
* can actually carry one. `keyExtractor` is the app's code — running it for a row that rendered
|
|
39
|
+
* nothing, or for a raw string that cannot be cloned, is both wasted work on the commit path and a
|
|
40
|
+
* side effect the app never asked for. Passing the key by value invites exactly that, and did.
|
|
41
|
+
*
|
|
42
|
+
* @param {Array} out The child list being built.
|
|
43
|
+
* @param {*} node Whatever the render callback returned.
|
|
44
|
+
* @param {(element: object) => string} keyFor Builds the React key, given the keyable element.
|
|
45
|
+
*/
|
|
46
|
+
export function pushKeyedChild(out, node, keyFor) {
|
|
47
|
+
if (rendersNothing(node)) return;
|
|
48
|
+
if (!isElement(node)) {
|
|
49
|
+
out.push(node);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const key = keyFor(node);
|
|
53
|
+
out.push(node.key === key ? node : cloneElement(node, {key}));
|
|
54
|
+
}
|
|
@@ -32,6 +32,10 @@ export const VOP_CUBIC = 4;
|
|
|
32
32
|
export const VOP_ARC = 5;
|
|
33
33
|
export const VOP_CLOSE = 6;
|
|
34
34
|
|
|
35
|
+
// Control-point ratio for approximating a quarter (circular or elliptical) arc with one cubic:
|
|
36
|
+
// 4/3 * (sqrt(2) - 1). Used by rounded-rect corners.
|
|
37
|
+
export const KAPPA = 0.5522847498307936;
|
|
38
|
+
|
|
35
39
|
export const CAP = {butt: 0, round: 1, square: 2};
|
|
36
40
|
export const JOIN = {miter: 0, round: 1, bevel: 2};
|
|
37
41
|
|
|
@@ -458,28 +462,111 @@ function ellipseOps(p) {
|
|
|
458
462
|
return parsePath(d);
|
|
459
463
|
}
|
|
460
464
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
465
|
+
/**
|
|
466
|
+
* SVG <rect> corner-radius resolution. A missing radius is `auto` and falls back to the other one; a
|
|
467
|
+
* NEGATIVE radius is invalid, which also means `auto`, so it falls back too — <rect rx="-3" ry="8">
|
|
468
|
+
* rounds at 8, matching what browsers render. An explicit ZERO is a valid radius and squares the
|
|
469
|
+
* corners, and each radius is clamped to half its own side. Returns [rx, ry] — [0, 0] for a
|
|
470
|
+
* square-cornered rect. Exported so the AOT and the SVG baker apply the same rules.
|
|
471
|
+
*/
|
|
472
|
+
export function rectRadii(rxAttr, ryAttr, w, h) {
|
|
473
|
+
let rx = num(rxAttr, -1);
|
|
474
|
+
let ry = num(ryAttr, -1);
|
|
475
|
+
if (rx < 0) rx = ry; // rx omitted -> ry
|
|
476
|
+
if (ry < 0) ry = rx; // ry omitted -> rx
|
|
477
|
+
rx = Math.min(rx, w / 2);
|
|
478
|
+
ry = Math.min(ry, h / 2);
|
|
479
|
+
return rx > 0 && ry > 0 ? [rx, ry] : [0, 0];
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Rect path ops, clockwise from the top-left corner. rx/ry must already be resolved by rectRadii();
|
|
484
|
+
* 0 gives the plain four-line rectangle. Corners are cubics rather than VOP_ARC so each one STARTS at
|
|
485
|
+
* exactly the preceding line's endpoint — an arc recomputes that point from cos/sin and can miss the
|
|
486
|
+
* engine's exact-equality join dedupe by a ULP, which spikes the miter join on a stroked rect.
|
|
487
|
+
*/
|
|
488
|
+
function rectOpsXY(x, y, w, h, rx, ry) {
|
|
489
|
+
if (rx <= 0 || ry <= 0)
|
|
490
|
+
return [
|
|
491
|
+
VOP_MOVE,
|
|
492
|
+
x,
|
|
493
|
+
y,
|
|
494
|
+
VOP_LINE,
|
|
495
|
+
x + w,
|
|
496
|
+
y,
|
|
497
|
+
VOP_LINE,
|
|
498
|
+
x + w,
|
|
499
|
+
y + h,
|
|
500
|
+
VOP_LINE,
|
|
501
|
+
x,
|
|
502
|
+
y + h,
|
|
503
|
+
VOP_CLOSE,
|
|
504
|
+
];
|
|
505
|
+
const kx = rx * KAPPA;
|
|
506
|
+
const ky = ry * KAPPA;
|
|
507
|
+
const x1 = x + rx; // where the top/bottom edges start, past the left corners
|
|
508
|
+
const x2 = x + w - rx; // ... and end, before the right corners
|
|
509
|
+
const y1 = y + ry;
|
|
510
|
+
const y2 = y + h - ry;
|
|
511
|
+
const r = x + w;
|
|
512
|
+
const b = y + h;
|
|
466
513
|
return [
|
|
467
514
|
VOP_MOVE,
|
|
468
|
-
|
|
515
|
+
x1,
|
|
469
516
|
y,
|
|
470
517
|
VOP_LINE,
|
|
471
|
-
|
|
518
|
+
x2,
|
|
519
|
+
y,
|
|
520
|
+
VOP_CUBIC,
|
|
521
|
+
x2 + kx,
|
|
472
522
|
y,
|
|
523
|
+
r,
|
|
524
|
+
y1 - ky,
|
|
525
|
+
r,
|
|
526
|
+
y1,
|
|
527
|
+
VOP_LINE,
|
|
528
|
+
r,
|
|
529
|
+
y2,
|
|
530
|
+
VOP_CUBIC,
|
|
531
|
+
r,
|
|
532
|
+
y2 + ky,
|
|
533
|
+
x2 + kx,
|
|
534
|
+
b,
|
|
535
|
+
x2,
|
|
536
|
+
b,
|
|
473
537
|
VOP_LINE,
|
|
474
|
-
|
|
475
|
-
|
|
538
|
+
x1,
|
|
539
|
+
b,
|
|
540
|
+
VOP_CUBIC,
|
|
541
|
+
x1 - kx,
|
|
542
|
+
b,
|
|
543
|
+
x,
|
|
544
|
+
y2 + ky,
|
|
545
|
+
x,
|
|
546
|
+
y2,
|
|
476
547
|
VOP_LINE,
|
|
477
548
|
x,
|
|
478
|
-
|
|
549
|
+
y1,
|
|
550
|
+
VOP_CUBIC,
|
|
551
|
+
x,
|
|
552
|
+
y1 - ky,
|
|
553
|
+
x1 - kx,
|
|
554
|
+
y,
|
|
555
|
+
x1,
|
|
556
|
+
y,
|
|
479
557
|
VOP_CLOSE,
|
|
480
558
|
];
|
|
481
559
|
}
|
|
482
560
|
|
|
561
|
+
function rectOps(p) {
|
|
562
|
+
const x = num(p.x, 0);
|
|
563
|
+
const y = num(p.y, 0);
|
|
564
|
+
const w = num(p.width, 0);
|
|
565
|
+
const h = num(p.height, 0);
|
|
566
|
+
const [rx, ry] = rectRadii(p.rx, p.ry, w, h);
|
|
567
|
+
return rectOpsXY(x, y, w, h, rx, ry);
|
|
568
|
+
}
|
|
569
|
+
|
|
483
570
|
function lineOps(p) {
|
|
484
571
|
return [
|
|
485
572
|
VOP_MOVE,
|
|
@@ -509,7 +596,7 @@ function arcOpsCW(cx, cy, r, a0deg, a1deg) {
|
|
|
509
596
|
* { arc: [cx, cy, r, startDeg, endDeg], stroke: '#f4a261', strokeWidth: 14, cap: 'round' }
|
|
510
597
|
* { circle: [cx, cy, r], fill: '#16202f', stroke: '#f4a261', strokeWidth: 3 }
|
|
511
598
|
* { line: [x1, y1, x2, y2], stroke, strokeWidth }
|
|
512
|
-
* { rect: [x, y, w, h], fill }
|
|
599
|
+
* { rect: [x, y, w, h], fill } // optional [x, y, w, h, rx, ry] for rounded corners
|
|
513
600
|
* { path: 'M..A..', stroke } // d-string supported but slower (regex + bezier)
|
|
514
601
|
* Arc angles are degrees, clockwise from 12 o'clock. This avoids the d-string parser entirely, so it's
|
|
515
602
|
* cheap enough to call on every pointer move (the imperative drag path).
|
|
@@ -562,21 +649,29 @@ export function shapesToVector(shapes) {
|
|
|
562
649
|
const y = s.rect[1];
|
|
563
650
|
const w = s.rect[2];
|
|
564
651
|
const h = s.rect[3];
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
652
|
+
if (s.rect.length > 4) {
|
|
653
|
+
// Rounded — the optional trailing [rx, ry]. Off the allocation-free path below, but a rounded
|
|
654
|
+
// rect is a chrome/backing shape, not something a drag rebuilds every move.
|
|
655
|
+
const [rx, ry] = rectRadii(s.rect[4], s.rect[5], w, h);
|
|
656
|
+
const ro = rectOpsXY(x, y, w, h, rx, ry);
|
|
657
|
+
for (let k = 0; k < ro.length; k++) ops.push(ro[k]);
|
|
658
|
+
} else {
|
|
659
|
+
ops.push(
|
|
660
|
+
VOP_MOVE,
|
|
661
|
+
x,
|
|
662
|
+
y,
|
|
663
|
+
VOP_LINE,
|
|
664
|
+
x + w,
|
|
665
|
+
y,
|
|
666
|
+
VOP_LINE,
|
|
667
|
+
x + w,
|
|
668
|
+
y + h,
|
|
669
|
+
VOP_LINE,
|
|
670
|
+
x,
|
|
671
|
+
y + h,
|
|
672
|
+
VOP_CLOSE,
|
|
673
|
+
);
|
|
674
|
+
}
|
|
580
675
|
} else if (s.line) {
|
|
581
676
|
ops.push(VOP_MOVE, s.line[0], s.line[1], VOP_LINE, s.line[2], s.line[3]);
|
|
582
677
|
} else if (s.path) {
|
|
@@ -698,20 +793,65 @@ function transformOps(ops, T) {
|
|
|
698
793
|
return out;
|
|
699
794
|
}
|
|
700
795
|
|
|
701
|
-
function asArray(children) {
|
|
702
|
-
if (children == null || children === false || children === true) return [];
|
|
703
|
-
return Array.isArray(children) ? children : [children];
|
|
704
|
-
}
|
|
705
|
-
|
|
706
796
|
function isElement(c) {
|
|
707
797
|
return c && typeof c === 'object' && c.type != null && c.props != null;
|
|
708
798
|
}
|
|
709
799
|
|
|
800
|
+
// React's fragment tag. Read from the global symbol registry rather than importing React, which this
|
|
801
|
+
// module deliberately does not depend on; `Symbol.for` returns the very symbol React itself uses.
|
|
802
|
+
const REACT_FRAGMENT = Symbol.for('react.fragment');
|
|
803
|
+
|
|
804
|
+
/** Children JSX produces for "draw nothing": a bare `{cond && <Path/>}` that failed, a hole in a
|
|
805
|
+
* list, and the whitespace JSX leaves between elements. Skipped without a word. */
|
|
806
|
+
function isEmptyChild(c) {
|
|
807
|
+
return (
|
|
808
|
+
c == null ||
|
|
809
|
+
typeof c === 'boolean' ||
|
|
810
|
+
(typeof c === 'string' && c.trim() === '')
|
|
811
|
+
);
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
// Shape/grouping tags flattenSvg knows. A tag outside this set is a mistake worth reporting; a known
|
|
815
|
+
// tag that produces no geometry (a <Path> with no `d`, a zero-radius <Circle>) is not.
|
|
816
|
+
const SVG_TAGS = ['Path', 'Circle', 'Ellipse', 'Rect', 'Line', 'Arc', 'G'];
|
|
817
|
+
|
|
818
|
+
let _warnedSvgChild = false;
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Warns ONCE about a child <Svg> cannot draw. The two common cases are a component (`<Needle/>` —
|
|
822
|
+
* <Svg> owns its subtree, so React never renders it) and a non-shape host tag; both used to vanish
|
|
823
|
+
* with no output at all. Once per app, like the other commit-path warnings: an <Svg> recompiles its
|
|
824
|
+
* tape on every update, and one bad child would otherwise print on every frame.
|
|
825
|
+
*
|
|
826
|
+
* The way out of the component case is to CALL it — `{needle()}` puts whatever it returns (an element
|
|
827
|
+
* or an array of them) straight into children, where the walk sees it. Having it return an array does
|
|
828
|
+
* nothing for `<Needle/>`: that form is never invoked at all.
|
|
829
|
+
*/
|
|
830
|
+
function warnSvgChild(c) {
|
|
831
|
+
if (_warnedSvgChild) return;
|
|
832
|
+
_warnedSvgChild = true;
|
|
833
|
+
const what = !isElement(c)
|
|
834
|
+
? typeof c === 'string'
|
|
835
|
+
? `the text ${JSON.stringify(c)}`
|
|
836
|
+
: `a ${typeof c} child`
|
|
837
|
+
: typeof c.type === 'function'
|
|
838
|
+
? `<${c.type.displayName || c.type.name || 'Component'}>, a component`
|
|
839
|
+
: `<${String(c.type)}>`;
|
|
840
|
+
console.warn(
|
|
841
|
+
`embedded-react: <Svg> can't draw ${what}, and skipped it. Children must be ${SVG_TAGS.join('/')} ` +
|
|
842
|
+
`elements (arrays and fragments around them are unwrapped). <Svg> flattens its subtree instead of ` +
|
|
843
|
+
`mounting it, so a component is never rendered — inline its shapes, or call it as a plain ` +
|
|
844
|
+
`function: {needle()}.`,
|
|
845
|
+
);
|
|
846
|
+
}
|
|
847
|
+
|
|
710
848
|
/**
|
|
711
849
|
* Flattens an <Svg> element's props into {ops, paints, gradients} flat arrays for NativeUI.setVectorOps.
|
|
712
850
|
* Handles Path/Circle/Ellipse/Rect/Line shapes, <G> grouping (inherited paint + translate/scale), and
|
|
713
|
-
* a root viewBox -> width/height scale.
|
|
714
|
-
*
|
|
851
|
+
* a root viewBox -> width/height scale. Arrays and fragments are unwrapped at any depth, so a mapped
|
|
852
|
+
* list of shapes draws like an inline one. A shape's fillGrad/strokeGrad descriptor lands in
|
|
853
|
+
* `gradients` and is referenced 1-based from its paint record. Returns empty arrays when there is
|
|
854
|
+
* nothing to draw.
|
|
715
855
|
*/
|
|
716
856
|
export function flattenSvg(props) {
|
|
717
857
|
const ops = [];
|
|
@@ -732,46 +872,54 @@ export function flattenSvg(props) {
|
|
|
732
872
|
}
|
|
733
873
|
}
|
|
734
874
|
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
const gx = num(p.x ?? p.translateX, 0);
|
|
744
|
-
const gy = num(p.y ?? p.translateY, 0);
|
|
745
|
-
const childT = {
|
|
746
|
-
sx: T.sx * s,
|
|
747
|
-
sy: T.sy * s,
|
|
748
|
-
tx: gx * T.sx + T.tx,
|
|
749
|
-
ty: gy * T.sy + T.ty,
|
|
750
|
-
};
|
|
751
|
-
walk(p.children, merged, childT);
|
|
752
|
-
continue;
|
|
753
|
-
}
|
|
754
|
-
let shapeOps = null;
|
|
755
|
-
if (c.type === 'Path' && p.d) shapeOps = parsePath(p.d);
|
|
756
|
-
else if (c.type === 'Circle') shapeOps = circleOps(p);
|
|
757
|
-
else if (c.type === 'Ellipse') shapeOps = ellipseOps(p);
|
|
758
|
-
else if (c.type === 'Rect') shapeOps = rectOps(p);
|
|
759
|
-
else if (c.type === 'Line') shapeOps = lineOps(p);
|
|
760
|
-
else if (c.type === 'Arc')
|
|
761
|
-
shapeOps = arcOpsCW(
|
|
762
|
-
num(p.cx, 0),
|
|
763
|
-
num(p.cy, 0),
|
|
764
|
-
num(p.r, 0),
|
|
765
|
-
num(p.startAngle, 0),
|
|
766
|
-
num(p.endAngle, 0),
|
|
767
|
-
);
|
|
768
|
-
if (!shapeOps || shapeOps.length === 0) continue;
|
|
769
|
-
|
|
770
|
-
const paintIndex = paints.length / PAINT_STRIDE;
|
|
771
|
-
const scale = (T.sx + T.sy) / 2; // stroke-width scale (uniform assumed)
|
|
772
|
-
paints.push(...paintRecord(merged, scale, gradients));
|
|
773
|
-
ops.push(VOP_SHAPE, paintIndex, ...transformOps(shapeOps, T));
|
|
875
|
+
// One child at a time, recursing through the wrappers, JSX inserts around shapes: an array (every
|
|
876
|
+
// `{shapes.map(...)}`, and arrays of arrays when those nest) and a fragment, either of which can
|
|
877
|
+
// sit anywhere a shape can. Both are transparent — they carry no paint and no transform.
|
|
878
|
+
const walk = (c, paint, T) => {
|
|
879
|
+
if (isEmptyChild(c)) return;
|
|
880
|
+
if (Array.isArray(c)) {
|
|
881
|
+
for (const item of c) walk(item, paint, T);
|
|
882
|
+
return;
|
|
774
883
|
}
|
|
884
|
+
if (!isElement(c)) return warnSvgChild(c);
|
|
885
|
+
const p = c.props || {};
|
|
886
|
+
if (c.type === REACT_FRAGMENT) return walk(p.children, paint, T);
|
|
887
|
+
const merged = mergePaint(paint, p);
|
|
888
|
+
if (c.type === 'G') {
|
|
889
|
+
// Compose a translate/scale for the group, then recurse.
|
|
890
|
+
const s = num(p.scale, 1);
|
|
891
|
+
const gx = num(p.x ?? p.translateX, 0);
|
|
892
|
+
const gy = num(p.y ?? p.translateY, 0);
|
|
893
|
+
const childT = {
|
|
894
|
+
sx: T.sx * s,
|
|
895
|
+
sy: T.sy * s,
|
|
896
|
+
tx: gx * T.sx + T.tx,
|
|
897
|
+
ty: gy * T.sy + T.ty,
|
|
898
|
+
};
|
|
899
|
+
return walk(p.children, merged, childT);
|
|
900
|
+
}
|
|
901
|
+
if (!SVG_TAGS.includes(c.type)) return warnSvgChild(c);
|
|
902
|
+
|
|
903
|
+
let shapeOps = null;
|
|
904
|
+
if (c.type === 'Path' && p.d) shapeOps = parsePath(p.d);
|
|
905
|
+
else if (c.type === 'Circle') shapeOps = circleOps(p);
|
|
906
|
+
else if (c.type === 'Ellipse') shapeOps = ellipseOps(p);
|
|
907
|
+
else if (c.type === 'Rect') shapeOps = rectOps(p);
|
|
908
|
+
else if (c.type === 'Line') shapeOps = lineOps(p);
|
|
909
|
+
else if (c.type === 'Arc')
|
|
910
|
+
shapeOps = arcOpsCW(
|
|
911
|
+
num(p.cx, 0),
|
|
912
|
+
num(p.cy, 0),
|
|
913
|
+
num(p.r, 0),
|
|
914
|
+
num(p.startAngle, 0),
|
|
915
|
+
num(p.endAngle, 0),
|
|
916
|
+
);
|
|
917
|
+
if (!shapeOps || shapeOps.length === 0) return;
|
|
918
|
+
|
|
919
|
+
const paintIndex = paints.length / PAINT_STRIDE;
|
|
920
|
+
const scale = (T.sx + T.sy) / 2; // stroke-width scale (uniform assumed)
|
|
921
|
+
paints.push(...paintRecord(merged, scale, gradients));
|
|
922
|
+
ops.push(VOP_SHAPE, paintIndex, ...transformOps(shapeOps, T));
|
|
775
923
|
};
|
|
776
924
|
|
|
777
925
|
walk(props.children, PAINT_DEFAULT, root);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Cory Lamming
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// Shared "you passed a prop this component ignores" warning for the JS-only RN wrappers (Button,
|
|
18
|
+
// FlatList, ImageBackground, SectionList). Those components exist for API compatibility, so an app
|
|
19
|
+
// ported from React Native arrives carrying props that mean nothing on a panel — and a prop that is
|
|
20
|
+
// silently dropped is the worst outcome, because the UI just quietly isn't what the source says.
|
|
21
|
+
//
|
|
22
|
+
// Warns ONCE per component and then stops scanning: these render on the Flow A commit path, and a
|
|
23
|
+
// misconfigured list re-renders on every data change. One line in the device console is a hint; one
|
|
24
|
+
// line per commit is a flood that pushes everything else out of the scrollback.
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* RN props that wrap an OS service a bare panel does not have: a screen reader, a focus engine, a test
|
|
28
|
+
* runner, a click sound. They are real RN props, they cost nothing to carry, and keeping them means a
|
|
29
|
+
* component still compiles when it goes back to React Native — so a wrapper drops them without a word
|
|
30
|
+
* rather than making an app strip them to silence a warning.
|
|
31
|
+
*
|
|
32
|
+
* Note that <FlatList> deliberately does NOT quiet these: it is the one wrapper the AOT lowers, and it
|
|
33
|
+
* rejects every prop outside its supported four, so a `testID` there fails the device build. Warning
|
|
34
|
+
* about it is the point.
|
|
35
|
+
*/
|
|
36
|
+
export const RN_PLATFORM_NO_OPS = [
|
|
37
|
+
'accessible',
|
|
38
|
+
'accessibilityLabel',
|
|
39
|
+
'accessibilityHint',
|
|
40
|
+
'accessibilityLanguage',
|
|
41
|
+
'accessibilityRole',
|
|
42
|
+
'accessibilityState',
|
|
43
|
+
'accessibilityActions',
|
|
44
|
+
'onAccessibilityAction',
|
|
45
|
+
'importantForAccessibility',
|
|
46
|
+
'testID',
|
|
47
|
+
'touchSoundDisabled',
|
|
48
|
+
'hasTVPreferredFocus',
|
|
49
|
+
'nextFocusDown',
|
|
50
|
+
'nextFocusForward',
|
|
51
|
+
'nextFocusLeft',
|
|
52
|
+
'nextFocusRight',
|
|
53
|
+
'nextFocusUp',
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Builds the once-only prop warner for a component.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} component Component name, as it appears in JSX (no angle brackets).
|
|
60
|
+
* @param {string[]} supported Props the component honours. Listed in the warning as the way out.
|
|
61
|
+
* @param {string} hint Why the rest are ignored / what to reach for instead. Ends the first sentence.
|
|
62
|
+
* @param {string[]} [quiet] Props to ignore silently — RN props that wrap an OS service this board
|
|
63
|
+
* doesn't have (accessibility, TV focus, test ids). They are portable no-ops, not mistakes.
|
|
64
|
+
* @returns {(props: object) => void} Call with the full prop object on every render.
|
|
65
|
+
*/
|
|
66
|
+
export function createPropWarner(component, supported, hint, quiet = []) {
|
|
67
|
+
let warned = false;
|
|
68
|
+
return props => {
|
|
69
|
+
if (warned) return;
|
|
70
|
+
const names = Object.keys(props).filter(
|
|
71
|
+
k => !supported.includes(k) && !quiet.includes(k),
|
|
72
|
+
);
|
|
73
|
+
if (names.length === 0) return;
|
|
74
|
+
warned = true;
|
|
75
|
+
console.warn(
|
|
76
|
+
`embedded-react: <${component}> ignores ${names.join(', ')} — ${hint} ` +
|
|
77
|
+
`Supported here: ${supported.join(', ')}.`,
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
}
|
package/src/host-config.js
CHANGED
|
@@ -35,12 +35,90 @@ import {
|
|
|
35
35
|
} from './embedded-react/svg-ops.js';
|
|
36
36
|
import {splitAnimatedStyle} from './embedded-react/split-style.js';
|
|
37
37
|
|
|
38
|
+
// --- Animated bindings ---------------------------------------------------------------------------
|
|
39
|
+
// A bound prop is owned by the engine from then on: it re-pushes the animated value over the static
|
|
40
|
+
// props of every later setProps (er_anim_reapply_bound), which is what keeps a re-render from jumping
|
|
41
|
+
// a running animation back to its declared value. Nothing in React says "this prop stopped being
|
|
42
|
+
// animated", so the binding has to be released explicitly or it keeps writing the prop forever — and a
|
|
43
|
+
// prop that swapped Animated.Values ends up written by both. Instances are bare node handles with no
|
|
44
|
+
// JS object to hang state on, so what we bound is remembered here: handle → (prop → animated value).
|
|
45
|
+
const boundValues = new Map();
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* True when two animated values bind a prop the same way, so a re-render can leave the live binding
|
|
49
|
+
* alone. Identity settles an Animated.Value; an interpolation is a throwaway object that
|
|
50
|
+
* `value.interpolate(...)` rebuilds on every render, so it answers __bindEq for itself.
|
|
51
|
+
*/
|
|
52
|
+
function sameBinding(prev, next) {
|
|
53
|
+
if (prev === next) return true;
|
|
54
|
+
if (prev == null || next == null) return false;
|
|
55
|
+
return typeof prev.__bindEq === 'function' && prev.__bindEq(next);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The value `bindings` (from splitAnimatedStyle) drives `prop` with, or undefined if none does. */
|
|
59
|
+
function bindingFor(bindings, prop) {
|
|
60
|
+
for (const b of bindings) {
|
|
61
|
+
if (b.prop === prop) return b.value;
|
|
62
|
+
}
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Releases the bindings a node has that its new props no longer ask for — a prop that went back to a
|
|
68
|
+
* static value, or moved to a different Animated.Value.
|
|
69
|
+
*
|
|
70
|
+
* Runs BEFORE the node's setProps, and that order is the whole point: setProps re-pushes every value
|
|
71
|
+
* still bound to the node over the static props it just wrote, so a binding released afterwards would
|
|
72
|
+
* leave its last animated float sitting on the node instead of the value React just set.
|
|
73
|
+
*/
|
|
74
|
+
function releaseStaleBindings(handle, bindings) {
|
|
75
|
+
const bound = boundValues.get(handle);
|
|
76
|
+
if (bound === undefined) return;
|
|
77
|
+
for (const [prop, value] of bound) {
|
|
78
|
+
if (sameBinding(value, bindingFor(bindings, prop))) continue;
|
|
79
|
+
NativeUI.animUnbind(handle, prop);
|
|
80
|
+
bound.delete(prop);
|
|
81
|
+
}
|
|
82
|
+
if (bound.size === 0) boundValues.delete(handle);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Binds the props that aren't already bound to the value asking for them. The engine ignores a
|
|
87
|
+
* duplicate bind, but the bridge crossing to find that out isn't free on an MCU.
|
|
88
|
+
*/
|
|
89
|
+
function applyBindings(handle, bindings) {
|
|
90
|
+
if (bindings.length === 0) return;
|
|
91
|
+
let bound = boundValues.get(handle);
|
|
92
|
+
for (const b of bindings) {
|
|
93
|
+
if (bound !== undefined && sameBinding(bound.get(b.prop), b.value))
|
|
94
|
+
continue;
|
|
95
|
+
b.value.__bind(handle, b.prop);
|
|
96
|
+
if (bound === undefined) {
|
|
97
|
+
bound = new Map();
|
|
98
|
+
boundValues.set(handle, bound);
|
|
99
|
+
}
|
|
100
|
+
bound.set(b.prop, b.value);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Forgets what a handle was bound to. The engine releases the bindings itself when a node is destroyed
|
|
106
|
+
* (er_anim_unbind_node), so this only drops our record — but it has to happen, because handles are
|
|
107
|
+
* recycled: a record left behind would make the next node to claim that handle look already-bound.
|
|
108
|
+
* Called on destroy for the node React hands us, and again on create because destroyNode reclaims a
|
|
109
|
+
* whole SUBTREE in C — React never mentions the descendants, so their handles come back from the free
|
|
110
|
+
* list still carrying a record.
|
|
111
|
+
*/
|
|
112
|
+
function forgetBindings(handle) {
|
|
113
|
+
boundValues.delete(handle);
|
|
114
|
+
}
|
|
115
|
+
|
|
38
116
|
/**
|
|
39
117
|
* Applies a node's resolved props, binding any Animated.Value found in its `style` to the matching
|
|
40
118
|
* node prop (native driver). This makes animated styles work on ANY host element — `<Pressable
|
|
41
119
|
* style={{ transform: [{ scale: v }] }}>` binds without an Animated.* wrapper — which is what the
|
|
42
|
-
* Flow B AOT compiler does too, so the two render paths stay in parity
|
|
43
|
-
*
|
|
120
|
+
* Flow B AOT compiler does too, so the two render paths stay in parity (and what an Animated.* wrapper
|
|
121
|
+
* relies on: it forwards its style untouched and is bound here like any other element).
|
|
44
122
|
*
|
|
45
123
|
* Returns the resolved flat style so a paired applyTextSpans call can reuse it instead of
|
|
46
124
|
* re-flattening props.style from scratch — style flattening (recursive array walk and object merge)
|
|
@@ -48,8 +126,21 @@ import {splitAnimatedStyle} from './embedded-react/split-style.js';
|
|
|
48
126
|
*/
|
|
49
127
|
function applyProps(type, handle, props) {
|
|
50
128
|
const {staticStyle, bindings} = splitAnimatedStyle(props.style);
|
|
129
|
+
// <Dial value={animatedValue}>: the value is a native-driver binding (ER_PROP_ARC_VALUE), not a prop —
|
|
130
|
+
// the engine ramps it with no JS per frame and damages only the swept sliver.
|
|
131
|
+
if (type === 'Dial') {
|
|
132
|
+
if (props.value && props.value.__animated) {
|
|
133
|
+
bindings.push({prop: 'value', value: props.value});
|
|
134
|
+
props = {...props, value: undefined};
|
|
135
|
+
}
|
|
136
|
+
if (props.valueStart && props.valueStart.__animated) {
|
|
137
|
+
bindings.push({prop: 'valueStart', value: props.valueStart});
|
|
138
|
+
props = {...props, valueStart: undefined};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
releaseStaleBindings(handle, bindings);
|
|
51
142
|
NativeUI.setProps(handle, buildProps(type, props, staticStyle));
|
|
52
|
-
|
|
143
|
+
applyBindings(handle, bindings);
|
|
53
144
|
return staticStyle;
|
|
54
145
|
}
|
|
55
146
|
|
|
@@ -289,11 +380,13 @@ export const hostConfig = {
|
|
|
289
380
|
const raster = rasterSvgArtifact(type, props);
|
|
290
381
|
if (raster) {
|
|
291
382
|
const handle = NativeUI.createNode('Image');
|
|
383
|
+
forgetBindings(handle);
|
|
292
384
|
applyProps('Image', handle, rasterImageProps(props, raster));
|
|
293
385
|
applyEvents(handle, null, props);
|
|
294
386
|
return handle;
|
|
295
387
|
}
|
|
296
388
|
const handle = NativeUI.createNode(type);
|
|
389
|
+
forgetBindings(handle);
|
|
297
390
|
const flatStyle = applyProps(type, handle, props);
|
|
298
391
|
applyTextSpans(type, handle, props, flatStyle);
|
|
299
392
|
applyVectorOps(type, handle, props);
|
|
@@ -338,10 +431,12 @@ export const hostConfig = {
|
|
|
338
431
|
removeChild(parent, child) {
|
|
339
432
|
NativeUI.removeChild(parent, child);
|
|
340
433
|
NativeUI.destroyNode(child);
|
|
434
|
+
forgetBindings(child);
|
|
341
435
|
},
|
|
342
436
|
removeChildFromContainer(container, child) {
|
|
343
437
|
NativeUI.removeChild(container, child);
|
|
344
438
|
NativeUI.destroyNode(child);
|
|
439
|
+
forgetBindings(child);
|
|
345
440
|
},
|
|
346
441
|
clearContainer() {
|
|
347
442
|
// Children are removed individually via removeChildFromContainer.
|