embedded-react 0.13.0 → 0.14.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 +78 -1
- package/aot/compile.mjs +2034 -232
- package/aot/style-map.mjs +20 -1
- package/assets/emit-container.mjs +4 -2
- package/cli.mjs +28 -2
- package/package.json +1 -1
- package/sim/embedded-react.wasm +0 -0
- package/src/embedded-react/PanResponder.js +1 -1
- package/src/embedded-react/index.d.ts +2 -1
- package/src/embedded-react/svg-ops.js +95 -11
- package/src/host-config.js +5 -0
- package/src/props.js +2 -0
- package/src/renderer.js +31 -0
package/aot/style-map.mjs
CHANGED
|
@@ -216,6 +216,15 @@ const KEYS = {
|
|
|
216
216
|
// View visual
|
|
217
217
|
backgroundColor: v => [{field: 'background_color', expr: colorLiteral(v)}],
|
|
218
218
|
borderRadius: v => [{field: 'border_radius', expr: dim(v)}],
|
|
219
|
+
// Per-corner radii; the engine reads 0 in one of these as "use borderRadius" (same as Flow A).
|
|
220
|
+
borderTopLeftRadius: v => [{field: 'border_top_left_radius', expr: dim(v)}],
|
|
221
|
+
borderTopRightRadius: v => [{field: 'border_top_right_radius', expr: dim(v)}],
|
|
222
|
+
borderBottomRightRadius: v => [
|
|
223
|
+
{field: 'border_bottom_right_radius', expr: dim(v)},
|
|
224
|
+
],
|
|
225
|
+
borderBottomLeftRadius: v => [
|
|
226
|
+
{field: 'border_bottom_left_radius', expr: dim(v)},
|
|
227
|
+
],
|
|
219
228
|
borderWidth: v => [{field: 'border_width', expr: dim(v)}],
|
|
220
229
|
borderColor: v => [{field: 'border_color', expr: colorLiteral(v)}],
|
|
221
230
|
opacity: v => [
|
|
@@ -236,6 +245,12 @@ const KEYS = {
|
|
|
236
245
|
letterSpacing: v => [{field: 'letter_spacing', expr: dim(v)}],
|
|
237
246
|
};
|
|
238
247
|
|
|
248
|
+
/** Whether the static lowering knows `key` at all (vs. knowing it but rejecting its value). */
|
|
249
|
+
export const isStyleKey = key => Object.hasOwn(KEYS, key);
|
|
250
|
+
|
|
251
|
+
/** Every style key the AOT lowers statically — listed in the "unsupported style key" diagnostic. */
|
|
252
|
+
export const STYLE_KEYS = Object.keys(KEYS);
|
|
253
|
+
|
|
239
254
|
/**
|
|
240
255
|
* Lowers one flattened style object to a list of ERProps field assignments.
|
|
241
256
|
*
|
|
@@ -246,7 +261,7 @@ export function lowerStyle(style) {
|
|
|
246
261
|
const out = [];
|
|
247
262
|
for (const [key, value] of Object.entries(style)) {
|
|
248
263
|
if (value === undefined || value === null) continue;
|
|
249
|
-
const fn = KEYS[key];
|
|
264
|
+
const fn = Object.hasOwn(KEYS, key) ? KEYS[key] : undefined;
|
|
250
265
|
if (!fn)
|
|
251
266
|
throw new Error(
|
|
252
267
|
`AOT: unsupported style key "${key}" (not yet lowered to ERProps)`,
|
|
@@ -297,6 +312,10 @@ const NUM_FIELDS = {
|
|
|
297
312
|
flexGrow: 'flex_grow',
|
|
298
313
|
flexShrink: 'flex_shrink',
|
|
299
314
|
borderRadius: 'border_radius',
|
|
315
|
+
borderTopLeftRadius: 'border_top_left_radius',
|
|
316
|
+
borderTopRightRadius: 'border_top_right_radius',
|
|
317
|
+
borderBottomRightRadius: 'border_bottom_right_radius',
|
|
318
|
+
borderBottomLeftRadius: 'border_bottom_left_radius',
|
|
300
319
|
borderWidth: 'border_width',
|
|
301
320
|
zIndex: 'z_index',
|
|
302
321
|
fontSize: 'font_size',
|
|
@@ -56,8 +56,10 @@ export const SECTION_ASSET_PACK = 2;
|
|
|
56
56
|
export const SECTION_VENDOR_BYTECODE = 3;
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
* CRC-32/IEEE (zlib polynomial 0xEDB88320), computed without a lookup table to match
|
|
60
|
-
*
|
|
59
|
+
* CRC-32/IEEE (zlib polynomial 0xEDB88320), computed without a lookup table to match er_crc32() in
|
|
60
|
+
* bridges/quickjs/er_runtime.c byte-for-byte — the one checksum of the whole delivery pipeline (this
|
|
61
|
+
* container, the hot-reload transport frame that carries it, and the device's verification of both).
|
|
62
|
+
* hotreload/protocol.mjs imports this rather than keeping its own.
|
|
61
63
|
*
|
|
62
64
|
* @param {Buffer|Uint8Array} buf Bytes to checksum.
|
|
63
65
|
* @returns {number} The CRC as an unsigned 32-bit integer.
|
package/cli.mjs
CHANGED
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
writeFileSync,
|
|
32
32
|
} from 'node:fs';
|
|
33
33
|
import {fileURLToPath, pathToFileURL} from 'node:url';
|
|
34
|
-
import {dirname, relative, resolve} from 'node:path';
|
|
34
|
+
import {basename, dirname, relative, resolve} from 'node:path';
|
|
35
35
|
import {tmpdir} from 'node:os';
|
|
36
36
|
import {buildApp, runDevServer} from './sim-server.mjs';
|
|
37
37
|
import {
|
|
@@ -339,6 +339,27 @@ async function exportApp(args) {
|
|
|
339
339
|
}
|
|
340
340
|
|
|
341
341
|
/** Resolve the root component file for the AOT compiler (App.jsx), distinct from the registry entry. */
|
|
342
|
+
/**
|
|
343
|
+
* The project identity stamped into app.gen.h as ER_AOT_DEMO / ER_AOT_DEMO_<name>, which a board example
|
|
344
|
+
* guards on (see the header's own comment). It is the directory of the nearest package.json at or above
|
|
345
|
+
* the App component, so `demos/watch-face/App.jsx` is `watch-face` whether the build runs from that
|
|
346
|
+
* directory or names the entry from somewhere else — and a scaffolded `src/App.jsx` reports its project
|
|
347
|
+
* folder rather than `src`. Deriving it from the cwd instead would stamp whatever directory you ran from.
|
|
348
|
+
*/
|
|
349
|
+
function projectIdentity(appPath) {
|
|
350
|
+
let dir = dirname(appPath);
|
|
351
|
+
for (let i = 0; i < 64; i++) {
|
|
352
|
+
// A package.json at a filesystem root has no directory name to report — basename('/') is '' — so
|
|
353
|
+
// treat it as absent rather than stamp an empty identity (`ER_AOT_DEMO_` with nothing after it).
|
|
354
|
+
if (existsSync(resolve(dir, 'package.json')) && basename(dir))
|
|
355
|
+
return basename(dir);
|
|
356
|
+
const up = dirname(dir);
|
|
357
|
+
if (up === dir) break; // filesystem root
|
|
358
|
+
dir = up;
|
|
359
|
+
}
|
|
360
|
+
return basename(dirname(appPath)) || 'app';
|
|
361
|
+
}
|
|
362
|
+
|
|
342
363
|
function resolveAppComponent(cwd, explicit) {
|
|
343
364
|
if (explicit) {
|
|
344
365
|
const p = resolve(cwd, explicit);
|
|
@@ -378,7 +399,12 @@ async function buildAot(cwd, explicit, outDir, screen) {
|
|
|
378
399
|
try {
|
|
379
400
|
// Bake <Svg source> .svg imports → vector artifacts (incl. gradients), then compile with them in hand.
|
|
380
401
|
const svgArtifacts = await bakeSvgArtifacts(src, appDir);
|
|
381
|
-
|
|
402
|
+
// app.gen.h records WHICH app it came from and a board example guards on that marker, so it must name
|
|
403
|
+
// the source project — the same ER_AOT_DEMO_watch_2d_face that `npm run aot -- watch-face` produces.
|
|
404
|
+
result = compileSource(src, projectIdentity(appPath), {
|
|
405
|
+
filename: appPath,
|
|
406
|
+
svgArtifacts,
|
|
407
|
+
});
|
|
382
408
|
} catch (e) {
|
|
383
409
|
console.error(e && e.aotLoc ? e.message : e?.message || String(e));
|
|
384
410
|
process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "embedded-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "React Native-style component package + reconciler that drives the embedded-react C engine through the QuickJS NativeUI bridge (Flow A).",
|
|
6
6
|
"license": "Apache-2.0",
|
package/sim/embedded-react.wasm
CHANGED
|
Binary file
|
|
@@ -85,7 +85,7 @@ const SUPPORTED = [
|
|
|
85
85
|
/**
|
|
86
86
|
* The engine's monotonic millisecond clock, used for velocity. `performance.now()` is installed by the
|
|
87
87
|
* QuickJS runtime on every context (it is React's scheduler clock) and exists in the simulator and in
|
|
88
|
-
* Node; `Date`
|
|
88
|
+
* Node; `Date.now()` jumps whenever the host sets the wall clock, so it is never used here.
|
|
89
89
|
* The clock only advances when the host ticks, so a dt of 0 is normal and leaves velocity untouched.
|
|
90
90
|
*/
|
|
91
91
|
const now = () =>
|
|
@@ -509,6 +509,7 @@ export interface TextInputProps extends TouchEventProps {
|
|
|
509
509
|
placeholder?: string;
|
|
510
510
|
placeholderTextColor?: string;
|
|
511
511
|
editable?: boolean;
|
|
512
|
+
secureTextEntry?: boolean;
|
|
512
513
|
visible?: boolean;
|
|
513
514
|
onChangeText?: (text: string) => void;
|
|
514
515
|
onSubmitEditing?: (event: NativeEvent<'submitEditing'>) => void;
|
|
@@ -539,8 +540,8 @@ export interface ActivityIndicatorProps extends TouchEventProps {
|
|
|
539
540
|
export interface ModalProps extends TouchEventProps {
|
|
540
541
|
style?: StyleProp<ModalStyle>;
|
|
541
542
|
children?: ReactNode;
|
|
542
|
-
/** Shows or hides the modal. Unlike other components this does not mean style `display`. */
|
|
543
543
|
visible?: boolean;
|
|
544
|
+
backdropColor?: string;
|
|
544
545
|
ref?: Ref<NodeHandle>;
|
|
545
546
|
}
|
|
546
547
|
|
|
@@ -299,8 +299,62 @@ function arcToCubics(x0, y0, rx, ry, phiDeg, largeArc, sweep, x, y) {
|
|
|
299
299
|
/**
|
|
300
300
|
* Parses an SVG `d` string into engine path ops (a flat number array, NO leading SHAPE op). Supports
|
|
301
301
|
* M/L/H/V/C/S/Q/T/A/Z and their relative (lowercase) forms; arcs are converted to cubics.
|
|
302
|
+
*
|
|
303
|
+
* Results are cached by `d` string, so the returned array is SHARED — read it, never mutate it.
|
|
302
304
|
*/
|
|
303
305
|
export function parsePath(d) {
|
|
306
|
+
return pathEntry(d).ops;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Parsed `d` strings, keyed on the string itself. An <Svg> recompiles its whole tape whenever any
|
|
310
|
+
// part of it changes, so without this a moving needle re-runs the tokenizer and the arc->cubic
|
|
311
|
+
// conversion over every static path beside it, only for the engine to memcmp the result and throw
|
|
312
|
+
// the identical bytes away. Held to both an op budget and an entry count, and a path too big to fit
|
|
313
|
+
// the budget on its own is never stored, so nothing can push it over; an entry also holds one
|
|
314
|
+
// transformed copy (see xf), so the real footprint is ~2x the op budget. The bridge caps a single
|
|
315
|
+
// <Svg> at 1024 ops and 16 shapes, so this holds several screens' worth.
|
|
316
|
+
const PATH_CACHE = new Map();
|
|
317
|
+
const PATH_CACHE_MAX_OPS = 4096;
|
|
318
|
+
const PATH_CACHE_MAX_ENTRIES = 128;
|
|
319
|
+
let _pathCacheOps = 0;
|
|
320
|
+
|
|
321
|
+
/** Cache record for one `d` string: `ops` are the parsed path ops, `xf` the last transform applied
|
|
322
|
+
* to them (see transformCached). Coerces its key, so a non-string `d` still hits the cache instead
|
|
323
|
+
* of keying a fresh entry off object identity every call. */
|
|
324
|
+
function pathEntry(d) {
|
|
325
|
+
const key = typeof d === 'string' ? d : String(d);
|
|
326
|
+
const hit = PATH_CACHE.get(key);
|
|
327
|
+
if (hit !== undefined) {
|
|
328
|
+
// A Map iterates oldest-first, so re-inserting on a hit makes eviction LRU — which is what keeps
|
|
329
|
+
// a static face cached next to a needle whose `d` is rebuilt every frame.
|
|
330
|
+
PATH_CACHE.delete(key);
|
|
331
|
+
PATH_CACHE.set(key, hit);
|
|
332
|
+
return hit;
|
|
333
|
+
}
|
|
334
|
+
const entry = {ops: parsePathUncached(key), xf: null};
|
|
335
|
+
// A path that alone exceeds the whole budget is parsed but not stored: caching it would blow the
|
|
336
|
+
// bound it is measured against, and at that size it is already past the bridge's per-<Svg> op cap.
|
|
337
|
+
if (entry.ops.length > PATH_CACHE_MAX_OPS) return entry;
|
|
338
|
+
PATH_CACHE.set(key, entry);
|
|
339
|
+
_pathCacheOps += entry.ops.length;
|
|
340
|
+
while (
|
|
341
|
+
_pathCacheOps > PATH_CACHE_MAX_OPS ||
|
|
342
|
+
PATH_CACHE.size > PATH_CACHE_MAX_ENTRIES
|
|
343
|
+
) {
|
|
344
|
+
const oldest = PATH_CACHE.keys().next().value;
|
|
345
|
+
_pathCacheOps -= PATH_CACHE.get(oldest).ops.length;
|
|
346
|
+
PATH_CACHE.delete(oldest);
|
|
347
|
+
}
|
|
348
|
+
return entry;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** Drops every cached path. Only for tests that measure parse work. */
|
|
352
|
+
export function clearPathCache() {
|
|
353
|
+
PATH_CACHE.clear();
|
|
354
|
+
_pathCacheOps = 0;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function parsePathUncached(d) {
|
|
304
358
|
const ops = [];
|
|
305
359
|
const toks = tokenizePath(d);
|
|
306
360
|
let cx = 0;
|
|
@@ -452,14 +506,14 @@ function circleOps(p) {
|
|
|
452
506
|
];
|
|
453
507
|
}
|
|
454
508
|
|
|
455
|
-
|
|
456
|
-
|
|
509
|
+
/** An ellipse as a `d` string: an arc-free path of four cubic Béziers (kappa) once parsePath lowers
|
|
510
|
+
* the two `A` commands. Returned as a string so it goes through the same parse cache as <Path d>. */
|
|
511
|
+
function ellipsePathD(p) {
|
|
457
512
|
const cx = num(p.cx, 0);
|
|
458
513
|
const cy = num(p.cy, 0);
|
|
459
514
|
const rx = num(p.rx, 0);
|
|
460
515
|
const ry = num(p.ry, 0);
|
|
461
|
-
|
|
462
|
-
return parsePath(d);
|
|
516
|
+
return `M ${cx - rx} ${cy} A ${rx} ${ry} 0 1 0 ${cx + rx} ${cy} A ${rx} ${ry} 0 1 0 ${cx - rx} ${cy} Z`;
|
|
463
517
|
}
|
|
464
518
|
|
|
465
519
|
/**
|
|
@@ -793,6 +847,27 @@ function transformOps(ops, T) {
|
|
|
793
847
|
return out;
|
|
794
848
|
}
|
|
795
849
|
|
|
850
|
+
/**
|
|
851
|
+
* transformOps against a cached path, reusing the last result when the transform is unchanged. One
|
|
852
|
+
* slot per path: a shape's transform is the root viewBox scale composed with its <G>s, which almost
|
|
853
|
+
* never moves between commits, so an untouched shape costs a compare instead of a rebuild. The same
|
|
854
|
+
* `d` drawn under several different transforms just misses and pays the full transform.
|
|
855
|
+
*/
|
|
856
|
+
function transformCached(entry, T) {
|
|
857
|
+
const xf = entry.xf;
|
|
858
|
+
if (
|
|
859
|
+
xf &&
|
|
860
|
+
xf.sx === T.sx &&
|
|
861
|
+
xf.sy === T.sy &&
|
|
862
|
+
xf.tx === T.tx &&
|
|
863
|
+
xf.ty === T.ty
|
|
864
|
+
)
|
|
865
|
+
return xf.out;
|
|
866
|
+
const out = transformOps(entry.ops, T);
|
|
867
|
+
entry.xf = {sx: T.sx, sy: T.sy, tx: T.tx, ty: T.ty, out};
|
|
868
|
+
return out;
|
|
869
|
+
}
|
|
870
|
+
|
|
796
871
|
function isElement(c) {
|
|
797
872
|
return c && typeof c === 'object' && c.type != null && c.props != null;
|
|
798
873
|
}
|
|
@@ -900,10 +975,14 @@ export function flattenSvg(props) {
|
|
|
900
975
|
}
|
|
901
976
|
if (!SVG_TAGS.includes(c.type)) return warnSvgChild(c);
|
|
902
977
|
|
|
978
|
+
// Path/Ellipse geometry comes from a `d` string and is cached (parse + transform) by that string;
|
|
979
|
+
// the primitives build a fixed handful of numbers, which is cheaper than any cache lookup.
|
|
980
|
+
let entry = null;
|
|
903
981
|
let shapeOps = null;
|
|
904
|
-
if (c.type === 'Path' && p.d)
|
|
982
|
+
if (c.type === 'Path' && p.d)
|
|
983
|
+
entry = pathEntry(p.d); // pathEntry coerces the key
|
|
984
|
+
else if (c.type === 'Ellipse') entry = pathEntry(ellipsePathD(p));
|
|
905
985
|
else if (c.type === 'Circle') shapeOps = circleOps(p);
|
|
906
|
-
else if (c.type === 'Ellipse') shapeOps = ellipseOps(p);
|
|
907
986
|
else if (c.type === 'Rect') shapeOps = rectOps(p);
|
|
908
987
|
else if (c.type === 'Line') shapeOps = lineOps(p);
|
|
909
988
|
else if (c.type === 'Arc')
|
|
@@ -914,12 +993,17 @@ export function flattenSvg(props) {
|
|
|
914
993
|
num(p.startAngle, 0),
|
|
915
994
|
num(p.endAngle, 0),
|
|
916
995
|
);
|
|
917
|
-
|
|
996
|
+
const baseOps = entry ? entry.ops : shapeOps;
|
|
997
|
+
if (!baseOps || baseOps.length === 0) return;
|
|
918
998
|
|
|
999
|
+
const seg = entry ? transformCached(entry, T) : transformOps(baseOps, T);
|
|
919
1000
|
const paintIndex = paints.length / PAINT_STRIDE;
|
|
920
1001
|
const scale = (T.sx + T.sy) / 2; // stroke-width scale (uniform assumed)
|
|
921
1002
|
paints.push(...paintRecord(merged, scale, gradients));
|
|
922
|
-
|
|
1003
|
+
// Appended one at a time: `seg` can be a long cached tape, and spreading it into push() both
|
|
1004
|
+
// copies it into an argument list and risks the call-argument limit.
|
|
1005
|
+
ops.push(VOP_SHAPE, paintIndex);
|
|
1006
|
+
for (let k = 0; k < seg.length; k++) ops.push(seg[k]);
|
|
923
1007
|
};
|
|
924
1008
|
|
|
925
1009
|
walk(props.children, PAINT_DEFAULT, root);
|
|
@@ -1025,7 +1109,7 @@ export function warnVectorCaps(
|
|
|
1025
1109
|
console.warn(
|
|
1026
1110
|
`embedded-react: an <Svg> op-tape is too long (${opsLen} > ${maxOps} floats) and will be truncated — ` +
|
|
1027
1111
|
`the shape gets cut off. Simplify the path (fewer/coarser curves) or split it across <Svg> nodes; ` +
|
|
1028
|
-
`raising the limit needs
|
|
1112
|
+
`raising the limit needs ERUI_VECTOR_TAPE_MAX.`,
|
|
1029
1113
|
);
|
|
1030
1114
|
}
|
|
1031
1115
|
const shapes = (paintsLen / PAINT_STRIDE) | 0;
|
|
@@ -1033,7 +1117,7 @@ export function warnVectorCaps(
|
|
|
1033
1117
|
_warnedVecPaints = true;
|
|
1034
1118
|
console.warn(
|
|
1035
1119
|
`embedded-react: an <Svg> has ${shapes} shapes (> ${maxPaints}) — the extra shapes won't render. ` +
|
|
1036
|
-
`Split them across multiple <Svg> nodes; raising the limit needs
|
|
1120
|
+
`Split them across multiple <Svg> nodes; raising the limit needs ERUI_VECTOR_PAINTS_MAX.`,
|
|
1037
1121
|
);
|
|
1038
1122
|
}
|
|
1039
1123
|
if (!_warnedVecGrads && maxGrads > 0 && gradsLen > maxGrads) {
|
|
@@ -1041,7 +1125,7 @@ export function warnVectorCaps(
|
|
|
1041
1125
|
console.warn(
|
|
1042
1126
|
`embedded-react: an <Svg> references ${gradsLen} gradients (> ${maxGrads}) — the extra gradients are ` +
|
|
1043
1127
|
`dropped and shapes that use them fall back to solid fills/strokes. Reuse fewer distinct gradients across ` +
|
|
1044
|
-
`shapes; raising the limit needs
|
|
1128
|
+
`shapes; raising the limit needs ERUI_VECTOR_GRADS_MAX.`,
|
|
1045
1129
|
);
|
|
1046
1130
|
}
|
|
1047
1131
|
}
|
package/src/host-config.js
CHANGED
|
@@ -367,10 +367,15 @@ export const hostConfig = {
|
|
|
367
367
|
},
|
|
368
368
|
|
|
369
369
|
// --- Commit lifecycle ---
|
|
370
|
+
// These two bracket React's mutation phase exactly, which is the only place the reconciler touches
|
|
371
|
+
// the bridge — so on an instrumented build they are what makes the marshaling bucket cover the JS
|
|
372
|
+
// glue (applyProps, style flattening) and not just the NativeUI calls it ends up making.
|
|
370
373
|
prepareForCommit() {
|
|
374
|
+
NativeUI.perfMarshalBegin?.();
|
|
371
375
|
return null;
|
|
372
376
|
},
|
|
373
377
|
resetAfterCommit() {
|
|
378
|
+
NativeUI.perfMarshalEnd?.();
|
|
374
379
|
NativeUI.commit();
|
|
375
380
|
},
|
|
376
381
|
|
package/src/props.js
CHANGED
|
@@ -27,8 +27,10 @@ export const PASSTHROUGH = [
|
|
|
27
27
|
'placeholder',
|
|
28
28
|
'placeholderTextColor',
|
|
29
29
|
'editable',
|
|
30
|
+
'secureTextEntry',
|
|
30
31
|
'animating',
|
|
31
32
|
'visible',
|
|
33
|
+
'backdropColor', // <Modal>'s scrim, as React Native takes it (the style key works too)
|
|
32
34
|
'resizeMode',
|
|
33
35
|
'tintColor',
|
|
34
36
|
'imageName',
|
package/src/renderer.js
CHANGED
|
@@ -27,6 +27,37 @@ const reconciler = Reconciler(hostConfig);
|
|
|
27
27
|
|
|
28
28
|
const LegacyRoot = 0;
|
|
29
29
|
|
|
30
|
+
// Host-initiated updates — a native event, a timer, a promise continuation — are outside any React
|
|
31
|
+
// batch, so in LegacyRoot mode each setState renders and commits on its own: three animations
|
|
32
|
+
// ticking on the same frame cost three renders and three engine commits to paint one frame. The
|
|
33
|
+
// bridge runs the frame pump — and each native event — inside this wrapper, which puts everything a
|
|
34
|
+
// frame does in one batch and leaves it as one render and one commit. Installed here rather than at
|
|
35
|
+
// createRoot() so the reconciler that batches is the one that renders.
|
|
36
|
+
// On an instrumented build the batcher is also where the JS phase's split gets drawn (er_perf.h):
|
|
37
|
+
// `fn(a, b)` is the callback, and whatever batchedUpdates does around it is React's render. That
|
|
38
|
+
// boundary is only visible from here — React flushes when it decides to, not reliably at the batch
|
|
39
|
+
// call the C side can see — so marking it in C measured the call overhead and left reconcile at ~0.
|
|
40
|
+
// The instrumented wrapper is chosen ONCE, here, so an ordinary build runs the plain one.
|
|
41
|
+
NativeUI.setBatcher?.(
|
|
42
|
+
NativeUI.perfRenderBegin
|
|
43
|
+
? (fn, a, b) => {
|
|
44
|
+
NativeUI.perfRenderBegin();
|
|
45
|
+
try {
|
|
46
|
+
return reconciler.batchedUpdates(() => {
|
|
47
|
+
NativeUI.perfCallbackBegin();
|
|
48
|
+
try {
|
|
49
|
+
return fn(a, b);
|
|
50
|
+
} finally {
|
|
51
|
+
NativeUI.perfCallbackEnd();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
} finally {
|
|
55
|
+
NativeUI.perfRenderEnd();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
: (fn, a, b) => reconciler.batchedUpdates(() => fn(a, b)),
|
|
59
|
+
);
|
|
60
|
+
|
|
30
61
|
/**
|
|
31
62
|
* Creates a root bound to a screen-sized container node.
|
|
32
63
|
*
|