embedded-react 0.12.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.
Files changed (38) hide show
  1. package/README.md +222 -6
  2. package/aot/compile.mjs +3316 -364
  3. package/aot/style-map.mjs +30 -6
  4. package/assets/bake-font.mjs +104 -12
  5. package/assets/bake-svg.mjs +11 -1
  6. package/assets/build-builtin-font.mjs +6 -12
  7. package/assets/emit-c.mjs +10 -2
  8. package/assets/emit-container.mjs +4 -2
  9. package/assets/font-config.mjs +49 -0
  10. package/assets/font-sizes.mjs +652 -0
  11. package/assets/glyph-coverage.mjs +281 -0
  12. package/assets/index.mjs +29 -5
  13. package/build.mjs +11 -21
  14. package/cli.mjs +41 -3
  15. package/compile-bin.mjs +71 -0
  16. package/hotreload/pack-app.mjs +8 -21
  17. package/hotreload/pack-split.mjs +12 -27
  18. package/pack-container.mjs +10 -47
  19. package/package.json +2 -1
  20. package/sim/embedded-react.wasm +0 -0
  21. package/sim/index.html +32 -3
  22. package/sim-server.mjs +33 -27
  23. package/src/embedded-react/Animated.js +23 -9
  24. package/src/embedded-react/Button.js +98 -0
  25. package/src/embedded-react/FlatList.js +88 -0
  26. package/src/embedded-react/ImageBackground.js +67 -0
  27. package/src/embedded-react/PanResponder.js +326 -0
  28. package/src/embedded-react/SectionList.js +148 -0
  29. package/src/embedded-react/TouchableOpacity.js +152 -0
  30. package/src/embedded-react/components.js +4 -3
  31. package/src/embedded-react/index.d.ts +867 -60
  32. package/src/embedded-react/index.js +7 -2
  33. package/src/embedded-react/list-child.js +54 -0
  34. package/src/embedded-react/svg-ops.js +309 -77
  35. package/src/embedded-react/warn-props.js +80 -0
  36. package/src/host-config.js +103 -3
  37. package/src/props.js +40 -0
  38. package/src/renderer.js +31 -0
