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
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
//
|
|
24
24
|
// const pan = useRef(PanResponder.create({
|
|
25
25
|
// onStartShouldSetPanResponder: () => true,
|
|
26
|
-
// onPanResponderMove: (
|
|
27
|
-
// onPanResponderRelease: (
|
|
26
|
+
// onPanResponderMove: (event, gesture) => setX(gesture.dx),
|
|
27
|
+
// onPanResponderRelease: (event, gesture) => (gesture.vx > 0.5 ? next() : settle()),
|
|
28
28
|
// })).current;
|
|
29
29
|
//
|
|
30
30
|
// <View {...pan.panHandlers} />
|
|
@@ -86,7 +86,8 @@ const SUPPORTED = [
|
|
|
86
86
|
* The engine's monotonic millisecond clock, used for velocity. `performance.now()` is installed by the
|
|
87
87
|
* QuickJS runtime on every context (it is React's scheduler clock) and exists in the simulator and in
|
|
88
88
|
* Node; `Date.now()` jumps whenever the host sets the wall clock, so it is never used here.
|
|
89
|
-
* The clock only advances when the host ticks, so
|
|
89
|
+
* The clock only advances when the host ticks, so an elapsed time of 0 is normal and leaves velocity
|
|
90
|
+
* untouched.
|
|
90
91
|
*/
|
|
91
92
|
const now = () =>
|
|
92
93
|
typeof performance !== 'undefined' && typeof performance.now === 'function'
|
|
@@ -108,10 +109,10 @@ function asConfig(config) {
|
|
|
108
109
|
/** Warns ONCE PER KEY about config keys this module does not act on. */
|
|
109
110
|
function warnUnsupportedConfig(config) {
|
|
110
111
|
const names = Object.keys(config).filter(
|
|
111
|
-
|
|
112
|
+
key => !SUPPORTED.includes(key) && !s_warnedKeys.has(key),
|
|
112
113
|
);
|
|
113
114
|
if (names.length === 0) return;
|
|
114
|
-
for (const
|
|
115
|
+
for (const key of names) s_warnedKeys.add(key);
|
|
115
116
|
console.warn(
|
|
116
117
|
`embedded-react: PanResponder ignores ${names.join(', ')} — ` +
|
|
117
118
|
`supported: ${SUPPORTED.join(', ')}.`,
|
|
@@ -122,17 +123,17 @@ function warnUnsupportedConfig(config) {
|
|
|
122
123
|
* Clears the travel/velocity fields between gestures. `numberActiveTouches` is deliberately left alone:
|
|
123
124
|
* it counts fingers on the panel, which outlives the gesture when a second finger is still down.
|
|
124
125
|
*
|
|
125
|
-
* @param {object}
|
|
126
|
+
* @param {object} gestureState The gesture state to reset in place.
|
|
126
127
|
*/
|
|
127
|
-
function resetGestureState(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
128
|
+
function resetGestureState(gestureState) {
|
|
129
|
+
gestureState.moveX = 0;
|
|
130
|
+
gestureState.moveY = 0;
|
|
131
|
+
gestureState.x0 = 0;
|
|
132
|
+
gestureState.y0 = 0;
|
|
133
|
+
gestureState.dx = 0;
|
|
134
|
+
gestureState.dy = 0;
|
|
135
|
+
gestureState.vx = 0;
|
|
136
|
+
gestureState.vy = 0;
|
|
136
137
|
}
|
|
137
138
|
|
|
138
139
|
/**
|
|
@@ -170,62 +171,63 @@ export function create(userConfig = {}) {
|
|
|
170
171
|
|
|
171
172
|
let granted = false;
|
|
172
173
|
let lastMoveTime = 0;
|
|
173
|
-
// The engine measures
|
|
174
|
-
// GRANT — a responder that needed 10px of slop to claim starts its own
|
|
175
|
-
// never shows up as a jump. The base is what
|
|
174
|
+
// The engine measures event.dx/event.dy from TOUCH-DOWN; RN (and this module) measure
|
|
175
|
+
// gestureState.dx/dy from the GRANT — a responder that needed 10px of slop to claim starts its own
|
|
176
|
+
// travel at zero, so the slop never shows up as a jump. The base is what event.dx read at the moment
|
|
177
|
+
// of the grant.
|
|
176
178
|
let baseDx = 0;
|
|
177
179
|
let baseDy = 0;
|
|
178
180
|
|
|
179
|
-
const fire = (name,
|
|
180
|
-
if (typeof config[name] === 'function') config[name](
|
|
181
|
+
const fire = (name, event) => {
|
|
182
|
+
if (typeof config[name] === 'function') config[name](event, gestureState);
|
|
181
183
|
};
|
|
182
184
|
|
|
183
|
-
/** Folds one engine payload (
|
|
184
|
-
const advance =
|
|
185
|
-
gestureState.moveX =
|
|
186
|
-
gestureState.moveY =
|
|
187
|
-
gestureState.dx =
|
|
188
|
-
gestureState.dy =
|
|
185
|
+
/** Folds one engine payload (event.x/y absolute, event.dx/dy from touch-down) into the travel fields. */
|
|
186
|
+
const advance = event => {
|
|
187
|
+
gestureState.moveX = event.x;
|
|
188
|
+
gestureState.moveY = event.y;
|
|
189
|
+
gestureState.dx = event.dx - baseDx;
|
|
190
|
+
gestureState.dy = event.dy - baseDy;
|
|
189
191
|
};
|
|
190
192
|
|
|
191
193
|
/** A move: travel, plus a fresh velocity reading over the time since the last one. */
|
|
192
|
-
const track =
|
|
193
|
-
const
|
|
194
|
-
const
|
|
195
|
-
const
|
|
196
|
-
const
|
|
194
|
+
const track = event => {
|
|
195
|
+
const time = now();
|
|
196
|
+
const elapsed = time - lastMoveTime;
|
|
197
|
+
const previousDx = gestureState.dx;
|
|
198
|
+
const previousDy = gestureState.dy;
|
|
197
199
|
|
|
198
|
-
advance(
|
|
200
|
+
advance(event);
|
|
199
201
|
|
|
200
|
-
//
|
|
201
|
-
// the division would be Infinity. Keeping the previous velocity is the honest
|
|
202
|
-
// has been measured yet.
|
|
203
|
-
if (
|
|
204
|
-
gestureState.vx = (gestureState.dx -
|
|
205
|
-
gestureState.vy = (gestureState.dy -
|
|
202
|
+
// The elapsed time is 0 whenever two touches land inside one host frame (the clock only moves on
|
|
203
|
+
// er_tick), and the division would be Infinity. Keeping the previous velocity is the honest
|
|
204
|
+
// answer: nothing new has been measured yet.
|
|
205
|
+
if (elapsed > 0) {
|
|
206
|
+
gestureState.vx = (gestureState.dx - previousDx) / elapsed;
|
|
207
|
+
gestureState.vy = (gestureState.dy - previousDy) / elapsed;
|
|
206
208
|
}
|
|
207
|
-
lastMoveTime =
|
|
209
|
+
lastMoveTime = time;
|
|
208
210
|
};
|
|
209
211
|
|
|
210
212
|
/** Wraps a should-set predicate as an engine query: track the point, ask, absent means "no" (as in RN). */
|
|
211
213
|
const query = name =>
|
|
212
214
|
typeof config[name] === 'function'
|
|
213
|
-
?
|
|
214
|
-
if (!granted) advance(
|
|
215
|
-
return config[name](
|
|
215
|
+
? event => {
|
|
216
|
+
if (!granted) advance(event);
|
|
217
|
+
return config[name](event, gestureState) === true;
|
|
216
218
|
}
|
|
217
219
|
: undefined;
|
|
218
220
|
|
|
219
221
|
/** Ends the gesture: reports it if this responder owned it, then clears the state for the next one. */
|
|
220
|
-
const finish = (
|
|
222
|
+
const finish = (event, callback) => {
|
|
221
223
|
const wasGranted = granted;
|
|
222
224
|
granted = false;
|
|
223
225
|
// Fold the final point into the travel so `dx` is the gesture's true total even when the finger
|
|
224
226
|
// lifted without a final move — but leave vx/vy at the last MOVE's reading. A fling ends with the
|
|
225
227
|
// finger resting for a frame or two, and re-measuring across that would report zero and throw the
|
|
226
228
|
// throw away.
|
|
227
|
-
advance(
|
|
228
|
-
if (wasGranted) fire(callback,
|
|
229
|
+
advance(event);
|
|
230
|
+
if (wasGranted) fire(callback, event);
|
|
229
231
|
resetGestureState(gestureState);
|
|
230
232
|
baseDx = 0;
|
|
231
233
|
baseDy = 0;
|
|
@@ -233,7 +235,7 @@ export function create(userConfig = {}) {
|
|
|
233
235
|
|
|
234
236
|
const panHandlers = {
|
|
235
237
|
// --- Raw touch bookkeeping (bubbles per finger): finger count + Start/End for extra fingers ---
|
|
236
|
-
onTouchStart(
|
|
238
|
+
onTouchStart(event) {
|
|
237
239
|
gestureState.numberActiveTouches += 1;
|
|
238
240
|
// A later finger joins the gesture in flight (the engine events carry no finger id, so
|
|
239
241
|
// independent tracking is impossible). Its own touch slot re-negotiates and re-grants this
|
|
@@ -242,19 +244,19 @@ export function create(userConfig = {}) {
|
|
|
242
244
|
resetGestureState(gestureState);
|
|
243
245
|
baseDx = 0;
|
|
244
246
|
baseDy = 0;
|
|
245
|
-
gestureState.x0 =
|
|
246
|
-
gestureState.y0 =
|
|
247
|
-
gestureState.moveX =
|
|
248
|
-
gestureState.moveY =
|
|
247
|
+
gestureState.x0 = event.x;
|
|
248
|
+
gestureState.y0 = event.y;
|
|
249
|
+
gestureState.moveX = event.x;
|
|
250
|
+
gestureState.moveY = event.y;
|
|
249
251
|
lastMoveTime = now();
|
|
250
252
|
},
|
|
251
|
-
onTouchEnd(
|
|
253
|
+
onTouchEnd(event) {
|
|
252
254
|
if (gestureState.numberActiveTouches > 0)
|
|
253
255
|
gestureState.numberActiveTouches -= 1;
|
|
254
256
|
// A finger lifted but the gesture continues; the RELEASE for the last one arrives as a
|
|
255
257
|
// responder event below.
|
|
256
258
|
if (granted && gestureState.numberActiveTouches > 0)
|
|
257
|
-
fire('onPanResponderEnd',
|
|
259
|
+
fire('onPanResponderEnd', event);
|
|
258
260
|
},
|
|
259
261
|
onTouchCancel() {
|
|
260
262
|
gestureState.numberActiveTouches = 0;
|
|
@@ -271,53 +273,55 @@ export function create(userConfig = {}) {
|
|
|
271
273
|
),
|
|
272
274
|
onResponderTerminationRequest:
|
|
273
275
|
typeof config.onPanResponderTerminationRequest === 'function'
|
|
274
|
-
?
|
|
276
|
+
? event =>
|
|
277
|
+
config.onPanResponderTerminationRequest(event, gestureState) ===
|
|
278
|
+
true
|
|
275
279
|
: undefined, // absent → the engine's default: yield (RN's default too)
|
|
276
280
|
|
|
277
281
|
// --- Responder lifecycle (native events; fire only on the node that owns the gesture) ---
|
|
278
|
-
onResponderGrant(
|
|
282
|
+
onResponderGrant(event) {
|
|
279
283
|
if (granted) {
|
|
280
284
|
// A second finger's touch slot granted the same node: one gesture, not two. RN calls this a
|
|
281
285
|
// responder "start" for the extra touch.
|
|
282
|
-
fire('onPanResponderStart',
|
|
286
|
+
fire('onPanResponderStart', event);
|
|
283
287
|
return;
|
|
284
288
|
}
|
|
285
289
|
granted = true;
|
|
286
|
-
baseDx =
|
|
287
|
-
baseDy =
|
|
288
|
-
gestureState.x0 =
|
|
289
|
-
gestureState.y0 =
|
|
290
|
+
baseDx = event.dx;
|
|
291
|
+
baseDy = event.dy;
|
|
292
|
+
gestureState.x0 = event.x;
|
|
293
|
+
gestureState.y0 = event.y;
|
|
290
294
|
gestureState.dx = 0;
|
|
291
295
|
gestureState.dy = 0;
|
|
292
296
|
lastMoveTime = now();
|
|
293
|
-
fire('onPanResponderGrant',
|
|
297
|
+
fire('onPanResponderGrant', event);
|
|
294
298
|
},
|
|
295
|
-
onResponderMove(
|
|
299
|
+
onResponderMove(event) {
|
|
296
300
|
if (!granted) return;
|
|
297
|
-
track(
|
|
298
|
-
fire('onPanResponderMove',
|
|
301
|
+
track(event);
|
|
302
|
+
fire('onPanResponderMove', event);
|
|
299
303
|
},
|
|
300
|
-
onResponderRelease(
|
|
304
|
+
onResponderRelease(event) {
|
|
301
305
|
if (!granted) return;
|
|
302
306
|
// Another finger still down: its touch slot keeps the responder, so the gesture continues (the
|
|
303
307
|
// raw onTouchEnd above already reported the End).
|
|
304
308
|
if (gestureState.numberActiveTouches > 0) return;
|
|
305
|
-
finish(
|
|
309
|
+
finish(event, 'onPanResponderRelease');
|
|
306
310
|
},
|
|
307
|
-
onResponderTerminate(
|
|
311
|
+
onResponderTerminate(event) {
|
|
308
312
|
if (!granted) return;
|
|
309
313
|
gestureState.numberActiveTouches = 0;
|
|
310
|
-
finish(
|
|
314
|
+
finish(event, 'onPanResponderTerminate');
|
|
311
315
|
},
|
|
312
|
-
onResponderReject(
|
|
313
|
-
fire('onPanResponderReject',
|
|
316
|
+
onResponderReject(event) {
|
|
317
|
+
fire('onPanResponderReject', event);
|
|
314
318
|
},
|
|
315
319
|
};
|
|
316
320
|
|
|
317
321
|
// Absent queries must not appear as props at all (an undefined on* prop is skipped by the host
|
|
318
322
|
// config anyway, but a clean bag is easier to reason about and to spread).
|
|
319
|
-
for (const
|
|
320
|
-
if (panHandlers[
|
|
323
|
+
for (const key of Object.keys(panHandlers)) {
|
|
324
|
+
if (panHandlers[key] === undefined) delete panHandlers[key];
|
|
321
325
|
}
|
|
322
326
|
|
|
323
327
|
return {panHandlers};
|
|
@@ -38,14 +38,8 @@ import {Pressable as HostPressable} from './components.js';
|
|
|
38
38
|
* @returns {*} A host <Pressable> element.
|
|
39
39
|
*/
|
|
40
40
|
export const Pressable = forwardRef(function Pressable(props = {}, ref) {
|
|
41
|
-
const {
|
|
42
|
-
|
|
43
|
-
onPress,
|
|
44
|
-
onLongPress,
|
|
45
|
-
onPressIn,
|
|
46
|
-
onPressOut,
|
|
47
|
-
...rest
|
|
48
|
-
} = props;
|
|
41
|
+
const {disabled, onPress, onLongPress, onPressIn, onPressOut, ...rest} =
|
|
42
|
+
props;
|
|
49
43
|
|
|
50
44
|
return createElement(HostPressable, {
|
|
51
45
|
...rest,
|
|
@@ -33,9 +33,7 @@
|
|
|
33
33
|
// stays mounted. Size `sections x (1 + rows) x nodes-per-row` against ERUI_MAX_NODES before writing
|
|
34
34
|
// the screen.
|
|
35
35
|
//
|
|
36
|
-
//
|
|
37
|
-
// and a section expands to a header AND a variable number of rows. It is a Flow A / simulator
|
|
38
|
-
// component until that lands; the AOT says so by name rather than "unknown element".
|
|
36
|
+
// Flow B builds the same tree, unrolling the sections at build time (aot/compiler/elements/section-list.mts).
|
|
39
37
|
import {createElement} from 'react';
|
|
40
38
|
import {ScrollView} from './components.js';
|
|
41
39
|
import {pushKeyedChild} from './list-child.js';
|
|
@@ -91,12 +89,12 @@ export function SectionList(props = {}) {
|
|
|
91
89
|
|
|
92
90
|
const children = [];
|
|
93
91
|
if (Array.isArray(sections)) {
|
|
94
|
-
for (let
|
|
95
|
-
const section = sections[
|
|
92
|
+
for (let sectionIndex = 0; sectionIndex < sections.length; sectionIndex++) {
|
|
93
|
+
const section = sections[sectionIndex];
|
|
96
94
|
if (section === null || typeof section !== 'object') continue;
|
|
97
95
|
const sectionKey =
|
|
98
96
|
section.key === null || section.key === undefined
|
|
99
|
-
? String(
|
|
97
|
+
? String(sectionIndex)
|
|
100
98
|
: String(section.key);
|
|
101
99
|
|
|
102
100
|
if (typeof renderSectionHeader === 'function')
|
|
@@ -120,11 +118,11 @@ export function SectionList(props = {}) {
|
|
|
120
118
|
const row = rowRenderer({item, index, section});
|
|
121
119
|
// Built lazily, so keyExtractor never runs for a row that rendered nothing or for a raw
|
|
122
120
|
// string — see pushKeyedChild.
|
|
123
|
-
pushKeyedChild(children, row,
|
|
121
|
+
pushKeyedChild(children, row, element => {
|
|
124
122
|
const key = rowKey
|
|
125
123
|
? String(rowKey(item, index))
|
|
126
|
-
:
|
|
127
|
-
?
|
|
124
|
+
: element.key !== null && element.key !== undefined
|
|
125
|
+
? element.key
|
|
128
126
|
: String(index);
|
|
129
127
|
return `${sectionKey}:${key}`;
|
|
130
128
|
});
|
|
@@ -24,9 +24,10 @@ export const StyleSheet = {
|
|
|
24
24
|
flatten(style) {
|
|
25
25
|
if (!style) return {};
|
|
26
26
|
if (Array.isArray(style)) {
|
|
27
|
-
const
|
|
28
|
-
for (const
|
|
29
|
-
|
|
27
|
+
const flattened = {};
|
|
28
|
+
for (const entry of style)
|
|
29
|
+
Object.assign(flattened, StyleSheet.flatten(entry));
|
|
30
|
+
return flattened;
|
|
30
31
|
}
|
|
31
32
|
return style;
|
|
32
33
|
},
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
// <Pressable style={[styles.tile, {opacity: dim}]} onPressIn={…} onPressOut={…}>…</Pressable>
|
|
23
23
|
//
|
|
24
24
|
// The fade is a native-driver animation, not a re-render: the two press handlers hand the engine a
|
|
25
|
-
// target opacity and a duration, and it runs the ramp in C (
|
|
25
|
+
// target opacity and a duration, and it runs the ramp in C (er_animation_value_*). Nothing re-enters JS per
|
|
26
26
|
// frame, and the subtree React just built is not touched at all.
|
|
27
27
|
//
|
|
28
28
|
// Worth knowing before wrapping a whole screen in one: an opacity below 1 makes the Pressable an
|
|
@@ -45,6 +45,7 @@ import {flattenStyleObj} from '../props.js';
|
|
|
45
45
|
// RN's own numbers (Libraries/Components/Touchable/TouchableOpacity.js): the dim lands on touch-down
|
|
46
46
|
// with no ramp at all and fades back over a quarter second once the finger lifts.
|
|
47
47
|
const DEFAULT_ACTIVE_OPACITY = 0.2;
|
|
48
|
+
const FULLY_OPAQUE = 1;
|
|
48
49
|
const DIM_MS = 0;
|
|
49
50
|
const RESTORE_MS = 250;
|
|
50
51
|
|
|
@@ -52,8 +53,8 @@ let warnedAnimatedOpacity = false;
|
|
|
52
53
|
|
|
53
54
|
/** The opacity the touchable rests at — whatever its style asks for, fully opaque if it asks nothing. */
|
|
54
55
|
function restingOpacity(style) {
|
|
55
|
-
const
|
|
56
|
-
if (
|
|
56
|
+
const opacity = flattenStyleObj(style).opacity;
|
|
57
|
+
if (opacity && opacity.__animated) {
|
|
57
58
|
if (!warnedAnimatedOpacity) {
|
|
58
59
|
warnedAnimatedOpacity = true;
|
|
59
60
|
console.warn(
|
|
@@ -62,14 +63,18 @@ function restingOpacity(style) {
|
|
|
62
63
|
'onPressIn/onPressOut driving an Animated.Value.',
|
|
63
64
|
);
|
|
64
65
|
}
|
|
65
|
-
return
|
|
66
|
+
return FULLY_OPAQUE;
|
|
66
67
|
}
|
|
67
|
-
return typeof
|
|
68
|
+
return typeof opacity === 'number' ? opacity : FULLY_OPAQUE;
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
/** Runs `value` to `
|
|
71
|
-
function fadeTo(value,
|
|
72
|
-
timing(value, {
|
|
71
|
+
/** Runs `value` to `target` over `durationMs` on the native driver (a 0 ms ramp snaps, without taking a slot). */
|
|
72
|
+
function fadeTo(value, target, durationMs) {
|
|
73
|
+
timing(value, {
|
|
74
|
+
toValue: target,
|
|
75
|
+
duration: durationMs,
|
|
76
|
+
easing: Easing.quadInOut,
|
|
77
|
+
}).start();
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
/**
|
|
@@ -182,7 +182,7 @@ export interface ViewStyle {
|
|
|
182
182
|
transform?: TransformStyle[];
|
|
183
183
|
transformOrigin?: TransformOrigin;
|
|
184
184
|
|
|
185
|
-
// Shadow. Rendered only in a build with shadows enabled (ERUI_SHADOWS)
|
|
185
|
+
// Shadow. Rendered only in a build with shadows enabled (ERUI_SHADOWS), by `shadowOpacity` above 0 or an `elevation`.
|
|
186
186
|
shadowColor?: string;
|
|
187
187
|
shadowOffset?: ShadowOffset;
|
|
188
188
|
shadowOpacity?: number;
|
|
@@ -434,8 +434,8 @@ export interface FlatListProps<T = unknown> {
|
|
|
434
434
|
/**
|
|
435
435
|
* `<SectionList>` is a thin `<ScrollView>` alias like `<FlatList>` — no virtualization, no sticky
|
|
436
436
|
* headers, and every header, row and footer mounts as a real engine node and stays mounted. Header,
|
|
437
|
-
* rows and footer are flat siblings, exactly as in RN. Flow
|
|
438
|
-
*
|
|
437
|
+
* rows and footer are flat siblings, exactly as in RN. Flow B unrolls the sections at build time, so
|
|
438
|
+
* write them out in place or use a constant array.
|
|
439
439
|
*/
|
|
440
440
|
export interface SectionListProps<ItemT = unknown, SectionT = DefaultSectionT> {
|
|
441
441
|
sections?: ReadonlyArray<SectionListData<ItemT, SectionT>>;
|
|
@@ -670,9 +670,9 @@ export interface SvgPaintProps {
|
|
|
670
670
|
strokeMiterlimit?: SvgNumber;
|
|
671
671
|
fillRule?: 'nonzero' | 'evenodd';
|
|
672
672
|
/** Fills with a gradient instead of the solid `fill`. */
|
|
673
|
-
|
|
673
|
+
fillGradient?: VectorGradient;
|
|
674
674
|
/** Strokes with a gradient instead of the solid `stroke`. */
|
|
675
|
-
|
|
675
|
+
strokeGradient?: VectorGradient;
|
|
676
676
|
}
|
|
677
677
|
|
|
678
678
|
/** A `.svg` import: the build bakes it to a vector op-tape, or to a raster asset when it uses features the
|
|
@@ -788,6 +788,23 @@ export const Platform: {
|
|
|
788
788
|
select<T>(specifics: Record<string, T>): T | undefined;
|
|
789
789
|
};
|
|
790
790
|
|
|
791
|
+
// --- Dimensions ------------------------------------------------------------
|
|
792
|
+
/** The panel's size in pixels. `scale` and `fontScale` are always 1. */
|
|
793
|
+
export interface ScaledSize {
|
|
794
|
+
width: number;
|
|
795
|
+
height: number;
|
|
796
|
+
scale: number;
|
|
797
|
+
fontScale: number;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
export const Dimensions: {
|
|
801
|
+
/** The panel's size. 'window' and 'screen' are the same on a panel. */
|
|
802
|
+
get(dimension: 'window' | 'screen'): ScaledSize;
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
/** The panel's size. It is fixed while the app runs. */
|
|
806
|
+
export function useWindowDimensions(): ScaledSize;
|
|
807
|
+
|
|
791
808
|
// --- AppRegistry -----------------------------------------------------------
|
|
792
809
|
export const AppRegistry: {
|
|
793
810
|
registerComponent(
|
|
@@ -929,6 +946,69 @@ export function usePersistentState<S>(
|
|
|
929
946
|
): [S, (value: S | ((prev: S) => S)) => void];
|
|
930
947
|
|
|
931
948
|
export function useHostValue(initial: number): number;
|
|
949
|
+
|
|
950
|
+
/** A whole number. A native method's `Int` is an int in C, where a `number` is a float. */
|
|
951
|
+
export type Int = number;
|
|
952
|
+
|
|
953
|
+
/**
|
|
954
|
+
* A whole number that may be past an Int's range: a native method's `Int64` is an int64_t in C. In JS it is a number,
|
|
955
|
+
* so it is exact up to 2^53.
|
|
956
|
+
*/
|
|
957
|
+
export type Int64 = number;
|
|
958
|
+
|
|
959
|
+
/** An optional native module, as nativeModule.optional returns it. */
|
|
960
|
+
export type OptionalNativeModule<T> = T & {
|
|
961
|
+
/** Whether the firmware has every method and event of the module. Set at load, and it never changes. */
|
|
962
|
+
readonly available: boolean;
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
/**
|
|
966
|
+
* A module the firmware provides in C, declared at module level by an interface of its methods, which take and
|
|
967
|
+
* return Int, Int64, number, boolean, string and records of them:
|
|
968
|
+
* `const Sensors = nativeModule<Sensors>('sensors', 1)`. Its events are the interface's `events`:
|
|
969
|
+
* `events: {reading(celsius: number): void}`.
|
|
970
|
+
*/
|
|
971
|
+
export const nativeModule: {
|
|
972
|
+
<T>(name: string, version: number): T;
|
|
973
|
+
/**
|
|
974
|
+
* A module only some boards have: `const Wifi = nativeModule.optional<Wifi>('wifi', 1)`. A package that uses it
|
|
975
|
+
* loads without it, and `Wifi.available` says whether it is there. Calling a method of a module that isn't stops
|
|
976
|
+
* the app; its events never arrive.
|
|
977
|
+
*/
|
|
978
|
+
optional<T>(name: string, version: number): OptionalNativeModule<T>;
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
/** The events a native module's interface declares. */
|
|
982
|
+
export type NativeEvents<T> = T extends {events: infer E} ? E : {};
|
|
983
|
+
|
|
984
|
+
/** The values an event is posted with. */
|
|
985
|
+
export type NativeEventValues<
|
|
986
|
+
T,
|
|
987
|
+
K extends keyof NativeEvents<T>,
|
|
988
|
+
> = NativeEvents<T>[K] extends (...values: infer V) => void ? V : never;
|
|
989
|
+
|
|
990
|
+
/**
|
|
991
|
+
* Runs `handler` with an event's values each time the firmware posts it, while the component is mounted:
|
|
992
|
+
* `useNativeEvent(Sensors, 'reading', celsius => setTemperature(celsius))`.
|
|
993
|
+
*/
|
|
994
|
+
export function useNativeEvent<T, K extends keyof NativeEvents<T> & string>(
|
|
995
|
+
module: T,
|
|
996
|
+
event: K,
|
|
997
|
+
handler: (...values: NativeEventValues<T, K>) => void,
|
|
998
|
+
): void;
|
|
999
|
+
|
|
1000
|
+
/** Posts one of a mocked module's events, as the firmware would. false while one of the mock's methods runs. */
|
|
1001
|
+
export type NativeEmit<T> = <K extends keyof NativeEvents<T> & string>(
|
|
1002
|
+
event: K,
|
|
1003
|
+
...values: NativeEventValues<T, K>
|
|
1004
|
+
) => boolean;
|
|
1005
|
+
|
|
1006
|
+
/**
|
|
1007
|
+
* A native module's mock for the simulators, the default export of `<name>.mock.ts`: its methods, or a function
|
|
1008
|
+
* that is given `emit` and returns them.
|
|
1009
|
+
*/
|
|
1010
|
+
export type NativeMock<T> =
|
|
1011
|
+
Omit<T, 'events'> | ((emit: NativeEmit<T>) => Omit<T, 'events'>);
|
|
932
1012
|
export const Easing: {readonly [K in EasingName]: K} & {
|
|
933
1013
|
bezier(x1: number, y1: number, x2: number, y2: number): BezierEasing;
|
|
934
1014
|
};
|
|
@@ -1058,8 +1138,8 @@ export interface VectorShape {
|
|
|
1058
1138
|
cap?: 'butt' | 'round' | 'square';
|
|
1059
1139
|
join?: 'miter' | 'round' | 'bevel';
|
|
1060
1140
|
fillRule?: 'nonzero' | 'evenodd';
|
|
1061
|
-
|
|
1062
|
-
|
|
1141
|
+
fillGradient?: VectorGradient;
|
|
1142
|
+
strokeGradient?: VectorGradient;
|
|
1063
1143
|
}
|
|
1064
1144
|
|
|
1065
1145
|
/**
|
|
@@ -1103,7 +1183,7 @@ export interface KeyboardConfig {
|
|
|
1103
1183
|
rowHeight?: number;
|
|
1104
1184
|
keyGap?: number;
|
|
1105
1185
|
keyRadius?: number;
|
|
1106
|
-
|
|
1186
|
+
gridColumns?: number;
|
|
1107
1187
|
layers?: KeyboardKey[][][];
|
|
1108
1188
|
}
|
|
1109
1189
|
|
|
@@ -49,10 +49,12 @@ export {SectionList} from './SectionList.js';
|
|
|
49
49
|
export {updateVector, updateText, setKeyboardConfig} from './imperative.js';
|
|
50
50
|
export {StyleSheet} from './StyleSheet.js';
|
|
51
51
|
export {Platform} from './Platform.js';
|
|
52
|
+
export {Dimensions, useWindowDimensions} from './Dimensions.js';
|
|
52
53
|
export {AppRegistry} from './AppRegistry.js';
|
|
53
54
|
export {Animated, useAnimatedValue} from './Animated.js';
|
|
54
55
|
export {PanResponder} from './PanResponder.js';
|
|
55
56
|
export {usePersistentState} from './usePersistentState.js';
|
|
56
57
|
export {useHostValue} from './useHostValue.js';
|
|
58
|
+
export {nativeModule, useNativeEvent} from './nativeModule.js';
|
|
57
59
|
export {Easing} from './Easing.js';
|
|
58
60
|
export {LayoutAnimation} from './LayoutAnimation.js';
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
// Node (see __tests__/layout-animation.unit.test.js). LayoutAnimation.js wires configureNext to the
|
|
19
19
|
// bridge using these.
|
|
20
20
|
|
|
21
|
+
/** Duration when a config gives none, as in RN. */
|
|
22
|
+
export const DEFAULT_DURATION_MS = 300;
|
|
23
|
+
|
|
21
24
|
/** RN-compatible animation type tokens. */
|
|
22
25
|
export const Types = {
|
|
23
26
|
spring: 'spring',
|
|
@@ -58,10 +61,13 @@ function easingForType(type) {
|
|
|
58
61
|
* are accepted for parity but not separately animated.
|
|
59
62
|
*/
|
|
60
63
|
export function toEngineConfig(config) {
|
|
61
|
-
const
|
|
62
|
-
const duration =
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
const options = config || {};
|
|
65
|
+
const duration =
|
|
66
|
+
typeof options.duration === 'number'
|
|
67
|
+
? options.duration
|
|
68
|
+
: DEFAULT_DURATION_MS;
|
|
69
|
+
const update = options.update || {};
|
|
70
|
+
const type = update.type || options.type || Types.easeInEaseOut;
|
|
65
71
|
if (type === Types.spring) {
|
|
66
72
|
return {type: 'spring', duration};
|
|
67
73
|
}
|
|
@@ -28,7 +28,7 @@ export const isElement = node =>
|
|
|
28
28
|
node !== null && typeof node === 'object' && node.$$typeof !== undefined;
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
* Appends one rendered row to `
|
|
31
|
+
* Appends one rendered row to `children`, keyed, or drops it if it rendered nothing.
|
|
32
32
|
*
|
|
33
33
|
* Callers own the key because they know what makes one unique (a SectionList's rows are siblings
|
|
34
34
|
* across sections, a FlatList's are not). A row that is not an element goes in untouched: there is no
|
|
@@ -39,16 +39,16 @@ export const isElement = node =>
|
|
|
39
39
|
* nothing, or for a raw string that cannot be cloned, is both wasted work on the commit path and a
|
|
40
40
|
* side effect the app never asked for. Passing the key by value invites exactly that, and did.
|
|
41
41
|
*
|
|
42
|
-
* @param {Array}
|
|
42
|
+
* @param {Array} children The child list being built.
|
|
43
43
|
* @param {*} node Whatever the render callback returned.
|
|
44
44
|
* @param {(element: object) => string} keyFor Builds the React key, given the keyable element.
|
|
45
45
|
*/
|
|
46
|
-
export function pushKeyedChild(
|
|
46
|
+
export function pushKeyedChild(children, node, keyFor) {
|
|
47
47
|
if (rendersNothing(node)) return;
|
|
48
48
|
if (!isElement(node)) {
|
|
49
|
-
|
|
49
|
+
children.push(node);
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
const key = keyFor(node);
|
|
53
|
-
|
|
53
|
+
children.push(node.key === key ? node : cloneElement(node, {key}));
|
|
54
54
|
}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
// The named colors every path accepts, as ARGB8888 with their CSS values. Keys are lowercase; callers
|
|
18
|
-
// lowercase the name first. The bridge's
|
|
18
|
+
// lowercase the name first. The bridge's k_named_colors table (native_ui_bridge.c) must list the same entries.
|
|
19
19
|
// No prototype, so `name in NAMED_COLORS` never finds `toString` and friends.
|
|
20
20
|
|
|
21
21
|
/** @type {Readonly<Record<string, number>>} */
|