embedded-react 0.21.0 → 0.22.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.
Files changed (99) hide show
  1. package/README.md +2 -2
  2. package/aot/compile.mjs +1 -1
  3. package/aot/compiler/alerts.mjs +604 -0
  4. package/aot/compiler/check.mjs +1 -1
  5. package/aot/compiler/collect.mjs +1 -1
  6. package/aot/compiler/elements/button.mjs +3 -3
  7. package/aot/compiler/elements/image-background.mjs +1 -1
  8. package/aot/compiler/elements/props.mjs +10 -6
  9. package/aot/compiler/elements/section-list.mjs +1 -1
  10. package/aot/compiler/expressions.mjs +29 -2
  11. package/aot/compiler/handlers.mjs +73 -16
  12. package/aot/compiler/keyboard-dismiss.mjs +99 -0
  13. package/aot/compiler/keyboard.mjs +1 -1
  14. package/aot/compiler/lower.mjs +12 -0
  15. package/aot/compiler/nodes.mjs +17 -9
  16. package/aot/compiler/out.mjs +4 -0
  17. package/aot/compiler/package/codegen.mjs +36 -2
  18. package/aot/compiler/package/format.mjs +5 -3
  19. package/aot/compiler/package/lower.mjs +53 -19
  20. package/aot/compiler/scroll-to.mjs +112 -0
  21. package/aot/compiler/style-text.mjs +2 -2
  22. package/aot/compiler/svg.mjs +6 -3
  23. package/aot/compiler/updaters.mjs +1 -0
  24. package/aot/style-map.mjs +44 -1
  25. package/assets/bake-font.mjs +187 -244
  26. package/assets/bake-image.mjs +47 -71
  27. package/assets/bake-svg.mjs +465 -533
  28. package/assets/build-builtin-font.mjs +14 -27
  29. package/assets/emit-c.mjs +124 -204
  30. package/assets/emit-container.mjs +129 -197
  31. package/assets/emit-pack.mjs +92 -136
  32. package/assets/font-config.mjs +19 -27
  33. package/assets/font-sizes.mjs +432 -507
  34. package/assets/glyph-coverage.mjs +170 -214
  35. package/assets/index.mjs +52 -97
  36. package/assets/rasterize.mjs +173 -194
  37. package/assets/svg-loader.mjs +42 -48
  38. package/build.mjs +84 -101
  39. package/cli.mjs +482 -621
  40. package/compile-bin.mjs +24 -36
  41. package/flash.mjs +297 -401
  42. package/hotreload/dev-device.mjs +229 -270
  43. package/hotreload/pack-app.mjs +118 -159
  44. package/hotreload/pack-split.mjs +144 -200
  45. package/hotreload/package-transfer.mjs +128 -131
  46. package/hotreload/protocol.mjs +118 -118
  47. package/hotreload/uploader.mjs +132 -159
  48. package/hotreload/watch-tree.mjs +56 -65
  49. package/pack-container.mjs +93 -123
  50. package/package.json +19 -16
  51. package/persist-transform.mjs +89 -105
  52. package/qjsc-wasm.mjs +47 -72
  53. package/sim/embedded-react.wasm +0 -0
  54. package/sim/index.html +1 -1
  55. package/sim-server.mjs +260 -354
  56. package/src/embedded-react/Alert.mjs +112 -0
  57. package/src/embedded-react/Animated.mjs +412 -0
  58. package/src/embedded-react/{AppRegistry.js → AppRegistry.mjs} +26 -25
  59. package/src/embedded-react/{Button.js → Button.mjs} +29 -53
  60. package/src/embedded-react/{Dimensions.js → Dimensions.mjs} +12 -17
  61. package/src/embedded-react/Easing.mjs +34 -0
  62. package/src/embedded-react/{FlatList.js → FlatList.mjs} +25 -42
  63. package/src/embedded-react/{ImageBackground.js → ImageBackground.mjs} +11 -22
  64. package/src/embedded-react/Keyboard.mjs +82 -0
  65. package/src/embedded-react/{LayoutAnimation.js → LayoutAnimation.mjs} +17 -28
  66. package/src/embedded-react/PanResponder.mjs +256 -0
  67. package/src/embedded-react/{Platform.js → Platform.mjs} +8 -9
  68. package/src/embedded-react/{Pressable.js → Pressable.mjs} +12 -25
  69. package/src/embedded-react/SectionList.mjs +103 -0
  70. package/src/embedded-react/{StyleSheet.js → StyleSheet.mjs} +16 -20
  71. package/src/embedded-react/{TouchableOpacity.js → TouchableOpacity.mjs} +47 -83
  72. package/src/embedded-react/background-image.mjs +321 -0
  73. package/src/embedded-react/{components.js → components.mjs} +1 -3
  74. package/src/embedded-react/{imperative.js → imperative.mjs} +27 -38
  75. package/src/embedded-react/index.d.ts +155 -2
  76. package/src/embedded-react/index.js +26 -19
  77. package/src/embedded-react/layout-anim-config.mjs +85 -0
  78. package/src/embedded-react/{list-child.js → list-child.mjs} +11 -20
  79. package/src/embedded-react/{named-colors.js → named-colors.mjs} +2 -6
  80. package/src/embedded-react/nativeModule.mjs +371 -0
  81. package/src/embedded-react/split-style.mjs +57 -0
  82. package/src/embedded-react/svg-ops.mjs +1075 -0
  83. package/src/embedded-react/{useHostValue.js → useHostValue.mjs} +2 -4
  84. package/src/embedded-react/{usePersistentState.js → usePersistentState.mjs} +34 -38
  85. package/src/embedded-react/{warn-props.js → warn-props.mjs} +32 -39
  86. package/src/host-config.mjs +512 -0
  87. package/src/{native-ui.js → native-ui.mjs} +1 -8
  88. package/src/props.mjs +341 -0
  89. package/src/{renderer.js → renderer.mjs} +30 -44
  90. package/src/embedded-react/Animated.js +0 -440
  91. package/src/embedded-react/Easing.js +0 -39
  92. package/src/embedded-react/PanResponder.js +0 -330
  93. package/src/embedded-react/SectionList.js +0 -146
  94. package/src/embedded-react/layout-anim-config.js +0 -101
  95. package/src/embedded-react/nativeModule.js +0 -462
  96. package/src/embedded-react/split-style.js +0 -58
  97. package/src/embedded-react/svg-ops.js +0 -1295
  98. package/src/host-config.js +0 -548
  99. package/src/props.js +0 -306
