embedded-react 0.18.0 → 0.20.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 +1 -1
- package/README.md +8 -4
- package/aot/compile.mjs +178 -58
- package/aot/compiler/animations.mjs +290 -281
- package/aot/compiler/boot.mjs +70 -33
- package/aot/compiler/branch-merge.mjs +4 -3
- package/aot/compiler/check.mjs +9 -9
- package/aot/compiler/collect.mjs +324 -205
- package/aot/compiler/control-flow.mjs +209 -197
- package/aot/compiler/diagnostics.mjs +22 -25
- package/aot/compiler/elements/activity-indicator.mjs +25 -24
- package/aot/compiler/elements/dial.mjs +91 -77
- package/aot/compiler/elements/flat-list.mjs +24 -22
- package/aot/compiler/elements/image.mjs +51 -50
- package/aot/compiler/elements/modal.mjs +31 -30
- package/aot/compiler/elements/props.mjs +23 -23
- package/aot/compiler/elements/switch.mjs +42 -34
- package/aot/compiler/elements/text-input.mjs +34 -32
- package/aot/compiler/expressions.mjs +372 -333
- package/aot/compiler/handlers.mjs +473 -387
- package/aot/compiler/ir/functions.mjs +11 -1
- package/aot/compiler/ir/nodes.mjs +4 -4
- package/aot/compiler/ir/reads.mjs +19 -19
- package/aot/compiler/ir/types.mjs +14 -14
- package/aot/compiler/ir/vectors.mjs +5 -1
- package/aot/compiler/keyboard.mjs +17 -7
- package/aot/compiler/lower.mjs +77 -80
- package/aot/compiler/nodes.mjs +169 -152
- package/aot/compiler/options.mjs +35 -30
- package/aot/compiler/out.mjs +18 -22
- package/aot/compiler/package/animations.mjs +669 -0
- package/aot/compiler/package/arena.mjs +252 -0
- package/aot/compiler/package/assemble.mjs +177 -0
- package/aot/compiler/package/bytecode.mjs +286 -0
- package/aot/compiler/package/checks.mjs +1022 -0
- package/aot/compiler/package/codegen.mjs +1329 -0
- package/aot/compiler/package/enums.mjs +138 -0
- package/aot/compiler/package/format.mjs +760 -0
- package/aot/compiler/package/layouts.mjs +136 -0
- package/aot/compiler/package/lower.mjs +1606 -0
- package/aot/compiler/package/props.mjs +118 -0
- package/aot/compiler/package/tables.mjs +103 -0
- package/aot/compiler/package/vectors.mjs +502 -0
- package/aot/compiler/package/writer.mjs +664 -0
- package/aot/compiler/pan-responder.mjs +69 -61
- package/aot/compiler/parse.mjs +21 -21
- package/aot/compiler/static-eval.mjs +25 -23
- package/aot/compiler/style-text.mjs +161 -172
- package/aot/compiler/svg.mjs +477 -251
- package/aot/screenshot-smoke.mjs +55 -41
- package/aot/style-map.mjs +102 -90
- 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 +14 -10
- package/assets/emit-c.mjs +83 -62
- package/assets/emit-container.mjs +124 -38
- 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 +16 -14
- package/cli.mjs +359 -172
- package/compile-bin.mjs +5 -5
- package/flash.mjs +537 -0
- package/hotreload/dev-device.mjs +90 -33
- package/hotreload/pack-app.mjs +55 -43
- package/hotreload/pack-split.mjs +46 -37
- package/hotreload/package-transfer.mjs +175 -0
- package/hotreload/protocol.mjs +51 -38
- package/hotreload/uploader.mjs +38 -27
- package/hotreload/watch-tree.mjs +19 -19
- package/pack-container.mjs +31 -23
- package/package.json +11 -12
- 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 +101 -82
- package/src/embedded-react/Animated.js +24 -24
- package/src/embedded-react/Easing.js +1 -1
- package/src/embedded-react/FlatList.js +4 -4
- 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 +6 -6
- package/src/embedded-react/StyleSheet.js +4 -3
- package/src/embedded-react/TouchableOpacity.js +13 -8
- package/src/embedded-react/index.d.ts +5 -5
- 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/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
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
// Animated — the React Native analog, backed by the engine's native-driver value system
|
|
18
|
-
// (
|
|
18
|
+
// (er_animation_value_*). An Animated.Value is a handle to an engine-side float; binding it to a node
|
|
19
19
|
// prop (via Animated.View) lets the engine advance the animation each frame with NO per-frame JS.
|
|
20
20
|
import {createElement, useRef, useEffect} from 'react';
|
|
21
21
|
import {NativeUI} from '../native-ui.js';
|
|
@@ -55,9 +55,9 @@ export class AnimatedValue {
|
|
|
55
55
|
this._destroyed = false;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
setValue(
|
|
59
|
-
this._value =
|
|
60
|
-
NativeUI.animValueSet(this._handle,
|
|
58
|
+
setValue(value) {
|
|
59
|
+
this._value = value;
|
|
60
|
+
NativeUI.animValueSet(this._handle, value);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
@@ -103,14 +103,14 @@ export class AnimatedInterpolation {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
__bind(node, prop) {
|
|
106
|
-
const
|
|
107
|
-
if (Array.isArray(
|
|
106
|
+
const outputRange = this._config?.outputRange;
|
|
107
|
+
if (Array.isArray(outputRange)) {
|
|
108
108
|
if (COLOR_PROPS.has(prop)) {
|
|
109
|
-
if (
|
|
109
|
+
if (outputRange.some(output => typeof output !== 'string')) {
|
|
110
110
|
warnColorBind(prop);
|
|
111
111
|
return;
|
|
112
112
|
}
|
|
113
|
-
} else if (
|
|
113
|
+
} else if (outputRange.some(output => typeof output !== 'number')) {
|
|
114
114
|
warnNumberBind(prop);
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
@@ -142,13 +142,13 @@ export class AnimatedInterpolation {
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
/** Wraps
|
|
146
|
-
function once(
|
|
145
|
+
/** Wraps callback so it runs at most once, regardless of how many times it is invoked. */
|
|
146
|
+
function once(callback) {
|
|
147
147
|
let called = false;
|
|
148
|
-
return
|
|
148
|
+
return argument => {
|
|
149
149
|
if (called) return;
|
|
150
150
|
called = true;
|
|
151
|
-
if (
|
|
151
|
+
if (callback) callback(argument);
|
|
152
152
|
};
|
|
153
153
|
}
|
|
154
154
|
|
|
@@ -166,11 +166,11 @@ function makeAnimation(value, toValue, config) {
|
|
|
166
166
|
_value: value,
|
|
167
167
|
start(onComplete) {
|
|
168
168
|
// Always pass a wrapper so we can null out the (possibly recycled) handle on completion.
|
|
169
|
-
const
|
|
169
|
+
const onEnd = finished => {
|
|
170
170
|
handle = 0;
|
|
171
171
|
if (onComplete) onComplete({finished: !!finished});
|
|
172
172
|
};
|
|
173
|
-
handle = NativeUI.animValueAnimate(value._handle, toValue, config,
|
|
173
|
+
handle = NativeUI.animValueAnimate(value._handle, toValue, config, onEnd);
|
|
174
174
|
},
|
|
175
175
|
stop() {
|
|
176
176
|
if (handle) NativeUI.animStop(handle);
|
|
@@ -252,16 +252,16 @@ export function parallel(animations, config) {
|
|
|
252
252
|
anyUnfinished = true;
|
|
253
253
|
if (stopTogether && !stopped) {
|
|
254
254
|
stopped = true;
|
|
255
|
-
for (const
|
|
255
|
+
for (const animation of animations) animation.stop();
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
if (doneCount >= total) done({finished: !anyUnfinished});
|
|
259
259
|
};
|
|
260
|
-
for (const
|
|
260
|
+
for (const animation of animations) animation.start(onChild);
|
|
261
261
|
},
|
|
262
262
|
stop() {
|
|
263
263
|
stopped = true;
|
|
264
|
-
for (const
|
|
264
|
+
for (const animation of animations) animation.stop();
|
|
265
265
|
},
|
|
266
266
|
};
|
|
267
267
|
}
|
|
@@ -285,22 +285,22 @@ export function stagger(delay, animations) {
|
|
|
285
285
|
if (!result || result.finished === false) anyUnfinished = true;
|
|
286
286
|
if (doneCount >= total) done({finished: !anyUnfinished});
|
|
287
287
|
};
|
|
288
|
-
animations.forEach((
|
|
289
|
-
if (
|
|
290
|
-
|
|
288
|
+
animations.forEach((animation, index) => {
|
|
289
|
+
if (index === 0) {
|
|
290
|
+
animation.start(onChild);
|
|
291
291
|
} else {
|
|
292
292
|
timers.push(
|
|
293
293
|
setTimeout(() => {
|
|
294
|
-
if (!stopped)
|
|
295
|
-
}, delay *
|
|
294
|
+
if (!stopped) animation.start(onChild);
|
|
295
|
+
}, delay * index),
|
|
296
296
|
);
|
|
297
297
|
}
|
|
298
298
|
});
|
|
299
299
|
},
|
|
300
300
|
stop() {
|
|
301
301
|
stopped = true;
|
|
302
|
-
for (const
|
|
303
|
-
for (const
|
|
302
|
+
for (const timer of timers) clearTimeout(timer);
|
|
303
|
+
for (const animation of animations) animation.stop();
|
|
304
304
|
},
|
|
305
305
|
};
|
|
306
306
|
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
// Easing tokens. The engine implements a fixed set of easing curves (
|
|
17
|
+
// Easing tokens. The engine implements a fixed set of easing curves (ERAnimationEasing), so unlike RN's
|
|
18
18
|
// composable Easing functions these are string tokens the bridge maps to the engine enum. `bezier`
|
|
19
19
|
// returns a control-point object the bridge reads as a custom cubic-bezier curve.
|
|
20
20
|
export const Easing = {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
// data.length x (nodes per row) slots out of the fixed ERUI_MAX_NODES pool. See "FlatList is a
|
|
29
29
|
// ScrollView alias" in the top-level README for the limits and when to reach for something else.
|
|
30
30
|
//
|
|
31
|
-
// This mirrors the AOT's emitFlatList (
|
|
31
|
+
// This mirrors the AOT's emitFlatList (packages/embedded-react/aot/compiler/elements/flat-list.mts),
|
|
32
32
|
// which performs the same rewrite at compile time. The two flows accept the SAME four props on
|
|
33
33
|
// purpose — a list that renders in the simulator must also compile for the device, so anything
|
|
34
34
|
// Flow B rejects is warned about here rather than silently forwarded.
|
|
@@ -74,11 +74,11 @@ export function FlatList(props = {}) {
|
|
|
74
74
|
const row = renderItem({item, index});
|
|
75
75
|
// The key is built lazily: pushKeyedChild calls this only for a row that can hold one, so
|
|
76
76
|
// keyExtractor never runs for a row that rendered nothing or for a raw string.
|
|
77
|
-
pushKeyedChild(rows, row,
|
|
77
|
+
pushKeyedChild(rows, row, element =>
|
|
78
78
|
keyExtractor
|
|
79
79
|
? String(keyExtractor(item, index))
|
|
80
|
-
:
|
|
81
|
-
?
|
|
80
|
+
: element.key !== null && element.key !== undefined
|
|
81
|
+
? element.key
|
|
82
82
|
: String(index),
|
|
83
83
|
);
|
|
84
84
|
}
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
// LayoutAnimation — the React Native analog. Calling configureNext(...) before a state update that
|
|
18
18
|
// changes layout makes the engine tween every node whose computed rect moved (instead of snapping)
|
|
19
|
-
// on the next commit. Backed by the engine's
|
|
20
|
-
// each frame (
|
|
19
|
+
// on the next commit. Backed by the engine's er_layout_animation_configure_next; the tween advances in C
|
|
20
|
+
// each frame (er_layout_animation_tick), so there's no per-frame JS.
|
|
21
21
|
import {NativeUI} from '../native-ui.js';
|
|
22
22
|
import {
|
|
23
23
|
Types,
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
Presets,
|
|
26
26
|
toEngineConfig,
|
|
27
27
|
create,
|
|
28
|
+
DEFAULT_DURATION_MS,
|
|
28
29
|
} from './layout-anim-config.js';
|
|
29
30
|
|
|
30
31
|
/**
|
|
@@ -34,9 +35,11 @@ import {
|
|
|
34
35
|
export function configureNext(config, onAnimationDidEnd) {
|
|
35
36
|
NativeUI.configureNextLayoutAnimation(toEngineConfig(config));
|
|
36
37
|
if (typeof onAnimationDidEnd === 'function') {
|
|
37
|
-
const
|
|
38
|
-
config && typeof config.duration === 'number'
|
|
39
|
-
|
|
38
|
+
const durationMs =
|
|
39
|
+
config && typeof config.duration === 'number'
|
|
40
|
+
? config.duration
|
|
41
|
+
: DEFAULT_DURATION_MS;
|
|
42
|
+
setTimeout(onAnimationDidEnd, durationMs);
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
|
|
@@ -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,
|
|
@@ -91,12 +91,12 @@ export function SectionList(props = {}) {
|
|
|
91
91
|
|
|
92
92
|
const children = [];
|
|
93
93
|
if (Array.isArray(sections)) {
|
|
94
|
-
for (let
|
|
95
|
-
const section = sections[
|
|
94
|
+
for (let sectionIndex = 0; sectionIndex < sections.length; sectionIndex++) {
|
|
95
|
+
const section = sections[sectionIndex];
|
|
96
96
|
if (section === null || typeof section !== 'object') continue;
|
|
97
97
|
const sectionKey =
|
|
98
98
|
section.key === null || section.key === undefined
|
|
99
|
-
? String(
|
|
99
|
+
? String(sectionIndex)
|
|
100
100
|
: String(section.key);
|
|
101
101
|
|
|
102
102
|
if (typeof renderSectionHeader === 'function')
|
|
@@ -120,11 +120,11 @@ export function SectionList(props = {}) {
|
|
|
120
120
|
const row = rowRenderer({item, index, section});
|
|
121
121
|
// Built lazily, so keyExtractor never runs for a row that rendered nothing or for a raw
|
|
122
122
|
// string — see pushKeyedChild.
|
|
123
|
-
pushKeyedChild(children, row,
|
|
123
|
+
pushKeyedChild(children, row, element => {
|
|
124
124
|
const key = rowKey
|
|
125
125
|
? String(rowKey(item, index))
|
|
126
|
-
:
|
|
127
|
-
?
|
|
126
|
+
: element.key !== null && element.key !== undefined
|
|
127
|
+
? element.key
|
|
128
128
|
: String(index);
|
|
129
129
|
return `${sectionKey}:${key}`;
|
|
130
130
|
});
|
|
@@ -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
|
/**
|
|
@@ -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
|
|
@@ -1058,8 +1058,8 @@ export interface VectorShape {
|
|
|
1058
1058
|
cap?: 'butt' | 'round' | 'square';
|
|
1059
1059
|
join?: 'miter' | 'round' | 'bevel';
|
|
1060
1060
|
fillRule?: 'nonzero' | 'evenodd';
|
|
1061
|
-
|
|
1062
|
-
|
|
1061
|
+
fillGradient?: VectorGradient;
|
|
1062
|
+
strokeGradient?: VectorGradient;
|
|
1063
1063
|
}
|
|
1064
1064
|
|
|
1065
1065
|
/**
|
|
@@ -1103,7 +1103,7 @@ export interface KeyboardConfig {
|
|
|
1103
1103
|
rowHeight?: number;
|
|
1104
1104
|
keyGap?: number;
|
|
1105
1105
|
keyRadius?: number;
|
|
1106
|
-
|
|
1106
|
+
gridColumns?: number;
|
|
1107
1107
|
layers?: KeyboardKey[][][];
|
|
1108
1108
|
}
|
|
1109
1109
|
|
|
@@ -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
|
}
|