embedded-react 0.21.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/README.md +2 -2
  2. package/aot/compile.mjs +1 -1
  3. package/aot/compiler/alerts.mjs +604 -0
  4. package/aot/compiler/check.mjs +1 -1
  5. package/aot/compiler/collect.mjs +1 -1
  6. package/aot/compiler/elements/button.mjs +3 -3
  7. package/aot/compiler/elements/image-background.mjs +1 -1
  8. package/aot/compiler/elements/props.mjs +10 -6
  9. package/aot/compiler/elements/section-list.mjs +1 -1
  10. package/aot/compiler/expressions.mjs +29 -2
  11. package/aot/compiler/handlers.mjs +73 -16
  12. package/aot/compiler/keyboard-dismiss.mjs +99 -0
  13. package/aot/compiler/keyboard.mjs +1 -1
  14. package/aot/compiler/lower.mjs +12 -0
  15. package/aot/compiler/nodes.mjs +17 -9
  16. package/aot/compiler/out.mjs +4 -0
  17. package/aot/compiler/package/codegen.mjs +36 -2
  18. package/aot/compiler/package/format.mjs +5 -3
  19. package/aot/compiler/package/lower.mjs +53 -19
  20. package/aot/compiler/scroll-to.mjs +112 -0
  21. package/aot/compiler/style-text.mjs +2 -2
  22. package/aot/compiler/svg.mjs +6 -3
  23. package/aot/compiler/updaters.mjs +1 -0
  24. package/aot/style-map.mjs +44 -1
  25. package/assets/bake-font.mjs +187 -244
  26. package/assets/bake-image.mjs +47 -71
  27. package/assets/bake-svg.mjs +465 -533
  28. package/assets/build-builtin-font.mjs +14 -27
  29. package/assets/emit-c.mjs +124 -204
  30. package/assets/emit-container.mjs +129 -197
  31. package/assets/emit-pack.mjs +92 -136
  32. package/assets/font-config.mjs +19 -27
  33. package/assets/font-sizes.mjs +432 -507
  34. package/assets/glyph-coverage.mjs +170 -214
  35. package/assets/index.mjs +52 -97
  36. package/assets/rasterize.mjs +173 -194
  37. package/assets/svg-loader.mjs +42 -48
  38. package/build.mjs +84 -101
  39. package/cli.mjs +482 -621
  40. package/compile-bin.mjs +24 -36
  41. package/flash.mjs +297 -401
  42. package/hotreload/dev-device.mjs +229 -270
  43. package/hotreload/pack-app.mjs +118 -159
  44. package/hotreload/pack-split.mjs +144 -200
  45. package/hotreload/package-transfer.mjs +128 -131
  46. package/hotreload/protocol.mjs +118 -118
  47. package/hotreload/uploader.mjs +132 -159
  48. package/hotreload/watch-tree.mjs +56 -65
  49. package/pack-container.mjs +93 -123
  50. package/package.json +19 -16
  51. package/persist-transform.mjs +89 -105
  52. package/qjsc-wasm.mjs +47 -72
  53. package/sim/embedded-react.wasm +0 -0
  54. package/sim/index.html +1 -1
  55. package/sim-server.mjs +260 -354
  56. package/src/embedded-react/Alert.mjs +112 -0
  57. package/src/embedded-react/Animated.mjs +412 -0
  58. package/src/embedded-react/{AppRegistry.js → AppRegistry.mjs} +26 -25
  59. package/src/embedded-react/{Button.js → Button.mjs} +29 -53
  60. package/src/embedded-react/{Dimensions.js → Dimensions.mjs} +12 -17
  61. package/src/embedded-react/Easing.mjs +34 -0
  62. package/src/embedded-react/{FlatList.js → FlatList.mjs} +25 -42
  63. package/src/embedded-react/{ImageBackground.js → ImageBackground.mjs} +11 -22
  64. package/src/embedded-react/Keyboard.mjs +82 -0
  65. package/src/embedded-react/{LayoutAnimation.js → LayoutAnimation.mjs} +17 -28
  66. package/src/embedded-react/PanResponder.mjs +256 -0
  67. package/src/embedded-react/{Platform.js → Platform.mjs} +8 -9
  68. package/src/embedded-react/{Pressable.js → Pressable.mjs} +12 -25
  69. package/src/embedded-react/SectionList.mjs +103 -0
  70. package/src/embedded-react/{StyleSheet.js → StyleSheet.mjs} +16 -20
  71. package/src/embedded-react/{TouchableOpacity.js → TouchableOpacity.mjs} +47 -83
  72. package/src/embedded-react/background-image.mjs +321 -0
  73. package/src/embedded-react/{components.js → components.mjs} +1 -3
  74. package/src/embedded-react/{imperative.js → imperative.mjs} +27 -38
  75. package/src/embedded-react/index.d.ts +155 -2
  76. package/src/embedded-react/index.js +26 -19
  77. package/src/embedded-react/layout-anim-config.mjs +85 -0
  78. package/src/embedded-react/{list-child.js → list-child.mjs} +11 -20
  79. package/src/embedded-react/{named-colors.js → named-colors.mjs} +2 -6
  80. package/src/embedded-react/nativeModule.mjs +371 -0
  81. package/src/embedded-react/split-style.mjs +57 -0
  82. package/src/embedded-react/svg-ops.mjs +1075 -0
  83. package/src/embedded-react/{useHostValue.js → useHostValue.mjs} +2 -4
  84. package/src/embedded-react/{usePersistentState.js → usePersistentState.mjs} +34 -38
  85. package/src/embedded-react/{warn-props.js → warn-props.mjs} +32 -39
  86. package/src/host-config.mjs +512 -0
  87. package/src/{native-ui.js → native-ui.mjs} +1 -8
  88. package/src/props.mjs +341 -0
  89. package/src/{renderer.js → renderer.mjs} +30 -44
  90. package/src/embedded-react/Animated.js +0 -440
  91. package/src/embedded-react/Easing.js +0 -39
  92. package/src/embedded-react/PanResponder.js +0 -330
  93. package/src/embedded-react/SectionList.js +0 -146
  94. package/src/embedded-react/layout-anim-config.js +0 -101
  95. package/src/embedded-react/nativeModule.js +0 -462
  96. package/src/embedded-react/split-style.js +0 -58
  97. package/src/embedded-react/svg-ops.js +0 -1295
  98. package/src/host-config.js +0 -548
  99. package/src/props.js +0 -306