@@ -0,0 +1,112 @@
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
+ // Alert — RN's Alert.alert(title, message, buttons, options), drawn as a stock <Modal>. There is no OS
17
+ // dialog to hand it to, so alerts wait in a queue and <AlertHost>, which AppRegistry mounts beside the
18
+ // app, shows the first one. With nothing queued the host renders no nodes.
19
+ import { createElement, useSyncExternalStore } from 'react';
20
+ import { Modal, Text, View } from './components.mjs';
21
+ import { Pressable } from './Pressable.mjs';
22
+ const SHEET_MAX_WIDTH = 280;
23
+ const SHEET_MARGIN = 16;
24
+ const styles = {
25
+ modal: {
26
+ position: 'absolute',
27
+ left: 0,
28
+ top: 0,
29
+ alignItems: 'center',
30
+ justifyContent: 'center',
31
+ },
32
+ sheet: { backgroundColor: '#ffffff', borderRadius: 4, padding: 16, gap: 8 },
33
+ title: { color: '#000000', fontWeight: 'bold' },
34
+ message: { color: '#444444' },
35
+ buttons: {
36
+ flexDirection: 'row',
37
+ flexWrap: 'wrap',
38
+ justifyContent: 'flex-end',
39
+ gap: 8,
40
+ marginTop: 8,
41
+ },
42
+ buttonText: { color: '#2196F3', fontWeight: '500', padding: 8 },
43
+ destructiveText: { color: '#d32f2f' },
44
+ };
45
+ const DEFAULT_BUTTONS = [{ text: 'OK' }];
46
+ const queue = [];
47
+ const listeners = new Set();
48
+ const subscribe = (listener) => {
49
+ listeners.add(listener);
50
+ return () => listeners.delete(listener);
51
+ };
52
+ const currentAlert = () => queue[0];
53
+ // Takes the alert off the queue, if it is still the one showing.
54
+ function close(alert) {
55
+ if (queue[0] !== alert)
56
+ return false;
57
+ queue.shift();
58
+ listeners.forEach(listener => listener());
59
+ return true;
60
+ }
61
+ export const Alert = {
62
+ alert(title, message, buttons, options) {
63
+ queue.push({
64
+ title,
65
+ message,
66
+ buttons: buttons && buttons.length > 0 ? buttons : DEFAULT_BUTTONS,
67
+ cancelable: Boolean(options && options.cancelable),
68
+ onDismiss: options && options.onDismiss,
69
+ });
70
+ if (queue.length === 1)
71
+ listeners.forEach(listener => listener());
72
+ },
73
+ };
74
+ const hasText = (value) => value !== undefined && value !== null && value !== '';
75
+ export function AlertHost() {
76
+ const alert = useSyncExternalStore(subscribe, currentAlert);
77
+ if (!alert)
78
+ return null;
79
+ const sheetWidth = Math.min(SHEET_MAX_WIDTH, screen.width - SHEET_MARGIN * 2);
80
+ const buttons = alert.buttons.map((button, index) => createElement(Pressable, {
81
+ key: index,
82
+ // The alert closes first, so a handler that raises another alert queues it behind nothing.
83
+ onPress: () => {
84
+ if (close(alert) && button.onPress)
85
+ button.onPress();
86
+ },
87
+ }, createElement(Text, {
88
+ style: button.style === 'destructive'
89
+ ? [styles.buttonText, styles.destructiveText]
90
+ : styles.buttonText,
91
+ }, hasText(button.text) ? String(button.text) : '')));
92
+ const sheet = createElement(
93
+ // A cancelable alert's sheet is a press target of its own, so a tap on it is not a tap outside.
94
+ alert.cancelable ? Pressable : View, {
95
+ style: [styles.sheet, { width: sheetWidth }],
96
+ onPress: alert.cancelable ? () => { } : undefined,
97
+ }, hasText(alert.title)
98
+ ? createElement(Text, { style: styles.title }, String(alert.title))
99
+ : null, hasText(alert.message)
100
+ ? createElement(Text, { style: styles.message }, String(alert.message))
101
+ : null, createElement(View, { style: styles.buttons }, buttons));
102
+ const fullScreen = { width: screen.width, height: screen.height };
103
+ return createElement(Modal, { visible: true, style: [styles.modal, fullScreen] }, alert.cancelable
104
+ ? createElement(Pressable, {
105
+ style: [styles.modal, fullScreen],
106
+ onPress: () => {
107
+ if (close(alert) && alert.onDismiss)
108
+ alert.onDismiss();
109
+ },
110
+ }, sheet)
111
+ : sheet);
112
+ }
@@ -0,0 +1,412 @@
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
+ // Animated — the React Native analog, backed by the engine's native-driver value system
17
+ // (er_animation_value_*). An Animated.Value is a handle to an engine-side float; binding it to a node
18
+ // prop (via Animated.View) lets the engine advance the animation each frame with NO per-frame JS.
19
+ import { createElement, useRef, useEffect } from 'react';
20
+ import { NativeUI } from '../native-ui.mjs';
21
+ import { deepEqualProps } from '../props.mjs';
22
+ // The style keys an animated value can drive only through an interpolation onto colors.
23
+ const COLOR_PROPS = new Set(['backgroundColor', 'color']);
24
+ let _warnedColorBind = false;
25
+ let _warnedNumberBind = false;
26
+ /** Warns once that `prop` takes a color, which a plain float or a numeric outputRange cannot give it. */
27
+ function warnColorBind(prop) {
28
+ if (_warnedColorBind)
29
+ return;
30
+ _warnedColorBind = true;
31
+ console.warn(`embedded-react: an animated "${prop}" needs colors: bind value.interpolate({inputRange, ` +
32
+ `outputRange: ['#000', '#fff']}) rather than the value itself, which is ignored.`);
33
+ }
34
+ /** Warns once that `prop` takes numbers, which an outputRange holding anything else cannot give it. */
35
+ function warnNumberBind(prop) {
36
+ if (_warnedNumberBind)
37
+ return;
38
+ _warnedNumberBind = true;
39
+ console.warn(`embedded-react: an animated "${prop}" takes an outputRange of numbers; this one is ignored.`);
40
+ }
41
+ /** A standalone animatable value bound to an engine-side float. */
42
+ export class AnimatedValue {
43
+ constructor(initial = 0) {
44
+ this.__animated = true;
45
+ this._handle = NativeUI.animValueCreate(initial);
46
+ this._value = initial;
47
+ this._destroyed = false;
48
+ }
49
+ setValue(value) {
50
+ this._value = value;
51
+ NativeUI.animValueSet(this._handle, value);
52
+ }
53
+ /**
54
+ * Releases the engine-side value slot. The engine's value pool is fixed-size (unlike RN, where the
55
+ * JS value is simply garbage-collected), so a value tied to a mounting/unmounting component must be
56
+ * freed explicitly — see useAnimatedValue. Idempotent; the value must not be used after destroy().
57
+ */
58
+ destroy() {
59
+ if (this._destroyed)
60
+ return;
61
+ this._destroyed = true;
62
+ NativeUI.animValueDestroy(this._handle);
63
+ }
64
+ __getValue() {
65
+ return NativeUI.animValueGet(this._handle);
66
+ }
67
+ __bind(node, prop) {
68
+ // The engine applies the current value on bind and ignores duplicate (node, prop) pairs, so
69
+ // this is safe to call on every render.
70
+ if (COLOR_PROPS.has(prop)) {
71
+ warnColorBind(prop);
72
+ return;
73
+ }
74
+ NativeUI.animValueBind(this._handle, node, prop);
75
+ }
76
+ interpolate(config) {
77
+ return new AnimatedInterpolation(this, config);
78
+ }
79
+ }
80
+ /**
81
+ * A value derived from a parent Animated.Value through a piecewise-linear interpolation.
82
+ * config = { inputRange, outputRange, extrapolate?, extrapolateLeft?, extrapolateRight? }; the
83
+ * extrapolate tokens ('extend' | 'clamp' | 'identity') control behavior outside the input range.
84
+ */
85
+ export class AnimatedInterpolation {
86
+ constructor(parent, config) {
87
+ this.__animated = true;
88
+ this._parent = parent;
89
+ this._config = config;
90
+ }
91
+ __bind(node, prop) {
92
+ const outputRange = this._config?.outputRange;
93
+ if (Array.isArray(outputRange)) {
94
+ if (COLOR_PROPS.has(prop)) {
95
+ if (outputRange.some(output => typeof output !== 'string')) {
96
+ warnColorBind(prop);
97
+ return;
98
+ }
99
+ }
100
+ else if (outputRange.some(output => typeof output !== 'number')) {
101
+ warnNumberBind(prop);
102
+ return;
103
+ }
104
+ }
105
+ NativeUI.animValueBindInterpolated(this._parent._handle, node, prop, this._config);
106
+ }
107
+ /**
108
+ * Two interpolations drive a prop identically when they map the same parent value through the same
109
+ * config. The host config asks because `value.interpolate(...)` builds a fresh object on every
110
+ * render: without this an unchanged interpolated style would be unbound and re-bound each commit.
111
+ */
112
+ __bindEq(other) {
113
+ return (other instanceof AnimatedInterpolation &&
114
+ other._parent === this._parent &&
115
+ deepEqualProps(this._config, other._config));
116
+ }
117
+ interpolate(config) {
118
+ // Chained interpolation isn't supported by the engine; re-map against the same parent.
119
+ return new AnimatedInterpolation(this._parent, config);
120
+ }
121
+ }
122
+ /** Wraps callback so it runs at most once, regardless of how many times it is invoked. */
123
+ function once(callback) {
124
+ let called = false;
125
+ return argument => {
126
+ if (called)
127
+ return;
128
+ called = true;
129
+ if (callback)
130
+ callback(argument);
131
+ };
132
+ }
133
+ /**
134
+ * Wraps a NativeUI animation call in an object with start()/stop() (RN's animation handle shape).
135
+ *
136
+ * start(onComplete) wires the engine's completion callback through the bridge: onComplete is called
137
+ * with `{ finished }` when the animation ends naturally (finished: true) or is interrupted by a new
138
+ * animation / stop() (finished: false). `_value` is exposed so Animated.loop can reset it between
139
+ * iterations.
140
+ */
141
+ function makeAnimation(value, toValue, config) {
142
+ let handle = 0;
143
+ return {
144
+ _value: value,
145
+ start(onComplete) {
146
+ // Always pass a wrapper so we can null out the (possibly recycled) handle on completion.
147
+ const onEnd = (finished) => {
148
+ handle = 0;
149
+ if (onComplete)
150
+ onComplete({ finished: !!finished });
151
+ };
152
+ handle = NativeUI.animValueAnimate(value._handle, toValue, config, onEnd);
153
+ },
154
+ stop() {
155
+ if (handle)
156
+ NativeUI.animStop(handle);
157
+ },
158
+ };
159
+ }
160
+ export function timing(value, config = {}) {
161
+ const { toValue = 0, useNativeDriver, ...rest } = config;
162
+ return makeAnimation(value, toValue, { type: 'timing', ...rest });
163
+ }
164
+ export function spring(value, config = {}) {
165
+ const { toValue = 0, useNativeDriver, ...rest } = config;
166
+ return makeAnimation(value, toValue, { type: 'spring', ...rest });
167
+ }
168
+ export function decay(value, config = {}) {
169
+ const { useNativeDriver, ...rest } = config;
170
+ // Decay coasts from its velocity; the engine ignores the target, so pass the current value.
171
+ return makeAnimation(value, value.__getValue(), { type: 'decay', ...rest });
172
+ }
173
+ // --- Composition -------------------------------------------------------------------------------
174
+ // These are pure JS over each child animation's start()/stop() + the §2 timer globals. The engine
175
+ // deactivates a finished animation before firing its completion callback, so chaining the next
176
+ // animation from inside a completion handler is safe (no per-frame JS — each child still runs in C).
177
+ /** Runs animations one after another; each starts when the previous finishes. */
178
+ export function sequence(animations) {
179
+ let current = 0;
180
+ let stopped = false;
181
+ return {
182
+ start(onComplete) {
183
+ // Reset the per-run state so the sequence is restartable — e.g., each iteration of Animated.loop calls
184
+ // start() again. Without this, `current` stays at animations.length from the previous run, so the next
185
+ // start() completes instantly and the loop re-enters synchronously → stack overflow.
186
+ current = 0;
187
+ stopped = false;
188
+ const done = once(onComplete);
189
+ const next = (result) => {
190
+ if (stopped || !result || result.finished === false) {
191
+ done({ finished: false });
192
+ return;
193
+ }
194
+ if (current >= animations.length) {
195
+ done({ finished: true });
196
+ return;
197
+ }
198
+ animations[current++].start(next);
199
+ };
200
+ next({ finished: true }); // kick off the first entry
201
+ },
202
+ stop() {
203
+ stopped = true;
204
+ if (current > 0 && current <= animations.length)
205
+ animations[current - 1].stop();
206
+ },
207
+ };
208
+ }
209
+ /** Runs animations simultaneously; completes when all finish. stopTogether (default true). */
210
+ export function parallel(animations, config) {
211
+ const stopTogether = !config || config.stopTogether !== false;
212
+ let stopped = false;
213
+ return {
214
+ start(onComplete) {
215
+ const done = once(onComplete);
216
+ const total = animations.length;
217
+ if (total === 0) {
218
+ done({ finished: true });
219
+ return;
220
+ }
221
+ let doneCount = 0;
222
+ let anyUnfinished = false;
223
+ const onChild = (result) => {
224
+ doneCount++;
225
+ if (!result || result.finished === false) {
226
+ anyUnfinished = true;
227
+ if (stopTogether && !stopped) {
228
+ stopped = true;
229
+ for (const animation of animations)
230
+ animation.stop();
231
+ }
232
+ }
233
+ if (doneCount >= total)
234
+ done({ finished: !anyUnfinished });
235
+ };
236
+ for (const animation of animations)
237
+ animation.start(onChild);
238
+ },
239
+ stop() {
240
+ stopped = true;
241
+ for (const animation of animations)
242
+ animation.stop();
243
+ },
244
+ };
245
+ }
246
+ /** Like parallel, but each animation starts `delay` ms after the previous one (uses setTimeout). */
247
+ export function stagger(delay, animations) {
248
+ let stopped = false;
249
+ const timers = [];
250
+ return {
251
+ start(onComplete) {
252
+ const done = once(onComplete);
253
+ const total = animations.length;
254
+ if (total === 0) {
255
+ done({ finished: true });
256
+ return;
257
+ }
258
+ let doneCount = 0;
259
+ let anyUnfinished = false;
260
+ const onChild = (result) => {
261
+ doneCount++;
262
+ if (!result || result.finished === false)
263
+ anyUnfinished = true;
264
+ if (doneCount >= total)
265
+ done({ finished: !anyUnfinished });
266
+ };
267
+ animations.forEach((animation, index) => {
268
+ if (index === 0) {
269
+ animation.start(onChild);
270
+ }
271
+ else {
272
+ timers.push(setTimeout(() => {
273
+ if (!stopped)
274
+ animation.start(onChild);
275
+ }, delay * index));
276
+ }
277
+ });
278
+ },
279
+ stop() {
280
+ stopped = true;
281
+ for (const timer of timers)
282
+ clearTimeout(timer);
283
+ for (const animation of animations)
284
+ animation.stop();
285
+ },
286
+ };
287
+ }
288
+ /** An animation that simply waits `time` ms — useful as a spacer inside sequence (uses setTimeout). */
289
+ export function delay(time) {
290
+ let timer = 0;
291
+ return {
292
+ start(onComplete) {
293
+ const done = once(onComplete);
294
+ timer = setTimeout(() => {
295
+ timer = 0;
296
+ done({ finished: true });
297
+ }, time);
298
+ },
299
+ stop() {
300
+ if (timer) {
301
+ clearTimeout(timer);
302
+ timer = 0;
303
+ }
304
+ },
305
+ };
306
+ }
307
+ /**
308
+ * Repeats an animation. iterations: -1 (default) loops forever; otherwise that many times.
309
+ * By default the underlying value is reset to its loop-start position before each iteration
310
+ * (resetBeforeIteration), matching RN — so a timing 0→1 repeats 0→1 rather than ping-ponging.
311
+ */
312
+ export function loop(animation, config) {
313
+ const iterations = config && Number.isInteger(config.iterations) ? config.iterations : -1;
314
+ const resetBeforeIteration = !config || config.resetBeforeIteration !== false;
315
+ let stopped = false;
316
+ return {
317
+ _value: animation._value,
318
+ start(onComplete) {
319
+ const done = once(onComplete);
320
+ const startValue = resetBeforeIteration && animation._value
321
+ ? animation._value.__getValue()
322
+ : null;
323
+ let count = 0;
324
+ const startIteration = () => {
325
+ if (stopped) {
326
+ done({ finished: false });
327
+ return;
328
+ }
329
+ if (iterations >= 0 && count >= iterations) {
330
+ done({ finished: true });
331
+ return;
332
+ }
333
+ count++;
334
+ if (resetBeforeIteration &&
335
+ animation._value &&
336
+ startValue != null &&
337
+ count > 1) {
338
+ animation._value.setValue(startValue);
339
+ }
340
+ animation.start(onIterationDone);
341
+ };
342
+ const onIterationDone = (result) => {
343
+ if (stopped || !result || result.finished === false) {
344
+ done({ finished: false });
345
+ return;
346
+ }
347
+ // Defer the next iteration to a fresh task instead of starting it inline. A child animation can
348
+ // complete *synchronously* (a long-duration timing finishing inside one large catch-up frame in
349
+ // the simulator), and starting the next iteration from within, that completion callback would
350
+ // recurse — loop → child → completion → loop → … — until the stack overflows. setTimeout breaks
351
+ // the chain: the host pump runs it on the next frame, by which point real time has advanced so
352
+ // the animation runs its full duration again. (Negligible cost in the normal async case.)
353
+ setTimeout(startIteration, 0);
354
+ };
355
+ startIteration();
356
+ },
357
+ stop() {
358
+ stopped = true;
359
+ animation.stop();
360
+ },
361
+ };
362
+ }
363
+ /**
364
+ * Returns a stable Animated.Value that persists across renders (the analog of
365
+ * `useRef(new Animated.Value(initial)).current`), and frees the engine-side value slot when the
366
+ * component unmounts. The unmount cleanup matters here in a way it doesn't in React Native: the
367
+ * engine's value pool is fixed-size, so a value owned by a mounting/unmounting component (e.g., a list
368
+ * row or a tab screen) would otherwise leak a slot on every unmount.
369
+ */
370
+ export function useAnimatedValue(initial = 0) {
371
+ const ref = useRef(null);
372
+ if (ref.current == null) {
373
+ ref.current = new AnimatedValue(initial);
374
+ }
375
+ // Empty deps → the cleanup runs only on unmount. `initial` is read once on the first render (matching
376
+ // useRef semantics); later changes don't recreate the value, as in React Native.
377
+ useEffect(() => {
378
+ const value = ref.current;
379
+ return () => value.destroy();
380
+ }, []);
381
+ return ref.current;
382
+ }
383
+ /**
384
+ * Wraps a host component for RN API parity. The style is forwarded untouched: the host config splits
385
+ * the animated values out of ANY element's style and binds them (native driver), so `<Animated.View
386
+ * style={{opacity: v}}>` and `<View style={{opacity: v}}>` render identically.
387
+ *
388
+ * The wrapper used to strip the bindings itself and apply them through a ref. Binding in two places
389
+ * was the reason a prop that stopped being animated kept following its old value: the ref knew what it
390
+ * had bound, but it ran after the commit had already written the props, and the host config — the only
391
+ * side that sees the PREVIOUS render — never saw those bindings at all, so nothing released them.
392
+ */
393
+ export function createAnimatedComponent(Component) {
394
+ return function AnimatedComponent(props) {
395
+ return createElement(Component, props);
396
+ };
397
+ }
398
+ export const Animated = {
399
+ Value: AnimatedValue,
400
+ View: createAnimatedComponent('View'),
401
+ Text: createAnimatedComponent('Text'),
402
+ Image: createAnimatedComponent('Image'),
403
+ timing,
404
+ spring,
405
+ decay,
406
+ sequence,
407
+ parallel,
408
+ stagger,
409
+ delay,
410
+ loop,
411
+ createAnimatedComponent,
412
+ };
@@ -13,7 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
-
17
16
  // AppRegistry — the RN entry point. An app registers a root component; the runtime mounts it into