@@ -118,9 +118,8 @@ function makeAssetPlugin({images, fonts, persistHooks, projectRoot}) {
118
118
  return {
119
119
  name: 'embedded-react-assets',
120
120
  async setup(b) {
121
- const {registerSvgVectorLoader} = await import(
122
- '../assets/svg-loader.mjs'
123
- );
121
+ const {registerSvgVectorLoader} =
122
+ await import('../assets/svg-loader.mjs');
124
123
  if (persistHooks) {
125
124
  b.onLoad({filter: /\.(jsx?|tsx?)$/}, a => {
126
125
  const {transformPersist, shouldPersist, projNorm} = persistHooks;
@@ -180,9 +179,8 @@ export async function bundleAppSource({
180
179
 
181
180
  let persistHooks = null;
182
181
  if (persist) {
183
- const {transformPersist, shouldPersist} = await import(
184
- '../persist-transform.mjs'
185
- );
182
+ const {transformPersist, shouldPersist} =
183
+ await import('../persist-transform.mjs');
186
184
  persistHooks = {
187
185
  transformPersist,
188
186
  shouldPersist,
@@ -203,15 +201,13 @@ export async function bundleAppSource({
203
201
  async function bakeAssets({images, fonts, source, projectRoot}) {
204
202
  const {bakeImage} = await import('../assets/bake-image.mjs');
205
203
  const {bakeFont} = await import('../assets/bake-font.mjs');
204
+ const {resolveFontJobs} = await import('../assets/font-config.mjs');
205
+ const {analyzeFontSizes, warnFontSizes} =
206
+ await import('../assets/font-sizes.mjs');
207
+ const {warnMissingGlyphs} = await import('../assets/glyph-coverage.mjs');
206
208
  const {emitAssetPack} = await import('../assets/emit-pack.mjs');
207
209
 
208
- const discoveredSizes = [
209
- ...new Set(
210
- [...source.matchAll(/\bfontSize\s*:\s*(\d+(?:\.\d+)?)/g)].map(m =>
211
- Math.round(Number(m[1])),
212
- ),
213
- ),
214
- ].sort((a, b) => a - b);
210
+ const usedSizes = analyzeFontSizes(source);
215
211
 
216
212
  let cfg = {};
217
213
  const cp = resolve(projectRoot, 'assets.config.js');
@@ -220,20 +216,7 @@ async function bakeAssets({images, fonts, source, projectRoot}) {
220
216
  const fontConfig = cfg.fonts || {};
221
217
  const imageConfig = cfg.images || {};
222
218
 
223
- const fontJobs = [...fonts.entries()].map(([family, path]) => {
224
- const fc = fontConfig[family] || {};
225
- return {
226
- path,
227
- family,
228
- sizes: fc.sizes?.length
229
- ? fc.sizes
230
- : discoveredSizes.length
231
- ? discoveredSizes
232
- : [16],
233
- bpp: fc.bpp ?? 4,
234
- glyphs: fc.glyphs ?? 'ascii',
235
- };
236
- });
219
+ const fontJobs = resolveFontJobs(fonts, fontConfig, usedSizes.sizes);
237
220
  const imageJobs = [...images.entries()].map(([name, path]) => ({
238
221
  path,
239
222
  name,
@@ -241,6 +224,8 @@ async function bakeAssets({images, fonts, source, projectRoot}) {
241
224
  }));
242
225
  const bakedImages = imageJobs.map(bakeImage);
243
226
  const bakedFonts = fontJobs.map(bakeFont);
227
+ warnMissingGlyphs({source, fonts: bakedFonts});
228
+ warnFontSizes({used: usedSizes, fonts: bakedFonts});
244
229
  return bakedImages.length || bakedFonts.length
245
230
  ? emitAssetPack({images: bakedImages, fonts: bakedFonts})
246
231
  : null;
@@ -41,9 +41,13 @@ import {
41
41
  } from 'node:fs';
42
42
  import {bakeImage} from './assets/bake-image.mjs';
43
43
  import {bakeFont} from './assets/bake-font.mjs';
44
+ import {resolveFontJobs} from './assets/font-config.mjs';
45
+ import {analyzeFontSizes, warnFontSizes} from './assets/font-sizes.mjs';
46
+ import {warnMissingGlyphs} from './assets/glyph-coverage.mjs';
44
47
  import {emitAssetPack} from './assets/emit-pack.mjs';
45
48
  import {emitContainer} from './assets/emit-container.mjs';
46
49
  import {registerSvgVectorLoader} from './assets/svg-loader.mjs';
50
+ import {findCompileBin, compileBinHelp} from './compile-bin.mjs';
47
51
 
48
52
  // QuickJS release the bytecode targets — MUST match the FetchContent pin in
49
53
  // bridges/quickjs/CMakeLists.txt and ER_QUICKJS_TAG in er_runtime.c. The loader rejects a mismatch.
@@ -71,37 +75,9 @@ if (!existsSync(entry)) {
71
75
  }
72
76
 
73
77
  // --- Locate the bytecode precompiler -----------------------------------------------------------
74
- const exe = process.platform === 'win32' ? '.exe' : '';
75
- const compileBin =
76
- process.env.ER_COMPILE_BIN ||
77
- [
78
- resolve(
79
- repoRoot,
80
- 'bridges/quickjs/build',
81
- `er-bridge-quickjs-compile${exe}`,
82
- ),
83
- resolve(
84
- repoRoot,
85
- 'examples/linux/build/bridges/quickjs',
86
- `er-bridge-quickjs-compile${exe}`,
87
- ),
88
- resolve(
89
- repoRoot,
90
- 'tools/simulator/build/bridges/quickjs',
91
- `er-bridge-quickjs-compile${exe}`,
92
- ),
93
- ].find(existsSync);
78
+ const compileBin = findCompileBin();
94
79
  if (!compileBin) {
95
- console.error(
96
- 'Bytecode precompiler (er-bridge-quickjs-compile) not found. Build it once:',
97
- );
98
- console.error(
99
- ' cmake -S bridges/quickjs -B bridges/quickjs/build -G "MinGW Makefiles"',
100
- );
101
- console.error(
102
- ' cmake --build bridges/quickjs/build --target er-bridge-quickjs-compile',
103
- );
104
- console.error('(or set ER_COMPILE_BIN to the binary path)');
80
+ console.error(compileBinHelp());
105
81
  process.exit(1);
106
82
  }
107
83
 
@@ -170,13 +146,7 @@ const bytecode = readFileSync(qbcPath);
170
146
 
171
147
  // --- Bake imported assets into an ERPK pack (same sizing rules as build.mjs / sim.mjs) ----------
172
148
  const bundleSrc = readFileSync(bundlePath, 'utf8');
173
- const discoveredSizes = [
174
- ...new Set(
175
- [...bundleSrc.matchAll(/\bfontSize\s*:\s*(\d+(?:\.\d+)?)/g)].map(m =>
176
- Math.round(Number(m[1])),
177
- ),
178
- ),
179
- ].sort((a, b) => a - b);
149
+ const usedSizes = analyzeFontSizes(bundleSrc);
180
150
 
181
151
  let config = {};
182
152
  const configPath = resolve(demoDir, 'assets.config.js');
@@ -185,16 +155,7 @@ if (existsSync(configPath))
185
155
  const fontConfig = config.fonts || {};
186
156
  const imageConfig = config.images || {};
187
157
 
188
- const fontJobs = [...fonts.entries()].map(([family, path]) => {
189
- const fc = fontConfig[family] || {};
190
- const sizes =
191
- fc.sizes && fc.sizes.length
192
- ? fc.sizes
193
- : discoveredSizes.length
194
- ? discoveredSizes
195
- : [16];
196
- return {path, family, sizes, bpp: fc.bpp ?? 4, glyphs: fc.glyphs ?? 'ascii'};
197
- });
158
+ const fontJobs = resolveFontJobs(fonts, fontConfig, usedSizes.sizes);
198
159
  const imageJobs = [...images.entries()].map(([name, path]) => ({
199
160
  path,
200
161
  name,
@@ -203,6 +164,8 @@ const imageJobs = [...images.entries()].map(([name, path]) => ({
203
164
 
204
165
  const bakedImages = imageJobs.map(i => bakeImage(i));
205
166
  const bakedFonts = fontJobs.map(f => bakeFont(f));
167
+ warnMissingGlyphs({source: bundleSrc, fonts: bakedFonts});
168
+ warnFontSizes({used: usedSizes, fonts: bakedFonts});
206
169
  const assetPack =
207
170
  bakedImages.length || bakedFonts.length
208
171
  ? emitAssetPack({images: bakedImages, fonts: bakedFonts})
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "embedded-react",
3
- "version": "0.12.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",
@@ -48,6 +48,7 @@
48
48
  "hotreload/",
49
49
  "build.mjs",
50
50
  "pack-container.mjs",
51
+ "compile-bin.mjs",
51
52
  "persist-transform.mjs",
52
53
  "cli.mjs",
53
54
  "sim-server.mjs",
Binary file
package/sim/index.html CHANGED
@@ -4,7 +4,8 @@
4
4
  Licensed under the Apache License, Version 2.0 (see LICENSE).
5
5
 
6
6
  WASM simulator host page. Loads embedded-react.wasm and runs a requestAnimationFrame loop:
7
- er_web_pump(dt) -> read the RGBA framebuffer -> putImageData. The canvas fills the whole viewport, so in
7
+ er_web_pump(dt) -> read the RGBA framebuffer -> putImageData, where dt is elapsed wall-clock time and an
8
+ interval keeps pumping when the browser stops calling rAF. The canvas fills the whole viewport, so in
8
9
  "Fit to window" mode the board size IS the viewport — set the browser's device toolbar to 240x320 and the
9
10
  app renders at exactly 240x320 (same workflow as a responsive web project). The size controls are a small
10
11
  floating, collapsible chip so they never steal render space. You can also lock to a real panel size. It
@@ -369,18 +370,46 @@
369
370
  canvas.addEventListener('pointerup', release);
370
371
  canvas.addEventListener('pointercancel', release);
371
372
 
373
+ // The engine clock advances by elapsed wall-clock time, the way a device host drives it (from
374
+ // esp_timer_get_time / SDL_GetTicks deltas). Frame cadence is not a clock: the browser throttles
375
+ // requestAnimationFrame when the window is occluded and stops it entirely while the page is hidden,
376
+ // which stalls the clock that setTimeout, setInterval and Animated completions all hang off.
377
+ // A pump hands over the whole elapsed delta, however long the gap, so a page that comes back from
378
+ // minutes of throttling is immediately at the right time. Catching up is cheap however long it was:
379
+ // the physics integrators cap their step count, timing animations clamp to their duration, and each
380
+ // timer fires once per pass rather than once per period it missed.
381
+ const MAX_DT_MS = 2147483647; // INT32_MAX: er_web_pump takes an int, and that is the only bound needed
382
+ // No frame for this long means rAF is stalled and the interval below takes over the pump.
383
+ const RAF_IDLE_MS = 250;
384
+
372
385
  let prev = performance.now();
373
- const frame = (now) => {
374
- const dt = Math.min(100, now - prev);
386
+ let lastFrame = performance.now();
387
+
388
+ const step = (paint) => {
389
+ const now = performance.now();
390
+ const dt = Math.min(MAX_DT_MS, now - prev);
375
391
  prev = now;
376
392
  pump(Math.round(dt));
393
+ if (!paint) return;
377
394
  // HEAPU8 may detach when WASM memory grows, so wrap a fresh view each frame, then copy into the
378
395
  // persistent ImageData (robust against detach during the copy).
379
396
  image.data.set(new Uint8ClampedArray(Module.HEAPU8.buffer, framebuffer(), len));
380
397
  ctx.putImageData(image, 0, 0);
398
+ };
399
+
400
+ const frame = () => {
401
+ step(true);
402
+ lastFrame = performance.now();
381
403
  requestAnimationFrame(frame);
382
404
  };
383
405
  requestAnimationFrame(frame);
406
+
407
+ // Background pump; no-ops while rAF is healthy. Browsers clamp interval timers in a hidden tab (to
408
+ // ~1s, and far less often once it has been hidden for minutes), which the wall-clock delta absorbs:
409
+ // callbacks land late rather than the app sitting frozen until the tab is focused again.
410
+ setInterval(() => {
411
+ if (performance.now() - lastFrame >= RAF_IDLE_MS) step(!document.hidden);
412
+ }, RAF_IDLE_MS);
384
413
  })();
385
414
  </script>
386
415
  </body>
package/sim-server.mjs CHANGED
@@ -38,6 +38,15 @@ const esbuild = require('esbuild');
38
38
  const {bakeAssetPack} = await import(
39
39
  pathToFileURL(resolve(HERE, 'assets/index.mjs')).href
40
40
  );
41
+ const {resolveFontJobs} = await import(
42
+ pathToFileURL(resolve(HERE, 'assets/font-config.mjs')).href
43
+ );
44
+ const {analyzeFontSizes, fontSizeSignature, warnFontSizes} = await import(
45
+ pathToFileURL(resolve(HERE, 'assets/font-sizes.mjs')).href
46
+ );
47
+ const {textSignature, warnMissingGlyphs} = await import(
48
+ pathToFileURL(resolve(HERE, 'assets/glyph-coverage.mjs')).href
49
+ );
41
50
  const {registerSvgVectorLoader} = await import(
42
51
  pathToFileURL(resolve(HERE, 'assets/svg-loader.mjs')).href
43
52
  );
@@ -94,15 +103,8 @@ function createBundle({
94
103
  let lastAssetSig = null;
95
104
 
96
105
  async function bakePack() {
97
- const discoveredSizes = [
98
- ...new Set(
99
- [
100
- ...readFileSync(bundlePath, 'utf8').matchAll(
101
- /\bfontSize\s*:\s*(\d+(?:\.\d+)?)/g,
102
- ),
103
- ].map(m => Math.round(Number(m[1]))),
104
- ),
105
- ].sort((a, b) => a - b);
106
+ const bundleSrc = readFileSync(bundlePath, 'utf8');
107
+ const usedSizes = analyzeFontSizes(bundleSrc);
106
108
 
107
109
  let cfg = {};
108
110
  const cp = resolve(projectRoot, 'assets.config.js');
@@ -113,43 +115,47 @@ function createBundle({
113
115
  const fontConfig = cfg.fonts || {};
114
116
  const imageConfig = cfg.images || {};
115
117
 
116
- const fontJobs = [...fonts.entries()].map(([family, path]) => {
117
- const fc = fontConfig[family] || {};
118
- const sizes =
119
- fc.sizes && fc.sizes.length
120
- ? fc.sizes
121
- : discoveredSizes.length
122
- ? discoveredSizes
123
- : [16];
124
- return {
125
- path,
126
- family,
127
- sizes,
128
- bpp: fc.bpp ?? 4,
129
- glyphs: fc.glyphs ?? 'ascii',
130
- };
131
- });
118
+ const fontJobs = resolveFontJobs(fonts, fontConfig, usedSizes.sizes);
132
119
  const imageJobs = [...images.entries()].map(([name, path]) => ({
133
120
  path,
134
121
  name,
135
122
  format: imageConfig[name]?.format,
136
123
  }));
137
124
 
125
+ // The app's text is an asset input too: new characters and new font sizes must both be
126
+ // re-checked against the bake even when no font or image file changed.
138
127
  const sig = JSON.stringify({
128
+ t: textSignature(bundleSrc),
129
+ z: fontSizeSignature(usedSizes),
139
130
  i: imageJobs.map(j => [j.name, j.path, mtime(j.path), j.format]).sort(),
140
131
  f: fontJobs
141
- .map(j => [j.family, j.path, mtime(j.path), j.sizes, j.bpp, j.glyphs])
132
+ .map(j => [
133
+ j.family,
134
+ j.path,
135
+ mtime(j.path),
136
+ j.sizes,
137
+ j.bpp,
138
+ j.glyphs,
139
+ j.extraGlyphs,
140
+ ])
142
141
  .sort(),
143
142
  });
144
143
  if (sig === lastAssetSig) return;
145
144
  lastAssetSig = sig;
146
- if (!imageJobs.length && !fontJobs.length) return; // built-in font only → no pack
145
+ if (!imageJobs.length && !fontJobs.length) {
146
+ // Built-in font only → no pack, but its glyph and size coverage still bind.
147
+ warnMissingGlyphs({source: bundleSrc});
148
+ warnFontSizes({used: usedSizes});
149
+ return;
150
+ }
147
151
 
148
152
  try {
149
153
  const s = bakeAssetPack({
150
154
  images: imageJobs,
151
155
  fonts: fontJobs,
152
156
  outPath: packPath,
157
+ source: bundleSrc,
158
+ usedSizes,
153
159
  });
154
160
  console.log(
155
161
  ` assets → ${s.images} image(s), ${s.fonts} font size(s), ${s.bytes} B`,
@@ -19,7 +19,7 @@
19
19
  // prop (via Animated.View) lets the engine advance the animation each frame with NO per-frame JS.
20
20
  import {createElement, useRef, useEffect} from 'react';
21
21
  import {NativeUI} from '../native-ui.js';
22
- import {splitAnimatedStyle} from './split-style.js';
22
+ import {deepEqualProps} from '../props.js';
23
23
 
24
24
  /** A standalone animatable value bound to an engine-side float. */
25
25
  export class AnimatedValue {
@@ -82,6 +82,19 @@ export class AnimatedInterpolation {
82
82
  );
83
83
  }
84
84
 
85
+ /**
86
+ * Two interpolations drive a prop identically when they map the same parent value through the same
87
+ * config. The host config asks because `value.interpolate(...)` builds a fresh object on every
88
+ * render: without this an unchanged interpolated style would be unbound and re-bound each commit.
89
+ */
90
+ __bindEq(other) {
91
+ return (
92
+ other instanceof AnimatedInterpolation &&
93
+ other._parent === this._parent &&
94
+ deepEqualProps(this._config, other._config)
95
+ );
96
+ }
97
+
85
98
  interpolate(config) {
86
99
  // Chained interpolation isn't supported by the engine; re-map against the same parent.
87
100
  return new AnimatedInterpolation(this._parent, config);
@@ -354,17 +367,18 @@ export function useAnimatedValue(initial = 0) {
354
367
  }
355
368
 
356
369
  /**
357
- * Wraps a host component so animated values in its `style` are bound to the node (native driver).
370
+ * Wraps a host component for RN API parity. The style is forwarded untouched: the host config splits
371
+ * the animated values out of ANY element's style and binds them (native driver), so `<Animated.View
372
+ * style={{opacity: v}}>` and `<View style={{opacity: v}}>` render identically.
373
+ *
374
+ * The wrapper used to strip the bindings itself and apply them through a ref. Binding in two places
375
+ * was the reason a prop that stopped being animated kept following its old value: the ref knew what it
376
+ * had bound, but it ran after the commit had already written the props, and the host config — the only
377
+ * side that sees the PREVIOUS render — never saw those bindings at all, so nothing released them.
358
378
  */
359
379
  export function createAnimatedComponent(Component) {
360
380
  return function AnimatedComponent(props) {
361
- const {style, ...rest} = props;
362
- const {staticStyle, bindings} = splitAnimatedStyle(style);
363
- const ref = node => {
364
- if (node == null) return; // unmount
365
- for (const b of bindings) b.value.__bind(node, b.prop);
366
- };
367
- return createElement(Component, {...rest, style: staticStyle, ref});
381
+ return createElement(Component, props);
368
382
  };
369
383
  }
370
384
 
@@ -0,0 +1,98 @@
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
+ // Button — RN's pre-styled button, as a plain component over <Pressable> + <Text>. No engine node of
18
+ // its own:
19
+ //
20
+ // <Button title="Save" onPress={save} />
21
+ // renders the same tree as
22
+ // <Pressable style={styles.button} onPress={save}><Text style={styles.text}>Save</Text></Pressable>
23
+ //
24
+ // RN nests that <Text> in a <View> inside the touchable, because its Touchable has no style of its
25
+ // own. <Pressable> here IS a styled scene node, so the View is dropped: two engine nodes per button
26
+ // instead of three, which matters against a fixed ERUI_MAX_NODES pool (44 slots on the CYD).
27
+ //
28
+ // Like RN's, this Button takes NO style prop — that is the whole point of it, and the escape hatch is
29
+ // the same: drop to <Pressable> + <Text> and style them yourself. `color` and `disabled` are the two
30
+ // knobs, exactly as upstream.
31
+ import {createElement} from 'react';
32
+ import {Pressable, Text} from './components.js';
33
+ import {createPropWarner, RN_PLATFORM_NO_OPS} from './warn-props.js';
34
+
35
+ // RN's Button styles are Platform.select({ios, android}) and Platform.OS is 'embedded', so neither
36
+ // branch applies. These are the android ones — a filled, rounded button — because a panel button
37
+ // should read as a button before it is styled, and the ios branch is bare text. RN's `elevation: 4`
38
+ // is dropped: shadows are compile-gated (ERUI_SHADOWS) and off in every board config here, so it
39
+ // would be a prop marshaled on every commit to paint nothing.
40
+ const styles = {
41
+ button: {backgroundColor: '#2196F3', borderRadius: 2},
42
+ buttonDisabled: {backgroundColor: '#dfdfdf'},
43
+ text: {color: '#ffffff', textAlign: 'center', padding: 8, fontWeight: '500'},
44
+ textDisabled: {color: '#a1a1a1'},
45
+ };
46
+
47
+ /** The props that do something here. RN's rest are OS services with nothing to wrap on an MCU. */
48
+ const SUPPORTED = ['title', 'onPress', 'color', 'disabled'];
49
+
50
+ const warnUnsupportedProps = createPropWarner(
51
+ 'Button',
52
+ SUPPORTED,
53
+ "it is RN's fixed-style button — for a button you style yourself, use <Pressable> + <Text> " +
54
+ '(the same tree this renders).',
55
+ RN_PLATFORM_NO_OPS,
56
+ );
57
+
58
+ /**
59
+ * A pre-styled press target with a centred label.
60
+ *
61
+ * @param {object} [props] Missing / empty renders an unlabelled button, rather than throwing on a
62
+ * device where a render-time throw takes the whole app down (RN `invariant`s on a missing title).
63
+ * @param {string} [props.title] The label. Coerced to a string; not upper-cased (RN does that on
64
+ * Android, and an upper-cased glyph an app never wrote is a glyph the font bake never baked).
65
+ * @param {(event: object) => void} [props.onPress] Press handler. Not attached while `disabled`.
66
+ * @param {string} [props.color] Fill colour, replacing the default blue.
67
+ * @param {boolean} [props.disabled] Greys the button out and stops it responding to presses.
68
+ * @returns {*} A <Pressable> wrapping a single <Text>.
69
+ */
70
+ export function Button(props = {}) {
71
+ const {title, onPress, color, disabled} = props;
72
+
73
+ warnUnsupportedProps(props);
74
+
75
+ const buttonStyles = [styles.button];
76
+ const textStyles = [styles.text];
77
+ if (color) buttonStyles.push({backgroundColor: color});
78
+ if (disabled) {
79
+ buttonStyles.push(styles.buttonDisabled);
80
+ textStyles.push(styles.textDisabled);
81
+ }
82
+
83
+ return createElement(
84
+ Pressable,
85
+ {
86
+ style: buttonStyles,
87
+ disabled,
88
+ // Withholding the handler is what actually disables the button: `disabled` is a Pressable prop
89
+ // in name only (the engine has no such node flag), so a node left holding onPress still fires.
90
+ onPress: disabled ? undefined : onPress,
91
+ },
92
+ createElement(
93
+ Text,
94
+ {style: textStyles},
95
+ title === undefined || title === null ? '' : String(title),
96
+ ),
97
+ );
98
+ }
@@ -0,0 +1,88 @@
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
+ // FlatList — a thin API-compat wrapper over <ScrollView>, NOT a virtualized list.
18
+ //
19
+ // <FlatList data={items} keyExtractor={(it) => it.id}
20
+ // renderItem={({item}) => <Row item={item} />} />
21
+ // renders the same tree as
22
+ // <ScrollView>{items.map((item) => <Row key={item.id} item={item} />)}</ScrollView>
23
+ //
24
+ // Keys are the one part that is not literal: this component attaches each row's key itself (see
25
+ // below), so callers never write one. Flow B ignores keys entirely — it unrolls at compile time.
26
+ //
27
+ // There is no windowing: every row mounts as a real engine node and stays mounted, so the list costs
28
+ // data.length x (nodes per row) slots out of the fixed ERUI_MAX_NODES pool. See "FlatList is a
29
+ // ScrollView alias" in the top-level README for the limits and when to reach for something else.
30
+ //
31
+ // This mirrors the AOT's emitFlatList (bridges/quickjs/js/aot/compile.mjs), which performs the same
32
+ // rewrite at compile time. The two flows accept the SAME four props on purpose — a list that renders
33
+ // in the simulator must also compile for the device, so anything Flow B rejects is warned about here
34
+ // rather than silently forwarded.
35
+ import {createElement} from 'react';
36
+ import {ScrollView} from './components.js';
37
+ import {pushKeyedChild} from './list-child.js';
38
+ import {createPropWarner} from './warn-props.js';
39
+
40
+ /** The only props both flows honour. Everything else is a virtualization/platform knob with no meaning. */
41
+ const SUPPORTED = ['data', 'renderItem', 'keyExtractor', 'style'];
42
+
43
+ // Warns once about props that do nothing here and that the AOT refuses to compile, so a list built in
44
+ // the simulator doesn't fail the device build later.
45
+ const warnUnsupportedProps = createPropWarner(
46
+ 'FlatList',
47
+ SUPPORTED,
48
+ 'it is a thin <ScrollView> alias with no virtualization, and the AOT rejects these props outright ' +
49
+ '("AOT: <FlatList> prop ... is not supported"). For headers/footers/separators/horizontal/' +
50
+ 'onEndReached, use <ScrollView> + .map directly.',
51
+ );
52
+
53
+ /**
54
+ * Renders `data` through `renderItem` into a <ScrollView>. Rows that render to nothing (null / false)
55
+ * are dropped, matching a plain `.map` + conditional.
56
+ *
57
+ * @param {object} [props] Missing / empty renders an empty scroller, like a missing `data`.
58
+ * @param {Array} [props.data] Row data. A non-array (or missing) renders an empty scroller.
59
+ * @param {(info: {item: *, index: number}) => *} [props.renderItem] Row renderer, called per item.
60
+ * @param {(item: *, index: number) => string|number} [props.keyExtractor] React key per row; defaults
61
+ * to the key `renderItem` already set, else the index.
62
+ * @param {object} [props.style] Forwarded to the ScrollView untouched.
63
+ * @returns {*} A <ScrollView> element holding one child per rendered row.
64
+ */
65
+ export function FlatList(props = {}) {
66
+ const {data, renderItem, keyExtractor, style} = props;
67
+
68
+ warnUnsupportedProps(props);
69
+
70
+ const rows = [];
71
+ if (Array.isArray(data) && typeof renderItem === 'function') {
72
+ for (let index = 0; index < data.length; index++) {
73
+ const item = data[index];
74
+ const row = renderItem({item, index});
75
+ // The key is built lazily: pushKeyedChild calls this only for a row that can hold one, so
76
+ // keyExtractor never runs for a row that rendered nothing or for a raw string.
77
+ pushKeyedChild(rows, row, el =>
78
+ keyExtractor
79
+ ? String(keyExtractor(item, index))
80
+ : el.key !== null && el.key !== undefined
81
+ ? el.key
82
+ : String(index),
83
+ );
84
+ }
85
+ }
86
+
87
+ return createElement(ScrollView, style === undefined ? null : {style}, rows);
88
+ }
@@ -0,0 +1,67 @@
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
+ // ImageBackground — RN's "content on top of a picture" wrapper, as a plain component. No engine node
18
+ // of its own:
19
+ //
20
+ // <ImageBackground source={wallpaper} style={{flex: 1}}><Text>hi</Text></ImageBackground>
21
+ // renders the same tree as
22
+ // <View style={{flex: 1}}>
23
+ // <Image source={wallpaper} style={StyleSheet.absoluteFill} />
24
+ // <Text>hi</Text>
25
+ // </View>
26
+ //
27
+ // <Image> cannot take children (it is a leaf node in the engine, as in RN), which is the whole reason
28
+ // this component exists. The image is absolutely positioned, so it is outside the flow: the children
29
+ // lay out against the <View> as if it weren't there, and they paint over it because the engine paints
30
+ // in tree order.
31
+ //
32
+ // One deliberate difference from upstream, because our <Image> is a plain scene node: RN re-proxies
33
+ // the container's width/height onto the image to undo <Image>'s own sizing. Ours doesn't size itself,
34
+ // so the inset alone fills the box — and since an absolute child resolves its insets against the
35
+ // container's PADDING box, as in RN, the picture fills the whole container even when it has padding.
36
+ import {createElement, forwardRef} from 'react';
37
+ import {View, Image} from './components.js';
38
+ import {StyleSheet} from './StyleSheet.js';
39
+
40
+ /**
41
+ * A <View> with an <Image> stretched behind its children.
42
+ *
43
+ * `style` sizes and lays out the container; every OTHER prop goes to the <Image>, exactly as upstream
44
+ * — `source`, `resizeMode` and `tintColor` are the ones worth setting. Note that this puts touch and
45
+ * `onLayout` handlers on the image rather than the container, and the children paint on top of it, so
46
+ * a handler meant for the whole area belongs on a <Pressable> around this component.
47
+ *
48
+ * @param {object} props Image props, plus the four below.
49
+ * @param {*} [props.style] Container style — the box the picture fills.
50
+ * @param {*} [props.imageStyle] Style merged over the fill, for `borderRadius`, `opacity`, `tintColor`.
51
+ * @param {*} [props.imageRef] Ref to the <Image> node (the outer `ref` goes to the <View>).
52
+ * @param {*} [props.children] Rendered above the picture, laid out against the container.
53
+ * @returns {*} A <View> whose first child is the backing <Image>.
54
+ */
55
+ export const ImageBackground = forwardRef(function ImageBackground(props, ref) {
56
+ const {children, style, imageStyle, imageRef, ...imageProps} = props;
57
+ return createElement(
58
+ View,
59
+ {style, ref},
60
+ createElement(Image, {
61
+ ...imageProps,
62
+ style: [StyleSheet.absoluteFill, imageStyle],
63
+ ref: imageRef,
64
+ }),
65
+ children,
66
+ );
67
+ });