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
package/sim-server.mjs
CHANGED
|
@@ -53,11 +53,16 @@ const {registerSvgVectorLoader} = await import(
|
|
|
53
53
|
const {transformPersist, shouldPersist} = await import(
|
|
54
54
|
pathToFileURL(resolve(HERE, 'persist-transform.mjs')).href
|
|
55
55
|
);
|
|
56
|
+
const {loadAppFile, loadDependencyFile} =
|
|
57
|
+
await import('./aot/app-file-loader.mjs');
|
|
56
58
|
|
|
57
59
|
const REACT_PIN = Object.fromEntries(
|
|
58
60
|
['react', 'react-reconciler', 'scheduler']
|
|
59
|
-
.map(
|
|
60
|
-
|
|
61
|
+
.map(packageName => [
|
|
62
|
+
packageName,
|
|
63
|
+
resolve(HERE, 'node_modules', packageName),
|
|
64
|
+
])
|
|
65
|
+
.filter(([, pinPath]) => existsSync(pinPath)),
|
|
61
66
|
);
|
|
62
67
|
|
|
63
68
|
const MIME = {
|
|
@@ -66,10 +71,10 @@ const MIME = {
|
|
|
66
71
|
'.wasm': 'application/wasm',
|
|
67
72
|
'.pack': 'application/octet-stream',
|
|
68
73
|
};
|
|
69
|
-
const assetName =
|
|
70
|
-
const mtime =
|
|
74
|
+
const assetName = filePath => basename(filePath).replace(/\.[^.]+$/, '');
|
|
75
|
+
const mtime = filePath => {
|
|
71
76
|
try {
|
|
72
|
-
return statSync(
|
|
77
|
+
return statSync(filePath).mtimeMs;
|
|
73
78
|
} catch {
|
|
74
79
|
return 0;
|
|
75
80
|
}
|
|
@@ -97,23 +102,26 @@ function createBundle({
|
|
|
97
102
|
}) {
|
|
98
103
|
const bundlePath = resolve(outDir, 'app.js');
|
|
99
104
|
const packPath = resolve(outDir, 'assets.pack');
|
|
100
|
-
const
|
|
105
|
+
const projectRootNormalized = projectRoot.replace(/\\/g, '/');
|
|
101
106
|
const images = new Map();
|
|
102
107
|
const fonts = new Map();
|
|
103
|
-
let
|
|
108
|
+
let lastAssetSignature = null;
|
|
104
109
|
|
|
105
110
|
async function bakePack() {
|
|
106
|
-
const
|
|
107
|
-
const usedSizes = analyzeFontSizes(
|
|
111
|
+
const bundleSource = readFileSync(bundlePath, 'utf8');
|
|
112
|
+
const usedSizes = analyzeFontSizes(bundleSource);
|
|
108
113
|
|
|
109
|
-
let
|
|
110
|
-
const
|
|
111
|
-
if (existsSync(
|
|
112
|
-
|
|
113
|
-
(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
let assetsConfig = {};
|
|
115
|
+
const assetsConfigPath = resolve(projectRoot, 'assets.config.js');
|
|
116
|
+
if (existsSync(assetsConfigPath))
|
|
117
|
+
assetsConfig =
|
|
118
|
+
(
|
|
119
|
+
await import(
|
|
120
|
+
`${pathToFileURL(assetsConfigPath).href}?t=${mtime(assetsConfigPath)}`
|
|
121
|
+
)
|
|
122
|
+
).default || {};
|
|
123
|
+
const fontConfig = assetsConfig.fonts || {};
|
|
124
|
+
const imageConfig = assetsConfig.images || {};
|
|
117
125
|
|
|
118
126
|
const fontJobs = resolveFontJobs(fonts, fontConfig, usedSizes.sizes);
|
|
119
127
|
const imageJobs = [...images.entries()].map(([name, path]) => ({
|
|
@@ -124,44 +132,46 @@ function createBundle({
|
|
|
124
132
|
|
|
125
133
|
// The app's text is an asset input too: new characters and new font sizes must both be
|
|
126
134
|
// re-checked against the bake even when no font or image file changed.
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
const assetSignature = JSON.stringify({
|
|
136
|
+
text: textSignature(bundleSource),
|
|
137
|
+
fontSizes: fontSizeSignature(usedSizes),
|
|
138
|
+
images: imageJobs
|
|
139
|
+
.map(job => [job.name, job.path, mtime(job.path), job.format])
|
|
140
|
+
.sort(),
|
|
141
|
+
fonts: fontJobs
|
|
142
|
+
.map(job => [
|
|
143
|
+
job.family,
|
|
144
|
+
job.path,
|
|
145
|
+
mtime(job.path),
|
|
146
|
+
job.sizes,
|
|
147
|
+
job.bpp,
|
|
148
|
+
job.glyphs,
|
|
149
|
+
job.extraGlyphs,
|
|
140
150
|
])
|
|
141
151
|
.sort(),
|
|
142
152
|
});
|
|
143
|
-
if (
|
|
144
|
-
|
|
153
|
+
if (assetSignature === lastAssetSignature) return;
|
|
154
|
+
lastAssetSignature = assetSignature;
|
|
145
155
|
if (!imageJobs.length && !fontJobs.length) {
|
|
146
156
|
// Built-in font only → no pack, but its glyph and size coverage still bind.
|
|
147
|
-
warnMissingGlyphs({source:
|
|
157
|
+
warnMissingGlyphs({source: bundleSource});
|
|
148
158
|
warnFontSizes({used: usedSizes});
|
|
149
159
|
return;
|
|
150
160
|
}
|
|
151
161
|
|
|
152
162
|
try {
|
|
153
|
-
const
|
|
163
|
+
const summary = bakeAssetPack({
|
|
154
164
|
images: imageJobs,
|
|
155
165
|
fonts: fontJobs,
|
|
156
166
|
outPath: packPath,
|
|
157
|
-
source:
|
|
167
|
+
source: bundleSource,
|
|
158
168
|
usedSizes,
|
|
159
169
|
});
|
|
160
170
|
console.log(
|
|
161
|
-
` assets → ${
|
|
171
|
+
` assets → ${summary.images} image(s), ${summary.fonts} font size(s), ${summary.bytes} B`,
|
|
162
172
|
);
|
|
163
|
-
} catch (
|
|
164
|
-
console.error(` asset bake failed: ${
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.error(` asset bake failed: ${error.message}`);
|
|
165
175
|
}
|
|
166
176
|
}
|
|
167
177
|
|
|
@@ -181,52 +191,61 @@ function createBundle({
|
|
|
181
191
|
plugins: [
|
|
182
192
|
{
|
|
183
193
|
name: 'embedded-react-websim',
|
|
184
|
-
setup(
|
|
185
|
-
|
|
194
|
+
setup(pluginBuild) {
|
|
195
|
+
pluginBuild.onStart(() => {
|
|
186
196
|
images.clear();
|
|
187
197
|
fonts.clear();
|
|
188
198
|
});
|
|
189
|
-
|
|
190
|
-
//
|
|
191
|
-
//
|
|
192
|
-
|
|
199
|
+
pluginBuild.onLoad({filter: /\.(jsx?|tsx?)$/}, async loadArgs => {
|
|
200
|
+
// Only the app's own source — never dependencies (see shouldPersist: excluding node_modules is what
|
|
201
|
+
// stops the library's usePersistentState being rewritten to call itself). Native modules get their
|
|
202
|
+
// signatures and mocks, and with persist on, useState persists. A package's native modules get theirs too.
|
|
203
|
+
if (!shouldPersist(loadArgs.path, projectRootNormalized))
|
|
204
|
+
return loadDependencyFile(loadArgs.path, {mocks: true});
|
|
193
205
|
try {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
} catch (
|
|
209
|
-
return {errors: [{text: `persist transform: ${
|
|
206
|
+
return await loadAppFile(
|
|
207
|
+
loadArgs.path,
|
|
208
|
+
persist
|
|
209
|
+
? source =>
|
|
210
|
+
transformPersist(
|
|
211
|
+
source,
|
|
212
|
+
relative(projectRoot, loadArgs.path).replace(
|
|
213
|
+
/\\/g,
|
|
214
|
+
'/',
|
|
215
|
+
),
|
|
216
|
+
)
|
|
217
|
+
: undefined,
|
|
218
|
+
{mocks: true},
|
|
219
|
+
);
|
|
220
|
+
} catch (error) {
|
|
221
|
+
return {errors: [{text: `persist transform: ${error.message}`}]};
|
|
210
222
|
}
|
|
211
223
|
});
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
224
|
+
pluginBuild.onLoad(
|
|
225
|
+
{filter: /\.(png|jpe?g|webp|gif|bmp)$/i},
|
|
226
|
+
loadArgs => {
|
|
227
|
+
images.set(assetName(loadArgs.path), loadArgs.path);
|
|
228
|
+
return {
|
|
229
|
+
contents: `module.exports = ${JSON.stringify(assetName(loadArgs.path))};`,
|
|
230
|
+
loader: 'js',
|
|
231
|
+
};
|
|
232
|
+
},
|
|
233
|
+
);
|
|
234
|
+
pluginBuild.onLoad({filter: /\.(ttf|otf)$/i}, loadArgs => {
|
|
235
|
+
fonts.set(assetName(loadArgs.path), loadArgs.path);
|
|
221
236
|
return {
|
|
222
|
-
contents: `module.exports = ${JSON.stringify(assetName(
|
|
237
|
+
contents: `module.exports = ${JSON.stringify(assetName(loadArgs.path))};`,
|
|
223
238
|
loader: 'js',
|
|
224
239
|
};
|
|
225
240
|
});
|
|
226
|
-
registerSvgVectorLoader(
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
241
|
+
registerSvgVectorLoader(pluginBuild, (name, svgPath) =>
|
|
242
|
+
images.set(name, svgPath),
|
|
243
|
+
); // raster-fallback SVGs join the image pack
|
|
244
|
+
pluginBuild.onEnd(async result => {
|
|
245
|
+
if (result.errors.length) {
|
|
246
|
+
console.error(
|
|
247
|
+
`✗ build failed (${result.errors.length} error(s))`,
|
|
248
|
+
);
|
|
230
249
|
return;
|
|
231
250
|
}
|
|
232
251
|
await bakePack();
|
|
@@ -283,7 +302,7 @@ export async function runDevServer({
|
|
|
283
302
|
}) {
|
|
284
303
|
const clients = new Set();
|
|
285
304
|
const broadcastReload = () => {
|
|
286
|
-
for (const
|
|
305
|
+
for (const response of clients) response.write('data: reload\n\n');
|
|
287
306
|
};
|
|
288
307
|
|
|
289
308
|
const {options} = createBundle({
|
|
@@ -299,38 +318,38 @@ export async function runDevServer({
|
|
|
299
318
|
},
|
|
300
319
|
});
|
|
301
320
|
|
|
302
|
-
const
|
|
303
|
-
await
|
|
304
|
-
await
|
|
321
|
+
const buildContext = await esbuild.context(options);
|
|
322
|
+
await buildContext.rebuild();
|
|
323
|
+
await buildContext.watch();
|
|
305
324
|
|
|
306
325
|
// Serve the host page; embedded-react.{js,wasm} from simDir, the freshly bundled app.js/assets.pack from
|
|
307
326
|
// outDir. The page references ./public/<name>. window.__erHot is injected so the page connects to /reload.
|
|
308
|
-
const send = async (
|
|
327
|
+
const send = async (response, file) => {
|
|
309
328
|
try {
|
|
310
329
|
const body = await readFile(file);
|
|
311
|
-
|
|
330
|
+
response
|
|
312
331
|
.writeHead(200, {
|
|
313
332
|
'content-type': MIME[extname(file)] || 'application/octet-stream',
|
|
314
333
|
'cache-control': 'no-store',
|
|
315
334
|
})
|
|
316
335
|
.end(body);
|
|
317
336
|
} catch {
|
|
318
|
-
|
|
337
|
+
response.writeHead(404).end('not found');
|
|
319
338
|
}
|
|
320
339
|
};
|
|
321
|
-
const server = createServer(async (
|
|
340
|
+
const server = createServer(async (request, response) => {
|
|
322
341
|
const path = decodeURIComponent(
|
|
323
|
-
new URL(
|
|
342
|
+
new URL(request.url, 'http://localhost').pathname,
|
|
324
343
|
);
|
|
325
344
|
if (path === '/reload') {
|
|
326
|
-
|
|
345
|
+
response.writeHead(200, {
|
|
327
346
|
'content-type': 'text/event-stream',
|
|
328
347
|
'cache-control': 'no-cache',
|
|
329
348
|
connection: 'keep-alive',
|
|
330
349
|
});
|
|
331
|
-
|
|
332
|
-
clients.add(
|
|
333
|
-
|
|
350
|
+
response.write('retry: 1000\n\n');
|
|
351
|
+
clients.add(response);
|
|
352
|
+
request.on('close', () => clients.delete(response));
|
|
334
353
|
return;
|
|
335
354
|
}
|
|
336
355
|
if (path === '/' || path === '/index.html') {
|
|
@@ -339,14 +358,14 @@ export async function runDevServer({
|
|
|
339
358
|
'</head>',
|
|
340
359
|
'<script>window.__erHot=true</script></head>',
|
|
341
360
|
);
|
|
342
|
-
|
|
361
|
+
response
|
|
343
362
|
.writeHead(200, {
|
|
344
363
|
'content-type': MIME['.html'],
|
|
345
364
|
'cache-control': 'no-store',
|
|
346
365
|
})
|
|
347
366
|
.end(html);
|
|
348
367
|
} catch {
|
|
349
|
-
|
|
368
|
+
response.writeHead(404).end('not found');
|
|
350
369
|
}
|
|
351
370
|
return;
|
|
352
371
|
}
|
|
@@ -356,23 +375,23 @@ export async function runDevServer({
|
|
|
356
375
|
name === 'embedded-react.js' || name === 'embedded-react.wasm'
|
|
357
376
|
? simDir
|
|
358
377
|
: outDir;
|
|
359
|
-
return void send(
|
|
378
|
+
return void send(response, resolve(dir, name));
|
|
360
379
|
}
|
|
361
|
-
|
|
380
|
+
response.writeHead(404).end('not found');
|
|
362
381
|
});
|
|
363
382
|
|
|
364
|
-
await new Promise(
|
|
383
|
+
await new Promise(onListening => server.listen(port, onListening));
|
|
365
384
|
console.log(`embedded-react WASM sim → http://localhost:${port}/`);
|
|
366
385
|
console.log(`watching ${label} — edit & save to hot-reload. Ctrl-C to quit.`);
|
|
367
386
|
|
|
368
387
|
const shutdown = async () => {
|
|
369
388
|
try {
|
|
370
|
-
await
|
|
389
|
+
await buildContext.dispose();
|
|
371
390
|
} catch {}
|
|
372
391
|
server.close();
|
|
373
392
|
process.exit(0);
|
|
374
393
|
};
|
|
375
394
|
process.on('SIGINT', shutdown);
|
|
376
395
|
process.on('SIGTERM', shutdown);
|
|
377
|
-
return {ctx, server};
|
|
396
|
+
return {ctx: buildContext, server};
|
|
378
397
|
}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
// Animated — the React Native analog, backed by the engine's native-driver value system
|
|
18
|
-
// (
|
|
18
|
+
// (er_animation_value_*). An Animated.Value is a handle to an engine-side float; binding it to a node
|
|
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';
|
|
@@ -55,9 +55,9 @@ export class AnimatedValue {
|
|
|
55
55
|
this._destroyed = false;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
setValue(
|
|
59
|
-
this._value =
|
|
60
|
-
NativeUI.animValueSet(this._handle,
|
|
58
|
+
setValue(value) {
|
|
59
|
+
this._value = value;
|
|
60
|
+
NativeUI.animValueSet(this._handle, value);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
@@ -103,14 +103,14 @@ export class AnimatedInterpolation {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
__bind(node, prop) {
|
|
106
|
-
const
|
|
107
|
-
if (Array.isArray(
|
|
106
|
+
const outputRange = this._config?.outputRange;
|
|
107
|
+
if (Array.isArray(outputRange)) {
|
|
108
108
|
if (COLOR_PROPS.has(prop)) {
|
|
109
|
-
if (
|
|
109
|
+
if (outputRange.some(output => typeof output !== 'string')) {
|
|
110
110
|
warnColorBind(prop);
|
|
111
111
|
return;
|
|
112
112
|
}
|
|
113
|
-
} else if (
|
|
113
|
+
} else if (outputRange.some(output => typeof output !== 'number')) {
|
|
114
114
|
warnNumberBind(prop);
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
@@ -142,13 +142,13 @@ export class AnimatedInterpolation {
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
/** Wraps
|
|
146
|
-
function once(
|
|
145
|
+
/** Wraps callback so it runs at most once, regardless of how many times it is invoked. */
|
|
146
|
+
function once(callback) {
|
|
147
147
|
let called = false;
|
|
148
|
-
return
|
|
148
|
+
return argument => {
|
|
149
149
|
if (called) return;
|
|
150
150
|
called = true;
|
|
151
|
-
if (
|
|
151
|
+
if (callback) callback(argument);
|
|
152
152
|
};
|
|
153
153
|
}
|
|
154
154
|
|
|
@@ -166,11 +166,11 @@ function makeAnimation(value, toValue, config) {
|
|
|
166
166
|
_value: value,
|
|
167
167
|
start(onComplete) {
|
|
168
168
|
// Always pass a wrapper so we can null out the (possibly recycled) handle on completion.
|
|
169
|
-
const
|
|
169
|
+
const onEnd = finished => {
|
|
170
170
|
handle = 0;
|
|
171
171
|
if (onComplete) onComplete({finished: !!finished});
|
|
172
172
|
};
|
|
173
|
-
handle = NativeUI.animValueAnimate(value._handle, toValue, config,
|
|
173
|
+
handle = NativeUI.animValueAnimate(value._handle, toValue, config, onEnd);
|
|
174
174
|
},
|
|
175
175
|
stop() {
|
|
176
176
|
if (handle) NativeUI.animStop(handle);
|
|
@@ -252,16 +252,16 @@ export function parallel(animations, config) {
|
|
|
252
252
|
anyUnfinished = true;
|
|
253
253
|
if (stopTogether && !stopped) {
|
|
254
254
|
stopped = true;
|
|
255
|
-
for (const
|
|
255
|
+
for (const animation of animations) animation.stop();
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
if (doneCount >= total) done({finished: !anyUnfinished});
|
|
259
259
|
};
|
|
260
|
-
for (const
|
|
260
|
+
for (const animation of animations) animation.start(onChild);
|
|
261
261
|
},
|
|
262
262
|
stop() {
|
|
263
263
|
stopped = true;
|
|
264
|
-
for (const
|
|
264
|
+
for (const animation of animations) animation.stop();
|
|
265
265
|
},
|
|
266
266
|
};
|
|
267
267
|
}
|
|
@@ -285,22 +285,22 @@ export function stagger(delay, animations) {
|
|
|
285
285
|
if (!result || result.finished === false) anyUnfinished = true;
|
|
286
286
|
if (doneCount >= total) done({finished: !anyUnfinished});
|
|
287
287
|
};
|
|
288
|
-
animations.forEach((
|
|
289
|
-
if (
|
|
290
|
-
|
|
288
|
+
animations.forEach((animation, index) => {
|
|
289
|
+
if (index === 0) {
|
|
290
|
+
animation.start(onChild);
|
|
291
291
|
} else {
|
|
292
292
|
timers.push(
|
|
293
293
|
setTimeout(() => {
|
|
294
|
-
if (!stopped)
|
|
295
|
-
}, delay *
|
|
294
|
+
if (!stopped) animation.start(onChild);
|
|
295
|
+
}, delay * index),
|
|
296
296
|
);
|
|
297
297
|
}
|
|
298
298
|
});
|
|
299
299
|
},
|
|
300
300
|
stop() {
|
|
301
301
|
stopped = true;
|
|
302
|
-
for (const
|
|
303
|
-
for (const
|
|
302
|
+
for (const timer of timers) clearTimeout(timer);
|
|
303
|
+
for (const animation of animations) animation.stop();
|
|
304
304
|
},
|
|
305
305
|
};
|
|
306
306
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
// Dimensions — RN analog over the host-injected `screen` global. A panel has no pixel-density or font
|
|
18
|
+
// setting, so `scale` and `fontScale` are 1, and 'window' and 'screen' are the same size.
|
|
19
|
+
export const Dimensions = {
|
|
20
|
+
get(dimension) {
|
|
21
|
+
if (dimension !== 'window' && dimension !== 'screen') {
|
|
22
|
+
throw new Error(`Dimensions.get: no dimension named "${dimension}"`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
width: screen.width,
|
|
27
|
+
height: screen.height,
|
|
28
|
+
scale: 1,
|
|
29
|
+
fontScale: 1,
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// The panel's size. It is fixed while the app runs, so this never re-renders.
|
|
35
|
+
export function useWindowDimensions() {
|
|
36
|
+
return Dimensions.get('window');
|
|
37
|
+
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
// Easing tokens. The engine implements a fixed set of easing curves (
|
|
17
|
+
// Easing tokens. The engine implements a fixed set of easing curves (ERAnimationEasing), so unlike RN's
|
|
18
18
|
// composable Easing functions these are string tokens the bridge maps to the engine enum. `bezier`
|
|
19
19
|
// returns a control-point object the bridge reads as a custom cubic-bezier curve.
|
|
20
20
|
export const Easing = {
|
|
@@ -74,11 +74,11 @@ export function FlatList(props = {}) {
|
|
|
74
74
|
const row = renderItem({item, index});
|
|
75
75
|
// The key is built lazily: pushKeyedChild calls this only for a row that can hold one, so
|
|
76
76
|
// keyExtractor never runs for a row that rendered nothing or for a raw string.
|
|
77
|
-
pushKeyedChild(rows, row,
|
|
77
|
+
pushKeyedChild(rows, row, element =>
|
|
78
78
|
keyExtractor
|
|
79
79
|
? String(keyExtractor(item, index))
|
|
80
|
-
:
|
|
81
|
-
?
|
|
80
|
+
: element.key !== null && element.key !== undefined
|
|
81
|
+
? element.key
|
|
82
82
|
: String(index),
|
|
83
83
|
);
|
|
84
84
|
}
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
// LayoutAnimation — the React Native analog. Calling configureNext(...) before a state update that
|
|
18
18
|
// changes layout makes the engine tween every node whose computed rect moved (instead of snapping)
|
|
19
|
-
// on the next commit. Backed by the engine's
|
|
20
|
-
// each frame (
|
|
19
|
+
// on the next commit. Backed by the engine's er_layout_animation_configure_next; the tween advances in C
|
|
20
|
+
// each frame (er_layout_animation_tick), so there's no per-frame JS.
|
|
21
21
|
import {NativeUI} from '../native-ui.js';
|
|
22
22
|
import {
|
|
23
23
|
Types,
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
Presets,
|
|
26
26
|
toEngineConfig,
|
|
27
27
|
create,
|
|
28
|
+
DEFAULT_DURATION_MS,
|
|
28
29
|
} from './layout-anim-config.js';
|
|
29
30
|
|
|
30
31
|
/**
|
|
@@ -34,9 +35,11 @@ import {
|
|
|
34
35
|
export function configureNext(config, onAnimationDidEnd) {
|
|
35
36
|
NativeUI.configureNextLayoutAnimation(toEngineConfig(config));
|
|
36
37
|
if (typeof onAnimationDidEnd === 'function') {
|
|
37
|
-
const
|
|
38
|
-
config && typeof config.duration === 'number'
|
|
39
|
-
|
|
38
|
+
const durationMs =
|
|
39
|
+
config && typeof config.duration === 'number'
|
|
40
|
+
? config.duration
|
|
41
|
+
: DEFAULT_DURATION_MS;
|
|
42
|
+
setTimeout(onAnimationDidEnd, durationMs);
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
|