18
17
  // a screen-sized container.
19
18
  //
@@ -21,9 +20,9 @@
21
20
  // "running the bundle IS starting the app", so registerComponent mounts immediately into a root
22
21
  // sized from the host-injected `screen` global. (A host-driven runApplication can be split out
23
22
  // later when the C host owns app lifecycle.)
24
- import {createElement} from 'react';
25
- import {createRoot} from '../renderer.js';
26
-
23
+ import { createElement, Fragment } from 'react';
24
+ import { createRoot } from '../renderer.mjs';
25
+ import { AlertHost } from './Alert.mjs';
27
26
  let registered = null;
28
27
  // The mounted root is created ONCE and reused on every subsequent registration. On a full reload, the
29
28
  // whole context is torn down and recreated, so this is recreated too (a fresh boot). But on an
@@ -32,26 +31,28 @@ let registered = null;
32
31
  // React reconciles old→new in place. Creating a new root each time would instead leak a fiber root per
33
32
  // reload and orphan the previous tree's effects.
34
33
  let root = null;
35
-
36
34
  export const AppRegistry = {
37
- /**
38
- * Registers a root component and mounts it. `componentProvider` is a zero-arg function returning
39
- * the component (RN signature), so the component module isn't evaluated until registration.
40
- */
41
- registerComponent(appKey, componentProvider) {
42
- registered = {appKey, Component: componentProvider()};
43
- AppRegistry.runApplication(appKey);
44
- return appKey;
45
- },
46
-
47
- /**
48
- * Mounts the registered root component into the screen-sized container, creating it on first use and
49
- * reusing it thereafter (see `root` above).
50
- */
51
- runApplication(appKey) {
52
- if (!registered) return;
53
- if (appKey && appKey !== registered.appKey) return;
54
- if (!root) root = createRoot({width: screen.width, height: screen.height});
55
- root.render(createElement(registered.Component));
56
- },
35
+ /**
36
+ * Registers a root component and mounts it. `componentProvider` is a zero-arg function returning
37
+ * the component (RN signature), so the component module isn't evaluated until registration.
38
+ */
39
+ registerComponent(appKey, componentProvider) {
40
+ registered = { appKey, Component: componentProvider() };
41
+ AppRegistry.runApplication(appKey);
42
+ return appKey;
43
+ },
44
+ /**
45
+ * Mounts the registered root component into the screen-sized container, creating it on first use and
46
+ * reusing it thereafter (see `root` above).
47
+ */
48
+ runApplication(appKey) {
49
+ if (!registered)
50
+ return;
51
+ if (appKey && appKey !== registered.appKey)
52
+ return;
53
+ if (!root)
54
+ root = createRoot({ width: screen.width, height: screen.height });
55
+ // The alert host comes after the app, so an alert draws over it.
56
+ root.render(createElement(Fragment, null, createElement(registered.Component), createElement(AlertHost)));
57
+ },
57
58
  };