embedded-react 0.20.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.
- package/NOTICE +5 -0
- package/README.md +3 -2
- package/aot/app-file-loader.mjs +116 -0
- package/aot/compile.mjs +17 -47
- package/aot/compiler/alerts.mjs +604 -0
- package/aot/compiler/animations.mjs +299 -57
- package/aot/compiler/boot.mjs +27 -2
- package/aot/compiler/check.mjs +62 -10
- package/aot/compiler/collect.mjs +517 -137
- package/aot/compiler/contexts.mjs +391 -0
- package/aot/compiler/control-flow.mjs +276 -117
- package/aot/compiler/custom-hooks.mjs +686 -0
- package/aot/compiler/elements/button.mjs +182 -0
- package/aot/compiler/elements/image-background.mjs +76 -0
- package/aot/compiler/elements/image.mjs +2 -1
- package/aot/compiler/elements/props.mjs +47 -8
- package/aot/compiler/elements/rewrite.mjs +118 -0
- package/aot/compiler/elements/section-list.mjs +370 -0
- package/aot/compiler/expressions.mjs +1378 -97
- package/aot/compiler/handlers.mjs +1807 -354
- package/aot/compiler/helper-values.mjs +312 -0
- package/aot/compiler/ir/nodes.mjs +40 -1
- package/aot/compiler/ir/reads.mjs +206 -5
- package/aot/compiler/ir/text.mjs +5 -1
- package/aot/compiler/ir/types.mjs +12 -0
- package/aot/compiler/kept-states.mjs +177 -0
- package/aot/compiler/keyboard-dismiss.mjs +99 -0
- package/aot/compiler/keyboard.mjs +1 -1
- 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 +203 -53
- 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 +45 -31
- package/aot/compiler/options.mjs +3 -2
- package/aot/compiler/out.mjs +18 -1
- package/aot/compiler/package/animations.mjs +133 -23
- package/aot/compiler/package/assemble.mjs +2 -4
- package/aot/compiler/package/bytecode.mjs +37 -8
- package/aot/compiler/package/checks.mjs +4 -0
- package/aot/compiler/package/codegen.mjs +906 -33
- package/aot/compiler/package/enums.mjs +10 -0
- package/aot/compiler/package/format.mjs +16 -3
- package/aot/compiler/package/lower.mjs +707 -176
- package/aot/compiler/package/string-caps.mjs +515 -0
- package/aot/compiler/package/tables.mjs +24 -0
- package/aot/compiler/package/writer.mjs +22 -0
- package/aot/compiler/parse.mjs +3 -1
- 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/scroll-to.mjs +112 -0
- package/aot/compiler/static-eval.mjs +315 -7
- package/aot/compiler/style-text.mjs +20 -5
- package/aot/compiler/svg.mjs +13 -7
- 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 +321 -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/style-map.mjs +94 -3
- package/assets/bake-font.mjs +187 -244
- package/assets/bake-image.mjs +47 -71
- package/assets/bake-svg.mjs +465 -533
- package/assets/build-builtin-font.mjs +14 -27
- package/assets/emit-c.mjs +124 -204
- package/assets/emit-container.mjs +129 -197
- package/assets/emit-pack.mjs +92 -136
- package/assets/font-config.mjs +19 -27
- package/assets/font-sizes.mjs +432 -507
- package/assets/glyph-coverage.mjs +170 -214
- package/assets/index.mjs +52 -97
- package/assets/rasterize.mjs +173 -194
- package/assets/svg-loader.mjs +42 -48
- package/build.mjs +85 -94
- package/cli.mjs +490 -586
- package/compile-bin.mjs +24 -36
- package/flash.mjs +297 -401
- package/hotreload/dev-device.mjs +229 -270
- package/hotreload/pack-app.mjs +118 -159
- package/hotreload/pack-split.mjs +146 -213
- package/hotreload/package-transfer.mjs +128 -131
- package/hotreload/protocol.mjs +118 -118
- package/hotreload/uploader.mjs +132 -159
- package/hotreload/watch-tree.mjs +56 -65
- package/pack-container.mjs +94 -116
- package/package.json +19 -16
- package/persist-transform.mjs +89 -105
- package/qjsc-wasm.mjs +47 -72
- package/sim/embedded-react.wasm +0 -0
- package/sim/index.html +1 -1
- package/sim-server.mjs +260 -354
- package/src/embedded-react/Alert.mjs +112 -0
- package/src/embedded-react/Animated.mjs +412 -0
- package/src/embedded-react/{AppRegistry.js → AppRegistry.mjs} +26 -25
- package/src/embedded-react/{Button.js → Button.mjs} +29 -53
- package/src/embedded-react/Dimensions.mjs +32 -0
- package/src/embedded-react/Easing.mjs +34 -0
- package/src/embedded-react/{FlatList.js → FlatList.mjs} +25 -42
- package/src/embedded-react/{ImageBackground.js → ImageBackground.mjs} +11 -22
- package/src/embedded-react/Keyboard.mjs +82 -0
- package/src/embedded-react/{LayoutAnimation.js → LayoutAnimation.mjs} +17 -28
- package/src/embedded-react/PanResponder.mjs +256 -0
- package/src/embedded-react/{Platform.js → Platform.mjs} +8 -9
- package/src/embedded-react/{Pressable.js → Pressable.mjs} +12 -25
- package/src/embedded-react/SectionList.mjs +103 -0
- package/src/embedded-react/{StyleSheet.js → StyleSheet.mjs} +16 -20
- package/src/embedded-react/{TouchableOpacity.js → TouchableOpacity.mjs} +47 -83
- package/src/embedded-react/background-image.mjs +321 -0
- package/src/embedded-react/{components.js → components.mjs} +1 -3
- package/src/embedded-react/{imperative.js → imperative.mjs} +27 -38
- package/src/embedded-react/index.d.ts +238 -5
- package/src/embedded-react/index.js +26 -17
- package/src/embedded-react/layout-anim-config.mjs +85 -0
- package/src/embedded-react/{list-child.js → list-child.mjs} +11 -20
- package/src/embedded-react/{named-colors.js → named-colors.mjs} +2 -6
- package/src/embedded-react/nativeModule.mjs +371 -0
- package/src/embedded-react/split-style.mjs +57 -0
- package/src/embedded-react/svg-ops.mjs +1075 -0
- package/src/embedded-react/{useHostValue.js → useHostValue.mjs} +2 -4
- package/src/embedded-react/{usePersistentState.js → usePersistentState.mjs} +34 -38
- package/src/embedded-react/{warn-props.js → warn-props.mjs} +32 -39
- package/src/host-config.mjs +512 -0
- package/src/{native-ui.js → native-ui.mjs} +1 -8
- package/src/props.mjs +341 -0
- package/src/{renderer.js → renderer.mjs} +30 -44
- package/src/embedded-react/Animated.js +0 -440
- package/src/embedded-react/Easing.js +0 -39
- package/src/embedded-react/PanResponder.js +0 -330
- package/src/embedded-react/SectionList.js +0 -148
- package/src/embedded-react/layout-anim-config.js +0 -101
- package/src/embedded-react/split-style.js +0 -58
- package/src/embedded-react/svg-ops.js +0 -1295
- package/src/host-config.js +0 -548
- 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,148 +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
|
-
// Unlike <FlatList>, this has no Flow B counterpart yet — the AOT unrolls one `.map` per container
|
|
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".
|
|
39
|
-
import {createElement} from 'react';
|
|
40
|
-
import {ScrollView} from './components.js';
|
|
41
|
-
import {pushKeyedChild} from './list-child.js';
|
|
42
|
-
import {createPropWarner, RN_PLATFORM_NO_OPS} from './warn-props.js';
|
|
43
|
-
|
|
44
|
-
/** The props this honours. The rest are virtualization / platform knobs with no meaning on a panel. */
|
|
45
|
-
const SUPPORTED = [
|
|
46
|
-
'sections',
|
|
47
|
-
'renderItem',
|
|
48
|
-
'renderSectionHeader',
|
|
49
|
-
'renderSectionFooter',
|
|
50
|
-
'keyExtractor',
|
|
51
|
-
'style',
|
|
52
|
-
];
|
|
53
|
-
|
|
54
|
-
const warnUnsupportedProps = createPropWarner(
|
|
55
|
-
'SectionList',
|
|
56
|
-
SUPPORTED,
|
|
57
|
-
'it is a thin <ScrollView> alias with no virtualization and no sticky headers. For separators, ' +
|
|
58
|
-
'list headers/footers or onEndReached, use <ScrollView> + .map directly.',
|
|
59
|
-
RN_PLATFORM_NO_OPS,
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Renders `sections` into a <ScrollView>, each as an optional header, its rows, and an optional footer.
|
|
64
|
-
*
|
|
65
|
-
* Row keys are namespaced by section (`<section>:<row>`), because the rows of every section end up as
|
|
66
|
-
* siblings of one another — an index or an id that is only unique WITHIN a section would collide.
|
|
67
|
-
*
|
|
68
|
-
* @param {object} [props] Missing / empty renders an empty scroller, like a missing `sections`.
|
|
69
|
-
* @param {Array} [props.sections] Sections, each `{data, key?, renderItem?, keyExtractor?, ...}`.
|
|
70
|
-
* Anything else on a section (RN's convention is `title`) is yours, and reaches the render callbacks.
|
|
71
|
-
* @param {(info: {item: *, index: number, section: object}) => *} [props.renderItem] Row renderer.
|
|
72
|
-
* A section's own `renderItem` wins for that section, as in RN.
|
|
73
|
-
* @param {(info: {section: object}) => *} [props.renderSectionHeader] Rendered before a section's rows.
|
|
74
|
-
* @param {(info: {section: object}) => *} [props.renderSectionFooter] Rendered after a section's rows.
|
|
75
|
-
* @param {(item: *, index: number) => string|number} [props.keyExtractor] React key per row (a
|
|
76
|
-
* section's own `keyExtractor` wins); defaults to the key `renderItem` already set, else the index.
|
|
77
|
-
* @param {object} [props.style] Forwarded to the ScrollView untouched.
|
|
78
|
-
* @returns {*} A <ScrollView> holding every section's header, rows and footer as flat children.
|
|
79
|
-
*/
|
|
80
|
-
export function SectionList(props = {}) {
|
|
81
|
-
const {
|
|
82
|
-
sections,
|
|
83
|
-
renderItem,
|
|
84
|
-
renderSectionHeader,
|
|
85
|
-
renderSectionFooter,
|
|
86
|
-
keyExtractor,
|
|
87
|
-
style,
|
|
88
|
-
} = props;
|
|
89
|
-
|
|
90
|
-
warnUnsupportedProps(props);
|
|
91
|
-
|
|
92
|
-
const children = [];
|
|
93
|
-
if (Array.isArray(sections)) {
|
|
94
|
-
for (let sectionIndex = 0; sectionIndex < sections.length; sectionIndex++) {
|
|
95
|
-
const section = sections[sectionIndex];
|
|
96
|
-
if (section === null || typeof section !== 'object') continue;
|
|
97
|
-
const sectionKey =
|
|
98
|
-
section.key === null || section.key === undefined
|
|
99
|
-
? String(sectionIndex)
|
|
100
|
-
: String(section.key);
|
|
101
|
-
|
|
102
|
-
if (typeof renderSectionHeader === 'function')
|
|
103
|
-
pushKeyedChild(
|
|
104
|
-
children,
|
|
105
|
-
renderSectionHeader({section}),
|
|
106
|
-
() => `${sectionKey}:$header`,
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
const rowRenderer =
|
|
110
|
-
typeof section.renderItem === 'function'
|
|
111
|
-
? section.renderItem
|
|
112
|
-
: renderItem;
|
|
113
|
-
const rowKey =
|
|
114
|
-
typeof section.keyExtractor === 'function'
|
|
115
|
-
? section.keyExtractor
|
|
116
|
-
: keyExtractor;
|
|
117
|
-
if (Array.isArray(section.data) && typeof rowRenderer === 'function') {
|
|
118
|
-
for (let index = 0; index < section.data.length; index++) {
|
|
119
|
-
const item = section.data[index];
|
|
120
|
-
const row = rowRenderer({item, index, section});
|
|
121
|
-
// Built lazily, so keyExtractor never runs for a row that rendered nothing or for a raw
|
|
122
|
-
// string — see pushKeyedChild.
|
|
123
|
-
pushKeyedChild(children, row, element => {
|
|
124
|
-
const key = rowKey
|
|
125
|
-
? String(rowKey(item, index))
|
|
126
|
-
: element.key !== null && element.key !== undefined
|
|
127
|
-
? element.key
|
|
128
|
-
: String(index);
|
|
129
|
-
return `${sectionKey}:${key}`;
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (typeof renderSectionFooter === 'function')
|
|
135
|
-
pushKeyedChild(
|
|
136
|
-
children,
|
|
137
|
-
renderSectionFooter({section}),
|
|
138
|
-
() => `${sectionKey}:$footer`,
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return createElement(
|
|
144
|
-
ScrollView,
|
|
145
|
-
style === undefined ? null : {style},
|
|
146
|
-
children,
|
|
147
|
-
);
|
|
148
|
-
}
|
|
@@ -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
|
-
};
|
|
@@ -1,58 +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
|
-
// Separates a style object into the static props (passed straight to the node) and the animated
|
|
18
|
-
// bindings (Animated.Value / interpolation, bound to the node's prop so the engine drives them).
|
|
19
|
-
// Pure (no NativeUI), so it's unit-testable. An animated entry is anything with an `__animated`
|
|
20
|
-
// marker — `transform: [{ translateX: value }]` entries are handled too (scale binds both axes).
|
|
21
|
-
import {flattenStyle} from '../props.js';
|
|
22
|
-
|
|
23
|
-
export function splitAnimatedStyle(style) {
|
|
24
|
-
const staticStyle = {};
|
|
25
|
-
const bindings = [];
|
|
26
|
-
|
|
27
|
-
const flat = {};
|
|
28
|
-
flattenStyle(style, flat);
|
|
29
|
-
|
|
30
|
-
for (const key in flat) {
|
|
31
|
-
const value = flat[key];
|
|
32
|
-
|
|
33
|
-
if (key === 'transform' && Array.isArray(value)) {
|
|
34
|
-
const staticTransform = [];
|
|
35
|
-
for (const entry of value) {
|
|
36
|
-
const axis = Object.keys(entry)[0];
|
|
37
|
-
const axisValue = entry[axis];
|
|
38
|
-
if (axisValue && axisValue.__animated) {
|
|
39
|
-
if (axis === 'scale') {
|
|
40
|
-
bindings.push({prop: 'scaleX', value: axisValue});
|
|
41
|
-
bindings.push({prop: 'scaleY', value: axisValue});
|
|
42
|
-
} else {
|
|
43
|
-
bindings.push({prop: axis, value: axisValue});
|
|
44
|
-
}
|
|
45
|
-
} else {
|
|
46
|
-
staticTransform.push(entry);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (staticTransform.length > 0) staticStyle.transform = staticTransform;
|
|
50
|
-
} else if (value && value.__animated) {
|
|
51
|
-
bindings.push({prop: key, value});
|
|
52
|
-
} else {
|
|
53
|
-
staticStyle[key] = value;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return {staticStyle, bindings};
|
|
58
|
-
}
|