@@ -1,330 +0,0 @@
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
- // PanResponder — the React Native analog for drags, swipes and flings.
18
- //
19
- // A raw `onTouchMove` carries an absolute point and nothing else, so every drag ends up re-deriving the
20
- // same three things by hand: where the finger started, how far it has travelled, and how fast it is
21
- // going. This module does that once. `create(config)` returns an object whose `panHandlers` you spread
22
- // onto any component; each callback receives `(event, gestureState)` exactly as in RN:
23
- //
24
- // const pan = useRef(PanResponder.create({
25
- // onStartShouldSetPanResponder: () => true,
26
- // onPanResponderMove: (event, gesture) => setX(gesture.dx),
27
- // onPanResponderRelease: (event, gesture) => (gesture.vx > 0.5 ? next() : settle()),
28
- // })).current;
29
- //
30
- // <View {...pan.panHandlers} />
31
- //
32
- // The gesture rides the ENGINE's responder system (issue #115 shipped a JS-only precursor over the raw
33
- // onTouch* events; this is the rebase). `panHandlers` is a bag of RN View responder props — the
34
- // should-set predicates become native negotiation QUERIES (the engine calls them synchronously during
35
- // hit-testing and the boolean answer decides who owns the gesture), and grant/move/release/terminate
36
- // arrive as native responder events. That buys real arbitration:
37
- //
38
- // • A granted PanResponder OWNS the gesture: a ScrollView ancestor no longer auto-scrolls under the
39
- // pan (auto-scroll only claims a gesture nobody owns), and it takes a slop-claimed scroll BACK the
40
- // moment `onMoveShouldSetPanResponder` answers true.
41
- // • Negotiation covers the subtree: the engine asks every node on the hit chain, capture phase
42
- // root→leaf first (`*Capture` config keys), then bubble leaf→root — so a responder on a wrapper
43
- // claims touches that land on its children, and an outer responder can pre-empt an inner one.
44
- // • Losing a negotiation is reported (`onPanResponderReject`), and a challenger asking for the
45
- // gesture is refusable (`onPanResponderTerminationRequest` — return false to keep it).
46
- // • `onPanResponderTerminate` is the undo hook for whatever `onPanResponderGrant` began: the engine
47
- // fires it when the touch sequence is cancelled, when a fresh touch-down arrives on a finger whose
48
- // previous sequence never ended, or when this responder yields to a challenger.
49
- //
50
- // Remaining limits: `onShouldBlockNativeResponder` is Android-specific and stays unsupported (holding
51
- // the responder already blocks the ScrollView; the built-in adjustable-Arc drag deliberately wins over
52
- // JS claimants). And the engine events carry no finger id, so multiple fingers fold into ONE gesture —
53
- // `numberActiveTouches` counts them, extra fingers fire `onPanResponderStart`/`End` (Flow A only; see
54
- // below), and the last one to lift releases; two independent single-finger gestures need two
55
- // responders on disjoint subtrees.
56
- //
57
- // Flow B compiles the same code: the AOT recognises `useRef(PanResponder.create({…})).current`
58
- // and the `{...pan.panHandlers}` spread as a special form and lowers them onto the SAME C responder
59
- // system this module rides — so no part of this file ships to a device that has no JS. Only
60
- // `onPanResponderStart`/`End`, which exist here to fold extra fingers into one gesture, are Flow A only;
61
- // the AOT names them rather than dropping them.
62
-
63
- /** Per-instance gesture id, so two responders on screen at once are told apart. */
64
- let s_nextStateID = 1;
65
-
66
- /** Unsupported config keys already warned about (each unique key warns once per process). */
67
- const s_warnedKeys = new Set();
68
-
69
- /** Config keys this module acts on. Everything else is either RN-Android-specific or a typo. */
70
- const SUPPORTED = [
71
- 'onStartShouldSetPanResponder',
72
- 'onStartShouldSetPanResponderCapture',
73
- 'onMoveShouldSetPanResponder',
74
- 'onMoveShouldSetPanResponderCapture',
75
- 'onPanResponderGrant',
76
- 'onPanResponderMove',
77
- 'onPanResponderRelease',
78
- 'onPanResponderTerminate',
79
- 'onPanResponderTerminationRequest',
80
- 'onPanResponderReject',
81
- 'onPanResponderStart',
82
- 'onPanResponderEnd',
83
- ];
84
-
85
- /**
86
- * The engine's monotonic millisecond clock, used for velocity. `performance.now()` is installed by the
87
- * QuickJS runtime on every context (it is React's scheduler clock) and exists in the simulator and in
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 an elapsed time of 0 is normal and leaves velocity
90
- * untouched.
91
- */
92
- const now = () =>
93
- typeof performance !== 'undefined' && typeof performance.now === 'function'
94
- ? performance.now()
95
- : 0;
96
-
97
- /**
98
- * Coerces whatever was passed to a usable config object. A default parameter only covers `undefined`,
99
- * so `create(null)` would throw on Object.keys, and a primitive would enumerate its INDICES as unknown
100
- * keys ("ignores 0, 1, 2, 3"). Neither is a useful failure for a public API on a device.
101
- *
102
- * @param {*} config Whatever the caller passed.
103
- * @returns {object} The config when it is a usable object; an empty one otherwise.
104
- */
105
- function asConfig(config) {
106
- return config !== null && typeof config === 'object' ? config : {};
107
- }
108
-
109
- /** Warns ONCE PER KEY about config keys this module does not act on. */
110
- function warnUnsupportedConfig(config) {
111
- const names = Object.keys(config).filter(
112
- key => !SUPPORTED.includes(key) && !s_warnedKeys.has(key),
113
- );
114
- if (names.length === 0) return;
115
- for (const key of names) s_warnedKeys.add(key);
116
- console.warn(
117
- `embedded-react: PanResponder ignores ${names.join(', ')} — ` +
118
- `supported: ${SUPPORTED.join(', ')}.`,
119
- );
120
- }
121
-
122
- /**
123
- * Clears the travel/velocity fields between gestures. `numberActiveTouches` is deliberately left alone:
124
- * it counts fingers on the panel, which outlives the gesture when a second finger is still down.
125
- *
126
- * @param {object} gestureState The gesture state to reset in place.
127
- */
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;
137
- }
138
-
139
- /**
140
- * Builds a gesture recogniser. Call it ONCE per component and keep the result in a ref — the returned
141
- * handlers close over one mutable gestureState, so re-creating it per render throws the drag away.
142
- *
143
- * @param {object} [userConfig] RN-shaped callbacks; see SUPPORTED. Every one is optional, and a
144
- * non-object (null, a primitive) is treated as an empty config.
145
- * @returns {{panHandlers: object}} `panHandlers` to spread onto a component.
146
- */
147
- export function create(userConfig = {}) {
148
- const config = asConfig(userConfig);
149
- warnUnsupportedConfig(config);
150
-
151
- // The single mutable object handed to every callback — same identity for the responder's lifetime,
152
- // as in RN, so a handler may stash it but must not expect a snapshot.
153
- const gestureState = {
154
- /** Identifies this responder; stable for its lifetime. */
155
- stateID: s_nextStateID++,
156
- /** Latest touch point. */
157
- moveX: 0,
158
- moveY: 0,
159
- /** Where the gesture was granted — the anchor dx/dy are measured from. */
160
- x0: 0,
161
- y0: 0,
162
- /** Travel since the grant, in pixels. */
163
- dx: 0,
164
- dy: 0,
165
- /** Velocity in pixels per millisecond. */
166
- vx: 0,
167
- vy: 0,
168
- /** Fingers currently on the panel (within this responder's subtree). */
169
- numberActiveTouches: 0,
170
- };
171
-
172
- let granted = false;
173
- let lastMoveTime = 0;
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.
178
- let baseDx = 0;
179
- let baseDy = 0;
180
-
181
- const fire = (name, event) => {
182
- if (typeof config[name] === 'function') config[name](event, gestureState);
183
- };
184
-
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;
191
- };
192
-
193
- /** A move: travel, plus a fresh velocity reading over the time since the last one. */
194
- const track = event => {
195
- const time = now();
196
- const elapsed = time - lastMoveTime;
197
- const previousDx = gestureState.dx;
198
- const previousDy = gestureState.dy;
199
-
200
- advance(event);
201
-
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;
208
- }
209
- lastMoveTime = time;
210
- };
211
-
212
- /** Wraps a should-set predicate as an engine query: track the point, ask, absent means "no" (as in RN). */
213
- const query = name =>
214
- typeof config[name] === 'function'
215
- ? event => {
216
- if (!granted) advance(event);
217
- return config[name](event, gestureState) === true;
218
- }
219
- : undefined;
220
-
221
- /** Ends the gesture: reports it if this responder owned it, then clears the state for the next one. */
222
- const finish = (event, callback) => {
223
- const wasGranted = granted;
224
- granted = false;
225
- // Fold the final point into the travel so `dx` is the gesture's true total even when the finger
226
- // lifted without a final move — but leave vx/vy at the last MOVE's reading. A fling ends with the
227
- // finger resting for a frame or two, and re-measuring across that would report zero and throw the
228
- // throw away.
229
- advance(event);
230
- if (wasGranted) fire(callback, event);
231
- resetGestureState(gestureState);
232
- baseDx = 0;
233
- baseDy = 0;
234
- };
235
-
236
- const panHandlers = {
237
- // --- Raw touch bookkeeping (bubbles per finger): finger count + Start/End for extra fingers ---
238
- onTouchStart(event) {
239
- gestureState.numberActiveTouches += 1;
240
- // A later finger joins the gesture in flight (the engine events carry no finger id, so
241
- // independent tracking is impossible). Its own touch slot re-negotiates and re-grants this
242
- // node, and THAT grant fires onPanResponderStart — not this raw handler, which runs first.
243
- if (gestureState.numberActiveTouches > 1) return;
244
- resetGestureState(gestureState);
245
- baseDx = 0;
246
- baseDy = 0;
247
- gestureState.x0 = event.x;
248
- gestureState.y0 = event.y;
249
- gestureState.moveX = event.x;
250
- gestureState.moveY = event.y;
251
- lastMoveTime = now();
252
- },
253
- onTouchEnd(event) {
254
- if (gestureState.numberActiveTouches > 0)
255
- gestureState.numberActiveTouches -= 1;
256
- // A finger lifted but the gesture continues; the RELEASE for the last one arrives as a
257
- // responder event below.
258
- if (granted && gestureState.numberActiveTouches > 0)
259
- fire('onPanResponderEnd', event);
260
- },
261
- onTouchCancel() {
262
- gestureState.numberActiveTouches = 0;
263
- },
264
-
265
- // --- Negotiation queries (the engine calls these; returning true claims the gesture) ---
266
- onStartShouldSetResponder: query('onStartShouldSetPanResponder'),
267
- onStartShouldSetResponderCapture: query(
268
- 'onStartShouldSetPanResponderCapture',
269
- ),
270
- onMoveShouldSetResponder: query('onMoveShouldSetPanResponder'),
271
- onMoveShouldSetResponderCapture: query(
272
- 'onMoveShouldSetPanResponderCapture',
273
- ),
274
- onResponderTerminationRequest:
275
- typeof config.onPanResponderTerminationRequest === 'function'
276
- ? event =>
277
- config.onPanResponderTerminationRequest(event, gestureState) ===
278
- true
279
- : undefined, // absent → the engine's default: yield (RN's default too)
280
-
281
- // --- Responder lifecycle (native events; fire only on the node that owns the gesture) ---
282
- onResponderGrant(event) {
283
- if (granted) {
284
- // A second finger's touch slot granted the same node: one gesture, not two. RN calls this a
285
- // responder "start" for the extra touch.
286
- fire('onPanResponderStart', event);
287
- return;
288
- }
289
- granted = true;
290
- baseDx = event.dx;
291
- baseDy = event.dy;
292
- gestureState.x0 = event.x;
293
- gestureState.y0 = event.y;
294
- gestureState.dx = 0;
295
- gestureState.dy = 0;
296
- lastMoveTime = now();
297
- fire('onPanResponderGrant', event);
298
- },
299
- onResponderMove(event) {
300
- if (!granted) return;
301
- track(event);
302
- fire('onPanResponderMove', event);
303
- },
304
- onResponderRelease(event) {
305
- if (!granted) return;
306
- // Another finger still down: its touch slot keeps the responder, so the gesture continues (the
307
- // raw onTouchEnd above already reported the End).
308
- if (gestureState.numberActiveTouches > 0) return;
309
- finish(event, 'onPanResponderRelease');
310
- },
311
- onResponderTerminate(event) {
312
- if (!granted) return;
313
- gestureState.numberActiveTouches = 0;
314
- finish(event, 'onPanResponderTerminate');
315
- },
316
- onResponderReject(event) {
317
- fire('onPanResponderReject', event);
318
- },
319
- };
320
-
321
- // Absent queries must not appear as props at all (an undefined on* prop is skipped by the host
322
- // config anyway, but a clean bag is easier to reason about and to spread).
323
- for (const key of Object.keys(panHandlers)) {
324
- if (panHandlers[key] === undefined) delete panHandlers[key];
325
- }
326
-
327
- return {panHandlers};
328
- }
329
-
330
- export const PanResponder = {create};
@@ -1,146 +0,0 @@
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
- // SectionList — a thin API-compat wrapper over <ScrollView>, NOT a virtualized list. It is <FlatList>
18
- // with a header and a footer around each group:
19
- //
20
- // <SectionList sections={[{title: 'A', data: ['ant']}]}
21
- // renderSectionHeader={({section}) => <Header title={section.title} />}
22
- // renderItem={({item}) => <Row item={item} />} />
23
- // renders the same tree as
24
- // <ScrollView><Header title="A" /><Row item="ant" /></ScrollView>
25
- //
26
- // Header, rows and footer are FLAT SIBLINGS, as in RN — no wrapper node per section — so a section
27
- // costs exactly the nodes it draws. Nothing sticks: `stickySectionHeadersEnabled` needs a scroll
28
- // listener re-laying the header out every frame, which is the per-event JS cost Flow A can least
29
- // afford.
30
- //
31
- // Everything the FlatList section of the README says about the node budget applies here and then
32
- // some: a section adds its header and footer on top of its rows, and every one of them mounts and
33
- // stays mounted. Size `sections x (1 + rows) x nodes-per-row` against ERUI_MAX_NODES before writing
34
- // the screen.
35
- //
36
- // Flow B builds the same tree, unrolling the sections at build time (aot/compiler/elements/section-list.mts).
37
- import {createElement} from 'react';
38
- import {ScrollView} from './components.js';
39
- import {pushKeyedChild} from './list-child.js';
40
- import {createPropWarner, RN_PLATFORM_NO_OPS} from './warn-props.js';
41
-
42
- /** The props this honours. The rest are virtualization / platform knobs with no meaning on a panel. */
43
- const SUPPORTED = [
44
- 'sections',
45
- 'renderItem',
46
- 'renderSectionHeader',
47
- 'renderSectionFooter',
48
- 'keyExtractor',
49
- 'style',
50
- ];
51
-
52
- const warnUnsupportedProps = createPropWarner(
53
- 'SectionList',
54
- SUPPORTED,
55
- 'it is a thin <ScrollView> alias with no virtualization and no sticky headers. For separators, ' +
56
- 'list headers/footers or onEndReached, use <ScrollView> + .map directly.',
57
- RN_PLATFORM_NO_OPS,
58
- );
59
-
60
- /**
61
- * Renders `sections` into a <ScrollView>, each as an optional header, its rows, and an optional footer.
62
- *
63
- * Row keys are namespaced by section (`<section>:<row>`), because the rows of every section end up as
64
- * siblings of one another — an index or an id that is only unique WITHIN a section would collide.
65
- *
66
- * @param {object} [props] Missing / empty renders an empty scroller, like a missing `sections`.
67
- * @param {Array} [props.sections] Sections, each `{data, key?, renderItem?, keyExtractor?, ...}`.
68
- * Anything else on a section (RN's convention is `title`) is yours, and reaches the render callbacks.
69
- * @param {(info: {item: *, index: number, section: object}) => *} [props.renderItem] Row renderer.
70
- * A section's own `renderItem` wins for that section, as in RN.
71
- * @param {(info: {section: object}) => *} [props.renderSectionHeader] Rendered before a section's rows.
72
- * @param {(info: {section: object}) => *} [props.renderSectionFooter] Rendered after a section's rows.
73
- * @param {(item: *, index: number) => string|number} [props.keyExtractor] React key per row (a
74
- * section's own `keyExtractor` wins); defaults to the key `renderItem` already set, else the index.
75
- * @param {object} [props.style] Forwarded to the ScrollView untouched.
76
- * @returns {*} A <ScrollView> holding every section's header, rows and footer as flat children.
77
- */
78
- export function SectionList(props = {}) {
79
- const {
80
- sections,
81
- renderItem,
82
- renderSectionHeader,
83
- renderSectionFooter,
84
- keyExtractor,
85
- style,
86
- } = props;
87
-
88
- warnUnsupportedProps(props);
89
-
90
- const children = [];
91
- if (Array.isArray(sections)) {
92
- for (let sectionIndex = 0; sectionIndex < sections.length; sectionIndex++) {
93
- const section = sections[sectionIndex];
94
- if (section === null || typeof section !== 'object') continue;
95
- const sectionKey =
96
- section.key === null || section.key === undefined
97
- ? String(sectionIndex)
98
- : String(section.key);
99
-
100
- if (typeof renderSectionHeader === 'function')
101
- pushKeyedChild(
102
- children,
103
- renderSectionHeader({section}),
104
- () => `${sectionKey}:$header`,
105
- );
106
-
107
- const rowRenderer =
108
- typeof section.renderItem === 'function'
109
- ? section.renderItem
110
- : renderItem;
111
- const rowKey =
112
- typeof section.keyExtractor === 'function'
113
- ? section.keyExtractor
114
- : keyExtractor;
115
- if (Array.isArray(section.data) && typeof rowRenderer === 'function') {
116
- for (let index = 0; index < section.data.length; index++) {
117
- const item = section.data[index];
118
- const row = rowRenderer({item, index, section});
119
- // Built lazily, so keyExtractor never runs for a row that rendered nothing or for a raw
120
- // string — see pushKeyedChild.
121
- pushKeyedChild(children, row, element => {
122
- const key = rowKey
123
- ? String(rowKey(item, index))
124
- : element.key !== null && element.key !== undefined
125
- ? element.key
126
- : String(index);
127
- return `${sectionKey}:${key}`;
128
- });
129
- }
130
- }
131
-
132
- if (typeof renderSectionFooter === 'function')
133
- pushKeyedChild(
134
- children,
135
- renderSectionFooter({section}),
136
- () => `${sectionKey}:$footer`,
137
- );
138
- }
139
- }
140
-
141
- return createElement(
142
- ScrollView,
143
- style === undefined ? null : {style},
144
- children,
145
- );
146
- }
@@ -1,101 +0,0 @@
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
- // Pure LayoutAnimation config helpers — no NativeUI dependency, so they're unit-testable in plain
18
- // Node (see __tests__/layout-animation.unit.test.js). LayoutAnimation.js wires configureNext to the
19
- // bridge using these.
20
-
21
- /** Duration when a config gives none, as in RN. */
22
- export const DEFAULT_DURATION_MS = 300;
23
-
24
- /** RN-compatible animation type tokens. */
25
- export const Types = {
26
- spring: 'spring',
27
- linear: 'linear',
28
- easeInEaseOut: 'easeInEaseOut',
29
- easeIn: 'easeIn',
30
- easeOut: 'easeOut',
31
- keyboard: 'keyboard',
32
- };
33
-
34
- /** RN-compatible animated-property tokens (accepted for API parity; the engine tweens position). */
35
- export const Properties = {
36
- opacity: 'opacity',
37
- scaleX: 'scaleX',
38
- scaleY: 'scaleY',
39
- scaleXY: 'scaleXY',
40
- };
41
-
42
- /** Maps an RN animation-type token to an engine easing token. */
43
- function easingForType(type) {
44
- switch (type) {
45
- case Types.linear:
46
- return 'linear';
47
- case Types.easeIn:
48
- return 'easeIn';
49
- case Types.easeOut:
50
- return 'easeOut';
51
- case Types.easeInEaseOut:
52
- case Types.keyboard:
53
- default:
54
- return 'easeInOut';
55
- }
56
- }
57
-
58
- /**
59
- * Reduces an RN LayoutAnimation config ({ duration, create, update, delete }) to the engine's flat
60
- * config. The engine tweens the *position transition*, which is RN's `update`; create/delete opacity
61
- * are accepted for parity but not separately animated.
62
- */
63
- export function toEngineConfig(config) {
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;
71
- if (type === Types.spring) {
72
- return {type: 'spring', duration};
73
- }
74
- return {type: 'timing', duration, easing: easingForType(type)};
75
- }
76
-
77
- /** Builds an RN-shaped config (duration + create/update/delete) from a type + creation property. */
78
- export function create(
79
- duration,
80
- type = Types.easeInEaseOut,
81
- creationProp = Properties.opacity,
82
- ) {
83
- return {
84
- duration,
85
- create: {type, property: creationProp},
86
- update: {type},
87
- delete: {type, property: creationProp},
88
- };
89
- }
90
-
91
- /** RN-compatible preset configs. */
92
- export const Presets = {
93
- easeInEaseOut: create(300, Types.easeInEaseOut, Properties.opacity),
94
- linear: create(500, Types.linear, Properties.opacity),
95
- spring: {
96
- duration: 700,
97
- create: {type: Types.linear, property: Properties.opacity},
98
- update: {type: Types.spring, springDamping: 0.4},
99
- delete: {type: Types.linear, property: Properties.opacity},
100
- },
101
- };