embedded-react 0.19.0 → 0.21.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/NOTICE +5 -0
- package/README.md +8 -3
- package/aot/app-file-loader.mjs +116 -0
- package/aot/compile.mjs +180 -90
- package/aot/compiler/animations.mjs +568 -317
- package/aot/compiler/boot.mjs +97 -35
- package/aot/compiler/branch-merge.mjs +4 -3
- package/aot/compiler/check.mjs +70 -18
- package/aot/compiler/collect.mjs +787 -288
- package/aot/compiler/contexts.mjs +391 -0
- package/aot/compiler/control-flow.mjs +439 -268
- package/aot/compiler/custom-hooks.mjs +686 -0
- package/aot/compiler/diagnostics.mjs +22 -25
- package/aot/compiler/elements/activity-indicator.mjs +25 -24
- package/aot/compiler/elements/button.mjs +182 -0
- package/aot/compiler/elements/dial.mjs +91 -77
- package/aot/compiler/elements/flat-list.mjs +24 -22
- package/aot/compiler/elements/image-background.mjs +76 -0
- package/aot/compiler/elements/image.mjs +52 -50
- package/aot/compiler/elements/modal.mjs +31 -30
- package/aot/compiler/elements/props.mjs +61 -26
- package/aot/compiler/elements/rewrite.mjs +118 -0
- package/aot/compiler/elements/section-list.mjs +370 -0
- package/aot/compiler/elements/switch.mjs +42 -34
- package/aot/compiler/elements/text-input.mjs +34 -32
- package/aot/compiler/expressions.mjs +1685 -392
- package/aot/compiler/handlers.mjs +2029 -547
- package/aot/compiler/helper-values.mjs +312 -0
- package/aot/compiler/ir/functions.mjs +11 -1
- package/aot/compiler/ir/nodes.mjs +43 -4
- package/aot/compiler/ir/reads.mjs +223 -22
- package/aot/compiler/ir/text.mjs +5 -1
- package/aot/compiler/ir/types.mjs +26 -14
- package/aot/compiler/ir/vectors.mjs +5 -1
- package/aot/compiler/kept-states.mjs +177 -0
- package/aot/compiler/keyboard.mjs +17 -7
- package/aot/compiler/list-items.mjs +226 -0
- package/aot/compiler/list-order.mjs +586 -0
- package/aot/compiler/list-split.mjs +259 -0
- package/aot/compiler/loops.mjs +582 -0
- package/aot/compiler/lower.mjs +246 -111
- package/aot/compiler/native-files.mjs +439 -0
- package/aot/compiler/native-header.mjs +335 -0
- package/aot/compiler/native-modules.mjs +1173 -0
- package/aot/compiler/nodes.mjs +195 -172
- package/aot/compiler/options.mjs +37 -31
- package/aot/compiler/out.mjs +32 -23
- package/aot/compiler/package/animations.mjs +779 -0
- package/aot/compiler/package/arena.mjs +252 -0
- package/aot/compiler/package/assemble.mjs +175 -0
- package/aot/compiler/package/bytecode.mjs +315 -0
- package/aot/compiler/package/checks.mjs +1026 -0
- package/aot/compiler/package/codegen.mjs +2168 -0
- package/aot/compiler/package/enums.mjs +148 -0
- package/aot/compiler/package/format.mjs +771 -0
- package/aot/compiler/package/layouts.mjs +136 -0
- package/aot/compiler/package/lower.mjs +2103 -0
- package/aot/compiler/package/props.mjs +118 -0
- package/aot/compiler/package/string-caps.mjs +515 -0
- package/aot/compiler/package/tables.mjs +127 -0
- package/aot/compiler/package/vectors.mjs +502 -0
- package/aot/compiler/package/writer.mjs +686 -0
- package/aot/compiler/pan-responder.mjs +69 -61
- package/aot/compiler/parse.mjs +23 -21
- package/aot/compiler/record-shapes.mjs +246 -0
- package/aot/compiler/records.mjs +654 -0
- package/aot/compiler/reducers.mjs +272 -0
- package/aot/compiler/static-eval.mjs +340 -30
- package/aot/compiler/style-text.mjs +178 -174
- package/aot/compiler/svg.mjs +480 -251
- package/aot/compiler/switch-cases.mjs +198 -0
- package/aot/compiler/tagged-records.mjs +450 -0
- package/aot/compiler/typing.mjs +307 -0
- package/aot/compiler/updaters.mjs +320 -0
- package/aot/compiler/window-dimensions.mjs +94 -0
- package/aot/compiler/worked-values.mjs +319 -0
- package/aot/demo-file.mjs +30 -0
- package/aot/screenshot-smoke.mjs +54 -40
- package/aot/style-map.mjs +152 -92
- package/assets/bake-font.mjs +123 -77
- package/assets/bake-image.mjs +39 -22
- package/assets/bake-svg.mjs +361 -262
- package/assets/build-builtin-font.mjs +11 -7
- package/assets/emit-c.mjs +77 -58
- package/assets/emit-container.mjs +123 -37
- package/assets/emit-pack.mjs +77 -67
- package/assets/font-config.mjs +9 -6
- package/assets/font-sizes.mjs +163 -123
- package/assets/glyph-coverage.mjs +74 -54
- package/assets/index.mjs +31 -9
- package/assets/rasterize.mjs +126 -99
- package/assets/svg-loader.mjs +8 -8
- package/build.mjs +23 -13
- package/cli.mjs +402 -172
- package/compile-bin.mjs +3 -3
- package/flash.mjs +537 -0
- package/hotreload/dev-device.mjs +90 -33
- package/hotreload/pack-app.mjs +55 -43
- package/hotreload/pack-split.mjs +62 -64
- package/hotreload/package-transfer.mjs +175 -0
- package/hotreload/protocol.mjs +50 -37
- package/hotreload/uploader.mjs +38 -27
- package/hotreload/watch-tree.mjs +19 -19
- package/pack-container.mjs +37 -21
- package/package.json +7 -8
- package/persist-transform.mjs +34 -28
- package/qjsc-wasm.mjs +25 -14
- package/sim/embedded-react.cjs +1 -1
- package/sim/embedded-react.js +1 -1
- package/sim/embedded-react.wasm +0 -0
- package/sim/index.html +94 -85
- package/sim-server.mjs +113 -94
- package/src/embedded-react/Animated.js +24 -24
- package/src/embedded-react/Dimensions.js +37 -0
- package/src/embedded-react/Easing.js +1 -1
- package/src/embedded-react/FlatList.js +3 -3
- package/src/embedded-react/LayoutAnimation.js +8 -5
- package/src/embedded-react/PanResponder.js +75 -71
- package/src/embedded-react/Pressable.js +2 -8
- package/src/embedded-react/SectionList.js +7 -9
- package/src/embedded-react/StyleSheet.js +4 -3
- package/src/embedded-react/TouchableOpacity.js +13 -8
- package/src/embedded-react/index.d.ts +88 -8
- package/src/embedded-react/index.js +2 -0
- package/src/embedded-react/layout-anim-config.js +10 -4
- package/src/embedded-react/list-child.js +5 -5
- package/src/embedded-react/named-colors.js +1 -1
- package/src/embedded-react/nativeModule.js +462 -0
- package/src/embedded-react/split-style.js +11 -11
- package/src/embedded-react/svg-ops.js +760 -593
- package/src/embedded-react/useHostValue.js +3 -3
- package/src/embedded-react/usePersistentState.js +6 -6
- package/src/embedded-react/warn-props.js +1 -1
- package/src/host-config.js +60 -53
- package/src/props.js +49 -41
- package/src/renderer.js +7 -4
- package/aot/compiler/assemble.mjs +0 -944
- package/aot/compiler/c/animations.mjs +0 -436
- package/aot/compiler/c/boot.mjs +0 -127
- package/aot/compiler/c/expressions.mjs +0 -270
- package/aot/compiler/c/functions.mjs +0 -268
- package/aot/compiler/c/keyboard.mjs +0 -96
- package/aot/compiler/c/nodes.mjs +0 -303
- package/aot/compiler/c/pan-responder.mjs +0 -136
- package/aot/compiler/c/statements.mjs +0 -319
- package/aot/compiler/c/text.mjs +0 -83
- package/aot/compiler/c/vectors.mjs +0 -381
- package/aot/compiler/c-syntax.mjs +0 -127
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
|
|
17
17
|
// useHostValue — a numeric value fed by the C HOST at runtime, not by the app.
|
|
18
18
|
//
|
|
19
|
-
// Flow B (AOT): the compiler recognizes `const steps = useHostValue(0)` and lowers it to an ordinary
|
|
20
|
-
//
|
|
21
|
-
//
|
|
19
|
+
// Flow B (AOT): the compiler recognizes `const steps = useHostValue(0)` and lowers it to an ordinary state
|
|
20
|
+
// slot, which the package names as an input. The host (e.g. a pedometer reading an IMU in main.c) finds it
|
|
21
|
+
// with erb_input_find("steps") and sets it with erb_input_set_int(); the app renders the value like any state.
|
|
22
22
|
// There is no JS setter — the host is the only writer.
|
|
23
23
|
//
|
|
24
24
|
// Flow A / simulator: there is no host, so this simply returns the initial value (the simulator has no
|
|
@@ -47,23 +47,23 @@ export function usePersistentState(key, initial) {
|
|
|
47
47
|
return typeof initial === 'function' ? initial() : initial;
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
const
|
|
50
|
+
const setPersistedValue = useCallback(
|
|
51
51
|
next => {
|
|
52
|
-
setValue(
|
|
53
|
-
const
|
|
52
|
+
setValue(previous => {
|
|
53
|
+
const resolved = typeof next === 'function' ? next(previous) : next;
|
|
54
54
|
const store = globalThis.__erPersist;
|
|
55
55
|
if (store) {
|
|
56
56
|
try {
|
|
57
|
-
store.set(key, JSON.stringify(
|
|
57
|
+
store.set(key, JSON.stringify(resolved));
|
|
58
58
|
} catch {
|
|
59
59
|
/* unserializable value — skip persistence, keep the in-memory state */
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
return
|
|
62
|
+
return resolved;
|
|
63
63
|
});
|
|
64
64
|
},
|
|
65
65
|
[key],
|
|
66
66
|
);
|
|
67
67
|
|
|
68
|
-
return [value,
|
|
68
|
+
return [value, setPersistedValue];
|
|
69
69
|
}
|
|
@@ -68,7 +68,7 @@ export function createPropWarner(component, supported, hint, quiet = []) {
|
|
|
68
68
|
return props => {
|
|
69
69
|
if (warned) return;
|
|
70
70
|
const names = Object.keys(props).filter(
|
|
71
|
-
|
|
71
|
+
name => !supported.includes(name) && !quiet.includes(name),
|
|
72
72
|
);
|
|
73
73
|
if (names.length === 0) return;
|
|
74
74
|
warned = true;
|
package/src/host-config.js
CHANGED
|
@@ -34,7 +34,7 @@ import {splitAnimatedStyle} from './embedded-react/split-style.js';
|
|
|
34
34
|
|
|
35
35
|
// --- Animated bindings ---------------------------------------------------------------------------
|
|
36
36
|
// A bound prop is owned by the engine from then on: it re-pushes the animated value over the static
|
|
37
|
-
// props of every later setProps (
|
|
37
|
+
// props of every later setProps (er_animation_reapply_bound), which is what keeps a re-render from jumping
|
|
38
38
|
// a running animation back to its declared value. Nothing in React says "this prop stopped being
|
|
39
39
|
// animated", so the binding has to be released explicitly or it keeps writing the prop forever — and a
|
|
40
40
|
// prop that swapped Animated.Values ends up written by both. Instances are bare node handles with no
|
|
@@ -46,16 +46,16 @@ const boundValues = new Map();
|
|
|
46
46
|
* alone. Identity settles an Animated.Value; an interpolation is a throwaway object that
|
|
47
47
|
* `value.interpolate(...)` rebuilds on every render, so it answers __bindEq for itself.
|
|
48
48
|
*/
|
|
49
|
-
function sameBinding(
|
|
50
|
-
if (
|
|
51
|
-
if (
|
|
52
|
-
return typeof
|
|
49
|
+
function sameBinding(previous, next) {
|
|
50
|
+
if (previous === next) return true;
|
|
51
|
+
if (previous == null || next == null) return false;
|
|
52
|
+
return typeof previous.__bindEq === 'function' && previous.__bindEq(next);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/** The value `bindings` (from splitAnimatedStyle) drives `prop` with, or undefined if none does. */
|
|
56
56
|
function bindingFor(bindings, prop) {
|
|
57
|
-
for (const
|
|
58
|
-
if (
|
|
57
|
+
for (const binding of bindings) {
|
|
58
|
+
if (binding.prop === prop) return binding.value;
|
|
59
59
|
}
|
|
60
60
|
return undefined;
|
|
61
61
|
}
|
|
@@ -86,25 +86,27 @@ function releaseStaleBindings(handle, bindings) {
|
|
|
86
86
|
function applyBindings(handle, bindings) {
|
|
87
87
|
if (bindings.length === 0) return;
|
|
88
88
|
let bound = boundValues.get(handle);
|
|
89
|
-
for (const
|
|
90
|
-
if (
|
|
89
|
+
for (const binding of bindings) {
|
|
90
|
+
if (
|
|
91
|
+
bound !== undefined &&
|
|
92
|
+
sameBinding(bound.get(binding.prop), binding.value)
|
|
93
|
+
)
|
|
91
94
|
continue;
|
|
92
|
-
|
|
95
|
+
binding.value.__bind(handle, binding.prop);
|
|
93
96
|
if (bound === undefined) {
|
|
94
97
|
bound = new Map();
|
|
95
98
|
boundValues.set(handle, bound);
|
|
96
99
|
}
|
|
97
|
-
bound.set(
|
|
100
|
+
bound.set(binding.prop, binding.value);
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
103
|
|
|
101
104
|
/**
|
|
102
105
|
* Forgets what a handle was bound to. The engine releases the bindings itself when a node is destroyed
|
|
103
|
-
* (
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* list still carrying a record.
|
|
106
|
+
* (er_animation_unbind_node), so this only drops our record — but it has to happen, or the map keeps a
|
|
107
|
+
* record for every destroyed node. Called on destroy for the node React hands us, and again from
|
|
108
|
+
* detachDeletedInstance because destroyNode reclaims a whole SUBTREE in C — React never hands
|
|
109
|
+
* removeChild the descendants, and detaching is where it names them.
|
|
108
110
|
*/
|
|
109
111
|
function forgetBindings(handle) {
|
|
110
112
|
boundValues.delete(handle);
|
|
@@ -115,6 +117,7 @@ function forgetBindings(handle) {
|
|
|
115
117
|
// children of a parent that did not fit are never attached to anything, and removing that parent frees
|
|
116
118
|
// nothing in C. Each failed create gets its own negative instance (the bridge ignores handles <= 0), and
|
|
117
119
|
// the children appended to it are kept here so they are freed when it is deleted.
|
|
120
|
+
const FAILED_CREATE = 0; // createNode's handle when the pool is full
|
|
118
121
|
const orphansOf = new Map(); // failed instance → Set of child handles
|
|
119
122
|
let nextFailedInstance = -1;
|
|
120
123
|
|
|
@@ -184,13 +187,14 @@ function applyTextSpans(type, handle, props, flatStyle) {
|
|
|
184
187
|
}
|
|
185
188
|
|
|
186
189
|
/** Resolves an <Svg>'s render-box dimension from style/props, falling back to the source's intrinsic size. */
|
|
187
|
-
function svgBoxSize(props,
|
|
188
|
-
const
|
|
189
|
-
props.style && typeof props.style[
|
|
190
|
-
? props.style[
|
|
190
|
+
function svgBoxSize(props, dimension, intrinsic) {
|
|
191
|
+
const styleSize =
|
|
192
|
+
props.style && typeof props.style[dimension] === 'number'
|
|
193
|
+
? props.style[dimension]
|
|
191
194
|
: undefined;
|
|
192
|
-
const
|
|
193
|
-
|
|
195
|
+
const propSize =
|
|
196
|
+
typeof props[dimension] === 'number' ? props[dimension] : undefined;
|
|
197
|
+
return styleSize ?? propSize ?? intrinsic;
|
|
194
198
|
}
|
|
195
199
|
|
|
196
200
|
/**
|
|
@@ -200,17 +204,17 @@ function svgBoxSize(props, dim, intrinsic) {
|
|
|
200
204
|
* (an imported artifact's kind is fixed at build time, so it never flips for a given element).
|
|
201
205
|
*/
|
|
202
206
|
function rasterSvgArtifact(type, props) {
|
|
203
|
-
const
|
|
204
|
-
return type === 'Svg' &&
|
|
207
|
+
const source = props && props.source;
|
|
208
|
+
return type === 'Svg' && source && source.kind === 'raster' ? source : null;
|
|
205
209
|
}
|
|
206
210
|
|
|
207
211
|
/** Maps a raster `<Svg source>` to equivalent `<Image>` props: the baked asset name + the resolved box size. */
|
|
208
|
-
function rasterImageProps(props,
|
|
209
|
-
const width = svgBoxSize(props, 'width',
|
|
210
|
-
const height = svgBoxSize(props, 'height',
|
|
212
|
+
function rasterImageProps(props, artifact) {
|
|
213
|
+
const width = svgBoxSize(props, 'width', artifact.width);
|
|
214
|
+
const height = svgBoxSize(props, 'height', artifact.height);
|
|
211
215
|
return {
|
|
212
216
|
...props,
|
|
213
|
-
source:
|
|
217
|
+
source: artifact.name,
|
|
214
218
|
style: {...(props.style || {}), width, height},
|
|
215
219
|
};
|
|
216
220
|
}
|
|
@@ -227,12 +231,12 @@ function applyVectorOps(type, handle, props) {
|
|
|
227
231
|
let ops;
|
|
228
232
|
let paints;
|
|
229
233
|
let gradients;
|
|
230
|
-
const
|
|
231
|
-
if (
|
|
234
|
+
const source = props.source;
|
|
235
|
+
if (source && source.kind === 'vector' && Array.isArray(source.ops)) {
|
|
232
236
|
({ops, paints, gradients} = scaleVectorArtifact(
|
|
233
|
-
|
|
234
|
-
svgBoxSize(props, 'width',
|
|
235
|
-
svgBoxSize(props, 'height',
|
|
237
|
+
source,
|
|
238
|
+
svgBoxSize(props, 'width', source.width),
|
|
239
|
+
svgBoxSize(props, 'height', source.height),
|
|
236
240
|
));
|
|
237
241
|
} else {
|
|
238
242
|
({ops, paints, gradients} = flattenSvg(props));
|
|
@@ -262,12 +266,16 @@ function applyVectorOps(type, handle, props) {
|
|
|
262
266
|
* drag, a color tweak) does not need the tape re-uploaded.
|
|
263
267
|
*/
|
|
264
268
|
function svgSourceBoxChanged(prevProps, nextProps) {
|
|
265
|
-
const
|
|
266
|
-
const
|
|
267
|
-
|
|
269
|
+
const source = nextProps.source;
|
|
270
|
+
const intrinsicWidth =
|
|
271
|
+
source && source.kind === 'vector' ? source.width : undefined;
|
|
272
|
+
const intrinsicHeight =
|
|
273
|
+
source && source.kind === 'vector' ? source.height : undefined;
|
|
268
274
|
return (
|
|
269
|
-
svgBoxSize(prevProps, 'width',
|
|
270
|
-
|
|
275
|
+
svgBoxSize(prevProps, 'width', intrinsicWidth) !==
|
|
276
|
+
svgBoxSize(nextProps, 'width', intrinsicWidth) ||
|
|
277
|
+
svgBoxSize(prevProps, 'height', intrinsicHeight) !==
|
|
278
|
+
svgBoxSize(nextProps, 'height', intrinsicHeight)
|
|
271
279
|
);
|
|
272
280
|
}
|
|
273
281
|
|
|
@@ -300,10 +308,10 @@ function diffUpdate(type, prevProps, nextProps) {
|
|
|
300
308
|
let events = false;
|
|
301
309
|
let vector = false;
|
|
302
310
|
const diffKey = key => {
|
|
303
|
-
const
|
|
304
|
-
const
|
|
305
|
-
if (Object.is(
|
|
306
|
-
if (isEventProp(key,
|
|
311
|
+
const previousValue = prevProps[key];
|
|
312
|
+
const nextValue = nextProps[key];
|
|
313
|
+
if (Object.is(previousValue, nextValue)) return;
|
|
314
|
+
if (isEventProp(key, previousValue) || isEventProp(key, nextValue)) {
|
|
307
315
|
events = true;
|
|
308
316
|
return;
|
|
309
317
|
}
|
|
@@ -312,16 +320,16 @@ function diffUpdate(type, prevProps, nextProps) {
|
|
|
312
320
|
// Only subtree-owning types render children through their OWN props (shouldSetTextContent);
|
|
313
321
|
// everywhere else children are separate host instances React mutates directly.
|
|
314
322
|
if (type === 'Text') {
|
|
315
|
-
if (!deepEqualProps(
|
|
323
|
+
if (!deepEqualProps(previousValue, nextValue)) {
|
|
316
324
|
props = true; // flat.text is built from children
|
|
317
325
|
spans = true;
|
|
318
326
|
}
|
|
319
327
|
} else if (type === 'Svg') {
|
|
320
|
-
if (!deepEqualProps(
|
|
328
|
+
if (!deepEqualProps(previousValue, nextValue)) vector = true;
|
|
321
329
|
}
|
|
322
330
|
return;
|
|
323
331
|
case 'style':
|
|
324
|
-
if (!deepEqualProps(
|
|
332
|
+
if (!deepEqualProps(previousValue, nextValue)) {
|
|
325
333
|
props = true;
|
|
326
334
|
if (type === 'Text') spans = true;
|
|
327
335
|
if (type === 'Svg' && nextProps.source)
|
|
@@ -342,7 +350,7 @@ function diffUpdate(type, prevProps, nextProps) {
|
|
|
342
350
|
}
|
|
343
351
|
// fall through: on other types these are ordinary (ignored or passthrough) props
|
|
344
352
|
default:
|
|
345
|
-
if (!deepEqualProps(
|
|
353
|
+
if (!deepEqualProps(previousValue, nextValue)) {
|
|
346
354
|
props = true;
|
|
347
355
|
// A source tape ignores root paint.
|
|
348
356
|
if (type === 'Svg' && !nextProps.source && PAINT_PROPS.includes(key))
|
|
@@ -418,15 +426,13 @@ export const hostConfig = {
|
|
|
418
426
|
const raster = rasterSvgArtifact(type, props);
|
|
419
427
|
if (raster) {
|
|
420
428
|
const handle = NativeUI.createNode('Image');
|
|
421
|
-
if (handle ===
|
|
422
|
-
forgetBindings(handle);
|
|
429
|
+
if (handle === FAILED_CREATE) return nextFailedInstance--;
|
|
423
430
|
applyProps('Image', handle, rasterImageProps(props, raster));
|
|
424
431
|
applyEvents(handle, null, props);
|
|
425
432
|
return handle;
|
|
426
433
|
}
|
|
427
434
|
const handle = NativeUI.createNode(type);
|
|
428
|
-
if (handle ===
|
|
429
|
-
forgetBindings(handle);
|
|
435
|
+
if (handle === FAILED_CREATE) return nextFailedInstance--;
|
|
430
436
|
const flatStyle = applyProps(type, handle, props);
|
|
431
437
|
applyTextSpans(type, handle, props, flatStyle);
|
|
432
438
|
applyVectorOps(type, handle, props);
|
|
@@ -515,6 +521,7 @@ export const hostConfig = {
|
|
|
515
521
|
detachDeletedInstance(instance) {
|
|
516
522
|
// Called for every host instance in a deleted subtree, including failed creates below its top.
|
|
517
523
|
if (instance < 0) freeOrphans(instance);
|
|
524
|
+
else forgetBindings(instance);
|
|
518
525
|
},
|
|
519
526
|
getCurrentEventPriority() {
|
|
520
527
|
return DefaultEventPriority;
|
|
@@ -530,12 +537,12 @@ export const hostConfig = {
|
|
|
530
537
|
},
|
|
531
538
|
|
|
532
539
|
// --- Scheduling ---
|
|
533
|
-
scheduleTimeout: (
|
|
534
|
-
cancelTimeout:
|
|
540
|
+
scheduleTimeout: (callback, delay) => setTimeout(callback, delay),
|
|
541
|
+
cancelTimeout: timeoutId => clearTimeout(timeoutId),
|
|
535
542
|
supportsMicrotasks: true,
|
|
536
543
|
scheduleMicrotask:
|
|
537
544
|
typeof queueMicrotask === 'function'
|
|
538
545
|
? queueMicrotask
|
|
539
|
-
:
|
|
546
|
+
: callback => Promise.resolve().then(callback),
|
|
540
547
|
now: () => NativeUI.now(),
|
|
541
548
|
};
|
package/src/props.js
CHANGED
|
@@ -64,22 +64,22 @@ export const PASSTHROUGH = [
|
|
|
64
64
|
];
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
|
-
* Flattens RN-style `style` (object or nested array) into the `
|
|
67
|
+
* Flattens RN-style `style` (object or nested array) into the `output` object.
|
|
68
68
|
*/
|
|
69
|
-
export function flattenStyle(style,
|
|
69
|
+
export function flattenStyle(style, output) {
|
|
70
70
|
if (!style) return;
|
|
71
71
|
if (Array.isArray(style)) {
|
|
72
|
-
for (const
|
|
72
|
+
for (const entry of style) flattenStyle(entry, output);
|
|
73
73
|
} else {
|
|
74
|
-
Object.assign(
|
|
74
|
+
Object.assign(output, style);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/** Flattens a style (object/array) into a fresh plain object. */
|
|
79
79
|
export function flattenStyleObj(style) {
|
|
80
|
-
const
|
|
81
|
-
flattenStyle(style,
|
|
82
|
-
return
|
|
80
|
+
const flattened = {};
|
|
81
|
+
flattenStyle(style, flattened);
|
|
82
|
+
return flattened;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
// Style fields the engine honors per inline text span (everything else inherits from the node).
|
|
@@ -127,7 +127,7 @@ export function flattenTextChildren(children, baseStyle) {
|
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
129
129
|
if (Array.isArray(node)) {
|
|
130
|
-
for (const
|
|
130
|
+
for (const child of node) walk(child, style);
|
|
131
131
|
return;
|
|
132
132
|
}
|
|
133
133
|
if (node && node.props !== undefined) {
|
|
@@ -152,11 +152,12 @@ export function buildTextSpans(props, flatStyle) {
|
|
|
152
152
|
if (!isTextContent(props.children)) return [];
|
|
153
153
|
const baseStyle = flatStyle || flattenStyleObj(props.style);
|
|
154
154
|
const segments = flattenTextChildren(props.children, baseStyle);
|
|
155
|
-
if (!segments.some(
|
|
156
|
-
return segments.map(
|
|
157
|
-
const span = {text:
|
|
158
|
-
for (const
|
|
159
|
-
if (
|
|
155
|
+
if (!segments.some(segment => segment.style !== baseStyle)) return [];
|
|
156
|
+
return segments.map(segment => {
|
|
157
|
+
const span = {text: segment.text};
|
|
158
|
+
for (const key of SPAN_STYLE_KEYS) {
|
|
159
|
+
if (segment.style && segment.style[key] !== undefined)
|
|
160
|
+
span[key] = segment.style[key];
|
|
160
161
|
}
|
|
161
162
|
return span;
|
|
162
163
|
});
|
|
@@ -181,8 +182,8 @@ export function resolveImageSource(source) {
|
|
|
181
182
|
export function buildProps(type, props, flatStyle) {
|
|
182
183
|
const flat = flatStyle ? {...flatStyle} : {};
|
|
183
184
|
if (!flatStyle) flattenStyle(props.style, flat);
|
|
184
|
-
for (const
|
|
185
|
-
if (props[
|
|
185
|
+
for (const key of PASSTHROUGH) {
|
|
186
|
+
if (props[key] !== undefined) flat[key] = props[key];
|
|
186
187
|
}
|
|
187
188
|
// <Svg> takes width/height as DIRECT props (the react-native-svg convention) — the engine sizes the
|
|
188
189
|
// vector node from them. Fold them into the resolved style (an explicit style width/height still wins)
|
|
@@ -221,9 +222,9 @@ export function buildProps(type, props, flatStyle) {
|
|
|
221
222
|
// The engine renders this when no spans are set; with spans (buildTextSpans) it carries the same
|
|
222
223
|
// text for the plain-text fallback. Non-flattenable children fall back to mounted child instances.
|
|
223
224
|
if (type === 'Text' && isTextContent(props.children)) {
|
|
224
|
-
const
|
|
225
|
-
flat.text = flattenTextChildren(props.children,
|
|
226
|
-
.map(
|
|
225
|
+
const baseStyle = flatStyle || flattenStyleObj(props.style);
|
|
226
|
+
flat.text = flattenTextChildren(props.children, baseStyle)
|
|
227
|
+
.map(segment => segment.text)
|
|
227
228
|
.join('');
|
|
228
229
|
}
|
|
229
230
|
return flat;
|
|
@@ -242,43 +243,50 @@ const DEEP_EQUAL_MAX_DEPTH = 24;
|
|
|
242
243
|
* Animated.Value) compare by IDENTITY only: a fresh instance must read as changed, so it gets bound
|
|
243
244
|
* to the node, while the same instance is already bound and can be skipped.
|
|
244
245
|
*/
|
|
245
|
-
export function deepEqualProps(
|
|
246
|
-
if (Object.is(
|
|
246
|
+
export function deepEqualProps(left, right, depth = 0) {
|
|
247
|
+
if (Object.is(left, right)) return true;
|
|
247
248
|
if (depth >= DEEP_EQUAL_MAX_DEPTH) return false;
|
|
248
249
|
if (
|
|
249
|
-
typeof
|
|
250
|
-
typeof
|
|
251
|
-
|
|
252
|
-
|
|
250
|
+
typeof left !== 'object' ||
|
|
251
|
+
typeof right !== 'object' ||
|
|
252
|
+
left === null ||
|
|
253
|
+
right === null
|
|
253
254
|
)
|
|
254
255
|
return false;
|
|
255
|
-
if (Array.isArray(
|
|
256
|
-
if (
|
|
256
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
257
|
+
if (
|
|
258
|
+
!Array.isArray(left) ||
|
|
259
|
+
!Array.isArray(right) ||
|
|
260
|
+
left.length !== right.length
|
|
261
|
+
)
|
|
257
262
|
return false;
|
|
258
|
-
for (let
|
|
259
|
-
if (!deepEqualProps(
|
|
263
|
+
for (let index = 0; index < left.length; index++) {
|
|
264
|
+
if (!deepEqualProps(left[index], right[index], depth + 1)) return false;
|
|
260
265
|
}
|
|
261
266
|
return true;
|
|
262
267
|
}
|
|
263
268
|
// React elements: equal when they render the same host output — same type, same props.
|
|
264
|
-
if (
|
|
265
|
-
if (
|
|
266
|
-
return
|
|
269
|
+
if (left.$$typeof !== right.$$typeof) return false;
|
|
270
|
+
if (left.$$typeof !== undefined) {
|
|
271
|
+
return (
|
|
272
|
+
left.type === right.type &&
|
|
273
|
+
deepEqualProps(left.props, right.props, depth + 1)
|
|
274
|
+
);
|
|
267
275
|
}
|
|
268
276
|
// Plain objects only; class instances fall through to "changed" (identity already ruled equal out).
|
|
269
|
-
const
|
|
270
|
-
const
|
|
277
|
+
const leftPrototype = Object.getPrototypeOf(left);
|
|
278
|
+
const rightPrototype = Object.getPrototypeOf(right);
|
|
271
279
|
if (
|
|
272
|
-
(
|
|
273
|
-
(
|
|
280
|
+
(leftPrototype !== null && leftPrototype !== Object.prototype) ||
|
|
281
|
+
(rightPrototype !== null && rightPrototype !== Object.prototype)
|
|
274
282
|
)
|
|
275
283
|
return false;
|
|
276
|
-
const
|
|
277
|
-
const
|
|
278
|
-
if (
|
|
279
|
-
for (const
|
|
280
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
281
|
-
if (!deepEqualProps(
|
|
284
|
+
const leftKeys = Object.keys(left);
|
|
285
|
+
const rightKeys = Object.keys(right);
|
|
286
|
+
if (leftKeys.length !== rightKeys.length) return false;
|
|
287
|
+
for (const key of leftKeys) {
|
|
288
|
+
if (!Object.prototype.hasOwnProperty.call(right, key)) return false;
|
|
289
|
+
if (!deepEqualProps(left[key], right[key], depth + 1)) return false;
|
|
282
290
|
}
|
|
283
291
|
return true;
|
|
284
292
|
}
|
package/src/renderer.js
CHANGED
|
@@ -34,19 +34,19 @@ const LegacyRoot = 0;
|
|
|
34
34
|
// frame does in one batch and leaves it as one render and one commit. Installed here rather than at
|
|
35
35
|
// createRoot() so the reconciler that batches is the one that renders.
|
|
36
36
|
// On an instrumented build the batcher is also where the JS phase's split gets drawn (er_perf.h):
|
|
37
|
-
// `
|
|
37
|
+
// `callback(firstArgument, secondArgument)` is the callback, and whatever batchedUpdates does around it is React's render. That
|
|
38
38
|
// boundary is only visible from here — React flushes when it decides to, not reliably at the batch
|
|
39
39
|
// call the C side can see — so marking it in C measured the call overhead and left reconcile at ~0.
|
|
40
40
|
// The instrumented wrapper is chosen ONCE, here, so an ordinary build runs the plain one.
|
|
41
41
|
NativeUI.setBatcher?.(
|
|
42
42
|
NativeUI.perfRenderBegin
|
|
43
|
-
? (
|
|
43
|
+
? (callback, firstArgument, secondArgument) => {
|
|
44
44
|
NativeUI.perfRenderBegin();
|
|
45
45
|
try {
|
|
46
46
|
return reconciler.batchedUpdates(() => {
|
|
47
47
|
NativeUI.perfCallbackBegin();
|
|
48
48
|
try {
|
|
49
|
-
return
|
|
49
|
+
return callback(firstArgument, secondArgument);
|
|
50
50
|
} finally {
|
|
51
51
|
NativeUI.perfCallbackEnd();
|
|
52
52
|
}
|
|
@@ -55,7 +55,10 @@ NativeUI.setBatcher?.(
|
|
|
55
55
|
NativeUI.perfRenderEnd();
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
: (
|
|
58
|
+
: (callback, firstArgument, secondArgument) =>
|
|
59
|
+
reconciler.batchedUpdates(() =>
|
|
60
|
+
callback(firstArgument, secondArgument),
|
|
61
|
+
),
|
|
59
62
|
);
|
|
60
63
|
|
|
61
64
|
/**
|