embedded-react 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +5 -0
- package/README.md +8 -3
- package/aot/app-file-loader.mjs +116 -0
- package/aot/compile.mjs +180 -90
- package/aot/compiler/animations.mjs +568 -317
- package/aot/compiler/boot.mjs +97 -35
- package/aot/compiler/branch-merge.mjs +4 -3
- package/aot/compiler/check.mjs +70 -18
- package/aot/compiler/collect.mjs +787 -288
- package/aot/compiler/contexts.mjs +391 -0
- package/aot/compiler/control-flow.mjs +439 -268
- package/aot/compiler/custom-hooks.mjs +686 -0
- package/aot/compiler/diagnostics.mjs +22 -25
- package/aot/compiler/elements/activity-indicator.mjs +25 -24
- package/aot/compiler/elements/button.mjs +182 -0
- package/aot/compiler/elements/dial.mjs +91 -77
- package/aot/compiler/elements/flat-list.mjs +24 -22
- package/aot/compiler/elements/image-background.mjs +76 -0
- package/aot/compiler/elements/image.mjs +52 -50
- package/aot/compiler/elements/modal.mjs +31 -30
- package/aot/compiler/elements/props.mjs +61 -26
- package/aot/compiler/elements/rewrite.mjs +118 -0
- package/aot/compiler/elements/section-list.mjs +370 -0
- package/aot/compiler/elements/switch.mjs +42 -34
- package/aot/compiler/elements/text-input.mjs +34 -32
- package/aot/compiler/expressions.mjs +1685 -392
- package/aot/compiler/handlers.mjs +2029 -547
- package/aot/compiler/helper-values.mjs +312 -0
- package/aot/compiler/ir/functions.mjs +11 -1
- package/aot/compiler/ir/nodes.mjs +43 -4
- package/aot/compiler/ir/reads.mjs +223 -22
- package/aot/compiler/ir/text.mjs +5 -1
- package/aot/compiler/ir/types.mjs +26 -14
- package/aot/compiler/ir/vectors.mjs +5 -1
- package/aot/compiler/kept-states.mjs +177 -0
- package/aot/compiler/keyboard.mjs +17 -7
- package/aot/compiler/list-items.mjs +226 -0
- package/aot/compiler/list-order.mjs +586 -0
- package/aot/compiler/list-split.mjs +259 -0
- package/aot/compiler/loops.mjs +582 -0
- package/aot/compiler/lower.mjs +246 -111
- package/aot/compiler/native-files.mjs +439 -0
- package/aot/compiler/native-header.mjs +335 -0
- package/aot/compiler/native-modules.mjs +1173 -0
- package/aot/compiler/nodes.mjs +195 -172
- package/aot/compiler/options.mjs +37 -31
- package/aot/compiler/out.mjs +32 -23
- package/aot/compiler/package/animations.mjs +779 -0
- package/aot/compiler/package/arena.mjs +252 -0
- package/aot/compiler/package/assemble.mjs +175 -0
- package/aot/compiler/package/bytecode.mjs +315 -0
- package/aot/compiler/package/checks.mjs +1026 -0
- package/aot/compiler/package/codegen.mjs +2168 -0
- package/aot/compiler/package/enums.mjs +148 -0
- package/aot/compiler/package/format.mjs +771 -0
- package/aot/compiler/package/layouts.mjs +136 -0
- package/aot/compiler/package/lower.mjs +2103 -0
- package/aot/compiler/package/props.mjs +118 -0
- package/aot/compiler/package/string-caps.mjs +515 -0
- package/aot/compiler/package/tables.mjs +127 -0
- package/aot/compiler/package/vectors.mjs +502 -0
- package/aot/compiler/package/writer.mjs +686 -0
- package/aot/compiler/pan-responder.mjs +69 -61
- package/aot/compiler/parse.mjs +23 -21
- package/aot/compiler/record-shapes.mjs +246 -0
- package/aot/compiler/records.mjs +654 -0
- package/aot/compiler/reducers.mjs +272 -0
- package/aot/compiler/static-eval.mjs +340 -30
- package/aot/compiler/style-text.mjs +178 -174
- package/aot/compiler/svg.mjs +480 -251
- package/aot/compiler/switch-cases.mjs +198 -0
- package/aot/compiler/tagged-records.mjs +450 -0
- package/aot/compiler/typing.mjs +307 -0
- package/aot/compiler/updaters.mjs +320 -0
- package/aot/compiler/window-dimensions.mjs +94 -0
- package/aot/compiler/worked-values.mjs +319 -0
- package/aot/demo-file.mjs +30 -0
- package/aot/screenshot-smoke.mjs +54 -40
- package/aot/style-map.mjs +152 -92
- package/assets/bake-font.mjs +123 -77
- package/assets/bake-image.mjs +39 -22
- package/assets/bake-svg.mjs +361 -262
- package/assets/build-builtin-font.mjs +11 -7
- package/assets/emit-c.mjs +77 -58
- package/assets/emit-container.mjs +123 -37
- package/assets/emit-pack.mjs +77 -67
- package/assets/font-config.mjs +9 -6
- package/assets/font-sizes.mjs +163 -123
- package/assets/glyph-coverage.mjs +74 -54
- package/assets/index.mjs +31 -9
- package/assets/rasterize.mjs +126 -99
- package/assets/svg-loader.mjs +8 -8
- package/build.mjs +23 -13
- package/cli.mjs +402 -172
- package/compile-bin.mjs +3 -3
- package/flash.mjs +537 -0
- package/hotreload/dev-device.mjs +90 -33
- package/hotreload/pack-app.mjs +55 -43
- package/hotreload/pack-split.mjs +62 -64
- package/hotreload/package-transfer.mjs +175 -0
- package/hotreload/protocol.mjs +50 -37
- package/hotreload/uploader.mjs +38 -27
- package/hotreload/watch-tree.mjs +19 -19
- package/pack-container.mjs +37 -21
- package/package.json +7 -8
- package/persist-transform.mjs +34 -28
- package/qjsc-wasm.mjs +25 -14
- package/sim/embedded-react.cjs +1 -1
- package/sim/embedded-react.js +1 -1
- package/sim/embedded-react.wasm +0 -0
- package/sim/index.html +94 -85
- package/sim-server.mjs +113 -94
- package/src/embedded-react/Animated.js +24 -24
- package/src/embedded-react/Dimensions.js +37 -0
- package/src/embedded-react/Easing.js +1 -1
- package/src/embedded-react/FlatList.js +3 -3
- package/src/embedded-react/LayoutAnimation.js +8 -5
- package/src/embedded-react/PanResponder.js +75 -71
- package/src/embedded-react/Pressable.js +2 -8
- package/src/embedded-react/SectionList.js +7 -9
- package/src/embedded-react/StyleSheet.js +4 -3
- package/src/embedded-react/TouchableOpacity.js +13 -8
- package/src/embedded-react/index.d.ts +88 -8
- package/src/embedded-react/index.js +2 -0
- package/src/embedded-react/layout-anim-config.js +10 -4
- package/src/embedded-react/list-child.js +5 -5
- package/src/embedded-react/named-colors.js +1 -1
- package/src/embedded-react/nativeModule.js +462 -0
- package/src/embedded-react/split-style.js +11 -11
- package/src/embedded-react/svg-ops.js +760 -593
- package/src/embedded-react/useHostValue.js +3 -3
- package/src/embedded-react/usePersistentState.js +6 -6
- package/src/embedded-react/warn-props.js +1 -1
- package/src/host-config.js +60 -53
- package/src/props.js +49 -41
- package/src/renderer.js +7 -4
- package/aot/compiler/assemble.mjs +0 -944
- package/aot/compiler/c/animations.mjs +0 -436
- package/aot/compiler/c/boot.mjs +0 -127
- package/aot/compiler/c/expressions.mjs +0 -270
- package/aot/compiler/c/functions.mjs +0 -268
- package/aot/compiler/c/keyboard.mjs +0 -96
- package/aot/compiler/c/nodes.mjs +0 -303
- package/aot/compiler/c/pan-responder.mjs +0 -136
- package/aot/compiler/c/statements.mjs +0 -319
- package/aot/compiler/c/text.mjs +0 -83
- package/aot/compiler/c/vectors.mjs +0 -381
- package/aot/compiler/c-syntax.mjs +0 -127
|
@@ -20,23 +20,23 @@ import { check, checkNumber } from './check.mjs';
|
|
|
20
20
|
import { aotError } from './diagnostics.mjs';
|
|
21
21
|
import { evalStaticOrThrow, evalStatic, foldScope, evalStaticOr, } from './static-eval.mjs';
|
|
22
22
|
import { INT_MAX, lowerExpr } from './expressions.mjs';
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
23
|
+
import { isFn, wideInitial } from './collect.mjs';
|
|
24
|
+
import { lowerBody } from './handlers.mjs';
|
|
25
25
|
import { isPanCreate } from './pan-responder.mjs';
|
|
26
26
|
import { parseColorValue } from '../style-map.mjs';
|
|
27
27
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
28
28
|
- Constants
|
|
29
29
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
30
30
|
/** The style keys an animated value drives only through an interpolation onto colors. */
|
|
31
|
-
export const
|
|
32
|
-
/** Style key → the
|
|
33
|
-
export const
|
|
31
|
+
export const ANIMATED_COLOR_KEYS = new Set(['backgroundColor', 'color']);
|
|
32
|
+
/** Style key → the ERAnimationProp(s) an animated value binds to. */
|
|
33
|
+
export const ANIMATED_STYLE_PROPS = {
|
|
34
34
|
opacity: ['ER_PROP_OPACITY'],
|
|
35
35
|
backgroundColor: ['ER_PROP_BACKGROUND_COLOR'],
|
|
36
36
|
color: ['ER_PROP_COLOR'],
|
|
37
37
|
};
|
|
38
|
-
/** Transform key → the
|
|
39
|
-
export const
|
|
38
|
+
/** Transform key → the ERAnimationProp(s) an animated value binds to. */
|
|
39
|
+
export const ANIMATED_TRANSFORM_PROPS = {
|
|
40
40
|
scale: ['ER_PROP_SCALE_X', 'ER_PROP_SCALE_Y'],
|
|
41
41
|
scaleX: ['ER_PROP_SCALE_X'],
|
|
42
42
|
scaleY: ['ER_PROP_SCALE_Y'],
|
|
@@ -45,7 +45,7 @@ export const ANIM_TRANSFORM_PROPS = {
|
|
|
45
45
|
rotate: ['ER_PROP_ROTATE_Z'],
|
|
46
46
|
rotateZ: ['ER_PROP_ROTATE_Z'],
|
|
47
47
|
};
|
|
48
|
-
const
|
|
48
|
+
const ANIMATION_KINDS = new Set([
|
|
49
49
|
'timing',
|
|
50
50
|
'spring',
|
|
51
51
|
'decay',
|
|
@@ -55,130 +55,138 @@ const ANIM_KINDS = new Set([
|
|
|
55
55
|
'delay',
|
|
56
56
|
'loop',
|
|
57
57
|
]);
|
|
58
|
+
// What an Animated config's field is when the app leaves it out, as React Native has it.
|
|
59
|
+
const DEFAULT_TIMING_DURATION_MS = 250;
|
|
60
|
+
const DEFAULT_SPRING_STIFFNESS = 200;
|
|
61
|
+
const DEFAULT_SPRING_DAMPING = 18;
|
|
62
|
+
const DEFAULT_DECAY_DECELERATION = 0.998;
|
|
63
|
+
/** The numbers Easing.bezier takes: x1, y1, x2, y2. */
|
|
64
|
+
const BEZIER_CONTROL_POINTS = 4;
|
|
65
|
+
/** Most descriptors one started tree may have (the runtime's ERB_MAX_ANIM_TREE): a group, its animations, its wait. */
|
|
66
|
+
const MAX_GROUP_ENTRIES = 32;
|
|
58
67
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
59
68
|
- Implementation
|
|
60
69
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
61
70
|
/**
|
|
62
|
-
* Collects `const x = useAnimatedValue(initial)` → Map (name → {
|
|
63
|
-
*
|
|
71
|
+
* Collects `const x = useAnimatedValue(initial)` → Map (name → {slotName, initial}). `prefix` namespaces the
|
|
72
|
+
* handle (`anim_<prefix><name>`) so each inlined child instance gets its own engine value handle.
|
|
64
73
|
*
|
|
65
|
-
* @param
|
|
74
|
+
* @param functionBody The component's body.
|
|
66
75
|
* @param scope Compile-time constants the initial values fold against.
|
|
67
|
-
* @param prefix The
|
|
76
|
+
* @param prefix The name prefix: none for the App, `c<n>_` for an inlined instance.
|
|
68
77
|
*
|
|
69
78
|
* @returns The animated values, by name.
|
|
70
79
|
*/
|
|
71
|
-
export function collectAnims(
|
|
80
|
+
export function collectAnims(functionBody, scope, prefix = '') {
|
|
72
81
|
// Collect animated value records by their JS binding name.
|
|
73
|
-
const
|
|
82
|
+
const animations = new Map();
|
|
74
83
|
// Only block-bodied functions can contain hook declarations to collect.
|
|
75
|
-
if (
|
|
76
|
-
return
|
|
84
|
+
if (functionBody.type !== 'BlockStatement')
|
|
85
|
+
return animations;
|
|
77
86
|
// Scan top-level declarations in the function body for useAnimatedValue hooks to allocate animated slots.
|
|
78
|
-
for (const
|
|
87
|
+
for (const statement of functionBody.body) {
|
|
79
88
|
// Only variable declarations can introduce bindings we need to inspect.
|
|
80
|
-
if (
|
|
89
|
+
if (statement.type !== 'VariableDeclaration')
|
|
81
90
|
continue;
|
|
82
91
|
// Collect useAnimatedValue declarations and register their engine-side animated slots.
|
|
83
|
-
for (const
|
|
84
|
-
const
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
? evalStaticOrThrow(
|
|
92
|
+
for (const declarator of statement.declarations) {
|
|
93
|
+
const initializer = declarator.init;
|
|
94
|
+
if (initializer?.type === 'CallExpression' &&
|
|
95
|
+
initializer.callee.name === 'useAnimatedValue' &&
|
|
96
|
+
declarator.id.type === 'Identifier') {
|
|
97
|
+
const initialValue = initializer.arguments[0]
|
|
98
|
+
? evalStaticOrThrow(initializer.arguments[0], scope, `AOT: the initial value of useAnimatedValue "${declarator.id.name}" must be a compile-time constant`, 'give it a finite starting number: useAnimatedValue(0).')
|
|
90
99
|
: 0;
|
|
91
|
-
// An animated value is a float slot
|
|
100
|
+
// An animated value is a float slot, which null or a non-finite number doesn't fit.
|
|
92
101
|
// Refuse here, at the declaration, with its location.
|
|
93
|
-
if (typeof
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
102
|
+
if (typeof initialValue !== 'number' ||
|
|
103
|
+
!Number.isFinite(initialValue)) {
|
|
104
|
+
const error = aotError(`AOT: the initial value of useAnimatedValue "${declarator.id.name}" is ${initialValue === undefined ? 'undefined' : String(initialValue)}`, 'give it a finite starting number: useAnimatedValue(0).');
|
|
105
|
+
if (initializer.arguments[0]?.loc) {
|
|
106
|
+
error.aotLoc = initializer.arguments[0].loc.start;
|
|
97
107
|
}
|
|
98
|
-
throw
|
|
108
|
+
throw error;
|
|
99
109
|
}
|
|
100
|
-
checkNumber(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
initial:
|
|
110
|
+
checkNumber(initialValue);
|
|
111
|
+
animations.set(declarator.id.name, {
|
|
112
|
+
slotName: `anim_${prefix}${declarator.id.name}`,
|
|
113
|
+
initial: initialValue,
|
|
104
114
|
});
|
|
105
115
|
}
|
|
106
116
|
}
|
|
107
117
|
}
|
|
108
|
-
return
|
|
118
|
+
return animations;
|
|
109
119
|
}
|
|
110
120
|
/**
|
|
111
|
-
* Collects `const r = useRef(initial)` refs → Map (name → {
|
|
112
|
-
* - VALUE ref (numeric initial): a mutable
|
|
121
|
+
* Collects `const r = useRef(initial)` refs → Map (name → {slotName, slotKind, initial, kind}). Two kinds:
|
|
122
|
+
* - VALUE ref (numeric initial): a mutable slot (escape-hatch state that does NOT re-render;
|
|
113
123
|
* `.current` reads/writes).
|
|
114
|
-
* - NODE ref (`useRef()` / `useRef(null)`): holds an
|
|
124
|
+
* - NODE ref (`useRef()` / `useRef(null)`): holds an node handle, captured by `ref={r}` on an element and
|
|
115
125
|
* used as the target of imperative calls like updateVector(r, …). kind === 'node'.
|
|
116
126
|
*
|
|
117
|
-
* @param
|
|
127
|
+
* @param functionBody The component's body.
|
|
118
128
|
* @param scope Compile-time constants the initial values fold against.
|
|
119
|
-
* @param prefix The
|
|
120
|
-
* @param wide Slots to declare 64-bit (see compileWidened).
|
|
129
|
+
* @param prefix The name prefix: none for the App, `c<n>_` for an inlined instance.
|
|
121
130
|
*
|
|
122
131
|
* @returns The refs, by name.
|
|
123
132
|
*/
|
|
124
|
-
export function collectRefs(
|
|
133
|
+
export function collectRefs(functionBody, scope, prefix = '') {
|
|
125
134
|
// Collect ref records by their JS binding name.
|
|
126
135
|
const refs = new Map();
|
|
127
136
|
// Only block-bodied functions can contain ref declarations to collect.
|
|
128
|
-
if (
|
|
137
|
+
if (functionBody.type !== 'BlockStatement')
|
|
129
138
|
return refs;
|
|
130
139
|
// Collect useRef declarations, splitting null/empty node refs from numeric value refs.
|
|
131
|
-
for (const
|
|
140
|
+
for (const statement of functionBody.body) {
|
|
132
141
|
// Only variable declarations can introduce bindings we need to inspect.
|
|
133
|
-
if (
|
|
142
|
+
if (statement.type !== 'VariableDeclaration')
|
|
134
143
|
continue;
|
|
135
144
|
// Find useRef bindings and lower each supported initializer to either a node ref or value ref record.
|
|
136
|
-
for (const
|
|
137
|
-
const
|
|
138
|
-
if (
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const
|
|
145
|
+
for (const declarator of statement.declarations) {
|
|
146
|
+
const initializer = declarator.init;
|
|
147
|
+
if (initializer?.type === 'CallExpression' &&
|
|
148
|
+
initializer.callee.name === 'useRef' &&
|
|
149
|
+
declarator.id.type === 'Identifier') {
|
|
150
|
+
const argument = initializer.arguments[0];
|
|
142
151
|
// A PanResponder ref — collectPanResponders owns it
|
|
143
|
-
if (isPanCreate(
|
|
152
|
+
if (isPanCreate(argument))
|
|
144
153
|
continue;
|
|
145
154
|
// Empty or null useRef values are node refs, initialized to no bound ERNode.
|
|
146
|
-
const
|
|
147
|
-
if (!
|
|
148
|
-
refs.set(
|
|
149
|
-
|
|
150
|
-
|
|
155
|
+
const slotName = `ref_${prefix}${declarator.id.name}`;
|
|
156
|
+
if (!argument || argument.type === 'NullLiteral') {
|
|
157
|
+
refs.set(declarator.id.name, {
|
|
158
|
+
slotName,
|
|
159
|
+
slotKind: 'node',
|
|
151
160
|
kind: 'node',
|
|
152
161
|
used: false,
|
|
153
162
|
});
|
|
154
163
|
continue;
|
|
155
164
|
}
|
|
156
165
|
// Value refs must start from a finite compile-time number.
|
|
157
|
-
const value = evalStaticOrThrow(
|
|
166
|
+
const value = evalStaticOrThrow(argument, scope, `AOT: useRef initial for "${declarator.id.name}" must be a number (value ref) or null/empty (node ref)`, 'a value ref needs a compile-time number: useRef(0).');
|
|
158
167
|
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
159
|
-
const error = aotError(`AOT: useRef initial for "${
|
|
160
|
-
if (
|
|
161
|
-
error.aotLoc =
|
|
168
|
+
const error = aotError(`AOT: useRef initial for "${declarator.id.name}" must be a number (value ref) or null/empty (node ref)`, `got ${value === undefined ? 'undefined' : String(value)}.`);
|
|
169
|
+
if (argument.loc) {
|
|
170
|
+
error.aotLoc = argument.loc.start;
|
|
162
171
|
}
|
|
163
172
|
throw error;
|
|
164
173
|
}
|
|
165
|
-
// A ref
|
|
174
|
+
// A ref that starts past the int range holds 64 bits; one a timestamp is written to is widened later.
|
|
166
175
|
const initialWidth = wideInitial(value);
|
|
167
|
-
const widened = Number.isInteger(value) && initialWidth
|
|
168
|
-
?
|
|
169
|
-
(initialWidth === 'number' ? 'number' : undefined))
|
|
176
|
+
const widened = Number.isInteger(value) && initialWidth === 'number'
|
|
177
|
+
? 'number'
|
|
170
178
|
: undefined;
|
|
171
|
-
const
|
|
179
|
+
const slotKind = !Number.isInteger(value) || initialWidth === 'float'
|
|
172
180
|
? 'float'
|
|
173
181
|
: widened
|
|
174
182
|
? 'i64'
|
|
175
183
|
: 'int';
|
|
176
|
-
if (
|
|
184
|
+
if (slotKind === 'float') {
|
|
177
185
|
checkNumber(value);
|
|
178
186
|
}
|
|
179
|
-
refs.set(
|
|
180
|
-
|
|
181
|
-
|
|
187
|
+
refs.set(declarator.id.name, {
|
|
188
|
+
slotName,
|
|
189
|
+
slotKind,
|
|
182
190
|
initial: value,
|
|
183
191
|
kind: 'value',
|
|
184
192
|
used: false,
|
|
@@ -212,11 +220,11 @@ function easingFamily(node) {
|
|
|
212
220
|
* Easing.bezier(x1,y1,x2,y2). No easing → ER_EASE_EASE_IN_OUT (RN's timing default); unknown → same.
|
|
213
221
|
*
|
|
214
222
|
* @param node The `easing:` expression, if there is one.
|
|
215
|
-
* @param
|
|
223
|
+
* @param environment The expression environment for folding bezier control points.
|
|
216
224
|
*
|
|
217
225
|
* @returns The engine easing, and its control points when it is a bezier.
|
|
218
226
|
*/
|
|
219
|
-
function easingInfo(node,
|
|
227
|
+
function easingInfo(node, environment) {
|
|
220
228
|
// Use React Native's timing default whenever no easing is supplied (or the expression is unsupported).
|
|
221
229
|
const FALLBACK = { ease: 'ER_EASE_EASE_IN_OUT', bezier: null };
|
|
222
230
|
if (!node)
|
|
@@ -241,22 +249,24 @@ function easingInfo(node, env) {
|
|
|
241
249
|
if (node.type === 'CallExpression' &&
|
|
242
250
|
node.callee.type === 'MemberExpression' &&
|
|
243
251
|
node.callee.object?.name === 'Easing') {
|
|
244
|
-
const
|
|
245
|
-
if (
|
|
246
|
-
const
|
|
247
|
-
.slice(0,
|
|
248
|
-
.map(
|
|
249
|
-
return
|
|
250
|
-
? { ease: 'ER_EASE_BEZIER', bezier:
|
|
252
|
+
const easing = node.callee.property.name;
|
|
253
|
+
if (easing === 'bezier') {
|
|
254
|
+
const controlPoints = node.arguments
|
|
255
|
+
.slice(0, BEZIER_CONTROL_POINTS)
|
|
256
|
+
.map(argument => Number(evalStaticOr(argument, environment, 0)));
|
|
257
|
+
return controlPoints.length === BEZIER_CONTROL_POINTS
|
|
258
|
+
? { ease: 'ER_EASE_BEZIER', bezier: controlPoints }
|
|
251
259
|
: FALLBACK;
|
|
252
260
|
}
|
|
253
|
-
if (
|
|
261
|
+
if (easing === 'elastic') {
|
|
254
262
|
return { ease: 'ER_EASE_ELASTIC_OUT', bezier: null };
|
|
255
263
|
}
|
|
256
|
-
if (
|
|
257
|
-
const
|
|
258
|
-
const
|
|
259
|
-
return
|
|
264
|
+
if (easing === 'in' || easing === 'out' || easing === 'inOut') {
|
|
265
|
+
const family = easingFamily(node.arguments[0]);
|
|
266
|
+
const direction = easing === 'in' ? 'IN' : easing === 'out' ? 'OUT' : 'IN_OUT';
|
|
267
|
+
return family
|
|
268
|
+
? { ease: `ER_EASE_${family}_${direction}`, bezier: null }
|
|
269
|
+
: FALLBACK;
|
|
260
270
|
}
|
|
261
271
|
}
|
|
262
272
|
return FALLBACK;
|
|
@@ -265,42 +275,42 @@ function easingInfo(node, env) {
|
|
|
265
275
|
* Parses a `.interpolate({ inputRange, outputRange, extrapolate })` config object → a static
|
|
266
276
|
* { input, output, exLeft, exRight } descriptor (ranges must be static, equal-length, 2..8 points).
|
|
267
277
|
*
|
|
268
|
-
* @param
|
|
269
|
-
* @param
|
|
278
|
+
* @param configNode The config argument.
|
|
279
|
+
* @param environment The expression environment.
|
|
270
280
|
*
|
|
271
281
|
* @returns The folded interpolation.
|
|
272
282
|
*/
|
|
273
|
-
export function parseInterp(
|
|
274
|
-
// Interpolation ranges must be known at compile time so the
|
|
275
|
-
if (
|
|
283
|
+
export function parseInterp(configNode, environment) {
|
|
284
|
+
// Interpolation ranges must be known at compile time so the package can bake the breakpoints directly.
|
|
285
|
+
if (configNode?.type !== 'ObjectExpression') {
|
|
276
286
|
throw aotError('AOT: .interpolate() needs a config object literal { inputRange, outputRange }');
|
|
277
287
|
}
|
|
278
288
|
// Read a named property from the interpolation config, accepting both identifier and string-literal keys.
|
|
279
|
-
const get = (key) =>
|
|
289
|
+
const get = (key) => configNode.properties.find(property => (property.key.name ??
|
|
280
290
|
property.key.value) === key)?.value;
|
|
281
291
|
// Fold an interpolation range into its breakpoints; ranges must be array literals for AOT emission.
|
|
282
292
|
const arr = (node, name) => {
|
|
283
293
|
if (node?.type !== 'ArrayExpression') {
|
|
284
294
|
throw aotError(`AOT: .interpolate() ${name} must be an array literal`);
|
|
285
295
|
}
|
|
286
|
-
return node.elements.map(
|
|
296
|
+
return node.elements.map(element => evalStatic(element, environment.constants ?? {}));
|
|
287
297
|
};
|
|
288
298
|
// inputRange and outputRange define the piecewise mapping and must line up point-for-point. An
|
|
289
299
|
// outputRange of strings maps onto colors.
|
|
290
300
|
const input = arr(get('inputRange'), 'inputRange').map(Number);
|
|
291
301
|
const outputValues = arr(get('outputRange'), 'outputRange');
|
|
292
302
|
// Colors parse as strictly as a static style color, so a typo is an error rather than black.
|
|
293
|
-
const colors = outputValues.every(
|
|
294
|
-
? outputValues.map(
|
|
303
|
+
const colors = outputValues.every(value => typeof value === 'string')
|
|
304
|
+
? outputValues.map(color => {
|
|
295
305
|
try {
|
|
296
|
-
return parseColorValue(
|
|
306
|
+
return parseColorValue(color);
|
|
297
307
|
}
|
|
298
308
|
catch (error) {
|
|
299
309
|
throw aotError(`AOT: .interpolate() outputRange has an ${error.message}`);
|
|
300
310
|
}
|
|
301
311
|
})
|
|
302
312
|
: undefined;
|
|
303
|
-
if (!colors && outputValues.some(
|
|
313
|
+
if (!colors && outputValues.some(value => typeof value !== 'number')) {
|
|
304
314
|
throw aotError('AOT: .interpolate() outputRange must be all numbers or all colors');
|
|
305
315
|
}
|
|
306
316
|
const output = colors ? [] : outputValues;
|
|
@@ -311,7 +321,7 @@ export function parseInterp(cfgNode, env) {
|
|
|
311
321
|
// Convert RN extrapolation strings to engine enum names, defaulting to extend like React Native.
|
|
312
322
|
const ex = (node) => {
|
|
313
323
|
const extrapolateMode = node
|
|
314
|
-
? String(evalStaticOr(node,
|
|
324
|
+
? String(evalStaticOr(node, environment, 'extend'))
|
|
315
325
|
: 'extend';
|
|
316
326
|
return extrapolateMode === 'clamp'
|
|
317
327
|
? 'ER_EXTRAPOLATE_CLAMP'
|
|
@@ -325,23 +335,23 @@ export function parseInterp(cfgNode, env) {
|
|
|
325
335
|
input,
|
|
326
336
|
output,
|
|
327
337
|
...(colors && { colors }),
|
|
328
|
-
|
|
329
|
-
|
|
338
|
+
extrapolateLeft: ex(get('extrapolateLeft') ?? both),
|
|
339
|
+
extrapolateRight: ex(get('extrapolateRight') ?? both),
|
|
330
340
|
};
|
|
331
341
|
}
|
|
332
342
|
/**
|
|
333
343
|
* Builds a `get(key)` accessor over an `Animated.*(value, config)` call's config object literal.
|
|
334
344
|
*
|
|
335
|
-
* @param
|
|
345
|
+
* @param configObject The config argument, if there is one.
|
|
336
346
|
*
|
|
337
347
|
* @returns The accessor; it reads undefined for every key when there is no config.
|
|
338
348
|
*/
|
|
339
|
-
function animConfigGetter(
|
|
340
|
-
return key =>
|
|
349
|
+
function animConfigGetter(configObject) {
|
|
350
|
+
return key => configObject?.properties?.find(property => (property.key.name ??
|
|
341
351
|
property.key.value) === key)?.value;
|
|
342
352
|
}
|
|
343
353
|
/**
|
|
344
|
-
* A folded config number that will be printed as a float, checked now so a value
|
|
354
|
+
* A folded config number that will be printed as a float, checked now so a value a float can't hold is reported
|
|
345
355
|
* where the animation is lowered.
|
|
346
356
|
*
|
|
347
357
|
* @param rawValue The folded value.
|
|
@@ -353,17 +363,17 @@ function configFloat(rawValue) {
|
|
|
353
363
|
return Number(rawValue);
|
|
354
364
|
}
|
|
355
365
|
/**
|
|
356
|
-
* A folded config time in whole milliseconds, checked so a time
|
|
366
|
+
* A folded config time in whole milliseconds, checked so a time too long to hold is reported at the field.
|
|
357
367
|
*
|
|
358
368
|
* @param node The field's value, if the app wrote one.
|
|
359
|
-
* @param
|
|
369
|
+
* @param environment The expression environment.
|
|
360
370
|
* @param defaultValue The time when the field is left out or not known at build time.
|
|
361
371
|
* @param field What the time is, for the error.
|
|
362
372
|
*
|
|
363
373
|
* @returns The time.
|
|
364
374
|
*/
|
|
365
|
-
function configMs(node,
|
|
366
|
-
const rawValue = evalStaticOr(node,
|
|
375
|
+
function configMs(node, environment, defaultValue, field) {
|
|
376
|
+
const rawValue = evalStaticOr(node, environment, defaultValue);
|
|
367
377
|
check({ kind: 'milliseconds', field, value: rawValue }, node?.loc?.start);
|
|
368
378
|
return Math.round(Number(rawValue));
|
|
369
379
|
}
|
|
@@ -371,21 +381,21 @@ function configMs(node, env, defaultValue, field) {
|
|
|
371
381
|
* A timing's folded duration (250 ms when it is left out, as in React Native).
|
|
372
382
|
*
|
|
373
383
|
* @param get The timing's config.
|
|
374
|
-
* @param
|
|
384
|
+
* @param environment The expression environment.
|
|
375
385
|
*
|
|
376
386
|
* @returns The duration.
|
|
377
387
|
*/
|
|
378
|
-
const timingDuration = (get,
|
|
388
|
+
const timingDuration = (get, environment) => configMs(get('duration'), environment, DEFAULT_TIMING_DURATION_MS, `Animated.timing's "duration"`);
|
|
379
389
|
/**
|
|
380
390
|
* An animation's own delay (0 when it is left out).
|
|
381
391
|
*
|
|
382
392
|
* @param kind timing, spring or decay.
|
|
383
393
|
* @param get The animation's config.
|
|
384
|
-
* @param
|
|
394
|
+
* @param environment The expression environment.
|
|
385
395
|
*
|
|
386
396
|
* @returns The delay.
|
|
387
397
|
*/
|
|
388
|
-
const ownDelayMs = (kind, get,
|
|
398
|
+
const ownDelayMs = (kind, get, environment) => configMs(get('delay'), environment, 0, `Animated.${kind}'s "delay"`);
|
|
389
399
|
/**
|
|
390
400
|
* A time added up from a composition's times, checked like them: each fits an int, but a sum of them need not.
|
|
391
401
|
*
|
|
@@ -402,32 +412,32 @@ function totalMs(value) {
|
|
|
402
412
|
* offsets are realized) and `loop` repeats a timing on the engine's own loop.
|
|
403
413
|
*
|
|
404
414
|
* @param entry The animation.
|
|
405
|
-
* @param
|
|
415
|
+
* @param environment The expression environment.
|
|
406
416
|
*
|
|
407
417
|
* @returns The animation.
|
|
408
418
|
*/
|
|
409
|
-
function lowerAnimation(entry,
|
|
410
|
-
const {
|
|
419
|
+
function lowerAnimation(entry, environment) {
|
|
420
|
+
const { slotName, kind, get, delayMs, loop } = entry;
|
|
411
421
|
// Fold the curve's fields, using RN-like defaults when the app leaves one out.
|
|
412
422
|
let curve;
|
|
413
423
|
if (kind === 'spring') {
|
|
414
424
|
curve = {
|
|
415
425
|
kind: 'spring',
|
|
416
|
-
stiffness: configFloat(evalStaticOr(get('stiffness'),
|
|
417
|
-
damping: configFloat(evalStaticOr(get('damping'),
|
|
418
|
-
mass: configFloat(evalStaticOr(get('mass'),
|
|
426
|
+
stiffness: configFloat(evalStaticOr(get('stiffness'), environment, DEFAULT_SPRING_STIFFNESS)),
|
|
427
|
+
damping: configFloat(evalStaticOr(get('damping'), environment, DEFAULT_SPRING_DAMPING)),
|
|
428
|
+
mass: configFloat(evalStaticOr(get('mass'), environment, 1)),
|
|
419
429
|
};
|
|
420
430
|
}
|
|
421
431
|
else if (kind === 'decay') {
|
|
422
432
|
curve = {
|
|
423
433
|
kind: 'decay',
|
|
424
|
-
deceleration: configFloat(evalStaticOr(get('deceleration'),
|
|
425
|
-
velocity: configFloat(evalStaticOr(get('velocity'),
|
|
434
|
+
deceleration: configFloat(evalStaticOr(get('deceleration'), environment, DEFAULT_DECAY_DECELERATION)),
|
|
435
|
+
velocity: configFloat(evalStaticOr(get('velocity'), environment, 0)),
|
|
426
436
|
};
|
|
427
437
|
}
|
|
428
438
|
else {
|
|
429
|
-
const durationMs = timingDuration(get,
|
|
430
|
-
const { ease, bezier } = easingInfo(get('easing'),
|
|
439
|
+
const durationMs = timingDuration(get, environment);
|
|
440
|
+
const { ease, bezier } = easingInfo(get('easing'), environment);
|
|
431
441
|
curve = {
|
|
432
442
|
kind: 'timing',
|
|
433
443
|
durationMs,
|
|
@@ -441,47 +451,237 @@ function lowerAnimation(entry, env) {
|
|
|
441
451
|
throw aotError(`AOT: Animated.${kind}() config needs a toValue`);
|
|
442
452
|
}
|
|
443
453
|
return {
|
|
444
|
-
handle:
|
|
454
|
+
handle: slotName,
|
|
445
455
|
curve,
|
|
446
|
-
to: toNode ? lowerExpr(toNode,
|
|
456
|
+
to: toNode ? lowerExpr(toNode, environment) : null,
|
|
447
457
|
delayMs: totalMs(delayMs),
|
|
448
458
|
isLooping: loop,
|
|
449
459
|
};
|
|
450
460
|
}
|
|
461
|
+
/**
|
|
462
|
+
* The latest a composition's delays end, when that may be after its animations do: what a group waits on.
|
|
463
|
+
*
|
|
464
|
+
* @param flat The flattened composition.
|
|
465
|
+
* @param environment The expression environment.
|
|
466
|
+
*
|
|
467
|
+
* @returns The wait from the composition's start, or null when an animation is known to end last.
|
|
468
|
+
*/
|
|
469
|
+
function outlastingDelay(flat, environment) {
|
|
470
|
+
const lastKnownEnd = Math.max(0, ...flat.entries.map(animationEntry => animationEntry.delayMs +
|
|
471
|
+
(animationEntry.kind === 'timing'
|
|
472
|
+
? timingDuration(animationEntry.get, environment)
|
|
473
|
+
: 0)));
|
|
474
|
+
return flat.duration != null && flat.duration > lastKnownEnd
|
|
475
|
+
? flat.duration
|
|
476
|
+
: null;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* The handle of every value a sequence drives.
|
|
480
|
+
*
|
|
481
|
+
* @param sequence The sequence.
|
|
482
|
+
* @param accumulator Collects the handles.
|
|
483
|
+
*
|
|
484
|
+
* @returns `accumulator`.
|
|
485
|
+
*/
|
|
486
|
+
function sequenceValues(sequence, accumulator = new Set()) {
|
|
487
|
+
for (const step of sequence.steps) {
|
|
488
|
+
if (step.kind === 'animation') {
|
|
489
|
+
accumulator.add(step.entry.slotName);
|
|
490
|
+
}
|
|
491
|
+
else if (step.kind === 'group') {
|
|
492
|
+
for (const animationEntry of step.flat.entries) {
|
|
493
|
+
accumulator.add(animationEntry.slotName);
|
|
494
|
+
}
|
|
495
|
+
for (const nested of step.flat.sequences) {
|
|
496
|
+
sequenceValues(nested, accumulator);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
return accumulator;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Running-animation entries a sequence takes: its own, and one for each step, delay and animation in it.
|
|
504
|
+
*
|
|
505
|
+
* @param sequence The sequence.
|
|
506
|
+
* @param environment The expression environment.
|
|
507
|
+
*
|
|
508
|
+
* @returns The entries.
|
|
509
|
+
*/
|
|
510
|
+
function sequenceEntries(sequence, environment) {
|
|
511
|
+
let count = 1;
|
|
512
|
+
for (const step of sequence.steps) {
|
|
513
|
+
if (step.kind !== 'group') {
|
|
514
|
+
count++;
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
count +=
|
|
518
|
+
1 +
|
|
519
|
+
(outlastingDelay(step.flat, environment) == null ? 0 : 1) +
|
|
520
|
+
step.flat.entries.length;
|
|
521
|
+
for (const nested of step.flat.sequences) {
|
|
522
|
+
count += sequenceEntries(nested, environment);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return count;
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Lowers a sequence that runs inside a parallel or stagger.
|
|
529
|
+
*
|
|
530
|
+
* @param sequence The sequence.
|
|
531
|
+
* @param environment The expression environment.
|
|
532
|
+
*
|
|
533
|
+
* @returns The sequence.
|
|
534
|
+
*/
|
|
535
|
+
function lowerSequence(sequence, environment) {
|
|
536
|
+
return {
|
|
537
|
+
steps: sequence.steps.map(step => {
|
|
538
|
+
if (step.kind === 'animation') {
|
|
539
|
+
return {
|
|
540
|
+
kind: 'animation',
|
|
541
|
+
animation: lowerAnimation(step.entry, environment),
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
if (step.kind === 'delay') {
|
|
545
|
+
return { kind: 'delay', delayMs: totalMs(step.delayMs) };
|
|
546
|
+
}
|
|
547
|
+
const waitMs = outlastingDelay(step.flat, environment);
|
|
548
|
+
return {
|
|
549
|
+
kind: 'group',
|
|
550
|
+
stopsTogether: step.stopsTogether,
|
|
551
|
+
animations: step.flat.entries.map(animationEntry => lowerAnimation(animationEntry, environment)),
|
|
552
|
+
sequences: step.flat.sequences.map(nested => lowerSequence(nested, environment)),
|
|
553
|
+
waitMs: waitMs == null ? null : totalMs(waitMs),
|
|
554
|
+
};
|
|
555
|
+
}),
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Flattens a sequence inside another composition. One with a single animation is that animation, delayed. Any
|
|
560
|
+
* other runs step by step, each step started when the one before it finishes, so a step that is interrupted ends
|
|
561
|
+
* the sequence, the same value can take several steps, and a step needs no fixed length. A sequence inside it is
|
|
562
|
+
* part of it.
|
|
563
|
+
*
|
|
564
|
+
* @param sequenceNode The sequence call.
|
|
565
|
+
* @param environment The expression environment.
|
|
566
|
+
* @param baseDelay When the sequence starts, in ms.
|
|
567
|
+
* @param loop The sequence repeats forever (inside an Animated.loop).
|
|
568
|
+
*
|
|
569
|
+
* @returns Its entries, or the sequence, and its run length.
|
|
570
|
+
*/
|
|
571
|
+
function flattenSequence(sequenceNode, environment, baseDelay, loop) {
|
|
572
|
+
const steps = [];
|
|
573
|
+
// The delays not yet given to a step: a step's own delay takes them, and a group has a delay step before it.
|
|
574
|
+
let pendingDelay = baseDelay;
|
|
575
|
+
const collect = (node) => {
|
|
576
|
+
const list = node.arguments[0];
|
|
577
|
+
if (list?.type !== 'ArrayExpression') {
|
|
578
|
+
throw aotError('AOT: Animated.sequence(...) needs an array of animations');
|
|
579
|
+
}
|
|
580
|
+
for (const element of list.elements) {
|
|
581
|
+
if (!element)
|
|
582
|
+
continue;
|
|
583
|
+
const child = resolveAnim(element, environment);
|
|
584
|
+
if (!isAnimatedCall(child)) {
|
|
585
|
+
throw aotError('AOT: an animation must be Animated.timing/spring/decay/sequence/parallel/stagger/delay/loop(...)');
|
|
586
|
+
}
|
|
587
|
+
const kind = child.callee.property.name;
|
|
588
|
+
if (kind === 'sequence') {
|
|
589
|
+
collect(child);
|
|
590
|
+
}
|
|
591
|
+
else if (kind === 'loop') {
|
|
592
|
+
throw aotError('AOT: an Animated.loop inside an Animated.sequence is not supported', 'a loop around a sequence works when the loop is the animation you start: Animated.loop(Animated.sequence([...])).start().');
|
|
593
|
+
}
|
|
594
|
+
else if (kind === 'parallel' || kind === 'stagger') {
|
|
595
|
+
const flat = flattenAnim(child, environment, 0, loop);
|
|
596
|
+
if (!flat.entries.length && !flat.sequences.length) {
|
|
597
|
+
pendingDelay += flat.duration ?? 0;
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
if (pendingDelay > 0) {
|
|
601
|
+
steps.push({ kind: 'delay', delayMs: pendingDelay });
|
|
602
|
+
pendingDelay = 0;
|
|
603
|
+
}
|
|
604
|
+
steps.push({
|
|
605
|
+
kind: 'group',
|
|
606
|
+
stopsTogether: stopsTogether(child, environment),
|
|
607
|
+
flat,
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
const flat = flattenAnim(child, environment, pendingDelay, loop);
|
|
612
|
+
if (flat.entries.length) {
|
|
613
|
+
steps.push({ kind: 'animation', entry: flat.entries[0] });
|
|
614
|
+
pendingDelay = 0;
|
|
615
|
+
}
|
|
616
|
+
else {
|
|
617
|
+
pendingDelay += flat.duration ?? 0;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
collect(sequenceNode);
|
|
623
|
+
// Delays alone start nothing.
|
|
624
|
+
if (!steps.length) {
|
|
625
|
+
return { entries: [], sequences: [], duration: pendingDelay - baseDelay };
|
|
626
|
+
}
|
|
627
|
+
// One animation needs no sequence, unless a delay follows an animation with no fixed length.
|
|
628
|
+
const [only] = steps;
|
|
629
|
+
if (steps.length === 1 &&
|
|
630
|
+
only.kind === 'animation' &&
|
|
631
|
+
(only.entry.kind === 'timing' || pendingDelay === 0)) {
|
|
632
|
+
const { entry } = only;
|
|
633
|
+
return {
|
|
634
|
+
entries: [entry],
|
|
635
|
+
sequences: [],
|
|
636
|
+
duration: entry.kind === 'timing'
|
|
637
|
+
? entry.delayMs -
|
|
638
|
+
baseDelay +
|
|
639
|
+
timingDuration(entry.get, environment) +
|
|
640
|
+
pendingDelay
|
|
641
|
+
: null,
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
if (pendingDelay > 0) {
|
|
645
|
+
steps.push({ kind: 'delay', delayMs: pendingDelay });
|
|
646
|
+
}
|
|
647
|
+
return { entries: [], sequences: [{ steps }], duration: null };
|
|
648
|
+
}
|
|
451
649
|
/**
|
|
452
650
|
* Flattens an Animated composition (timing/spring/decay/sequence/parallel/stagger/delay/loop) into a flat
|
|
453
|
-
* list of atomic entries, each with an ABSOLUTE start delay (ms) —
|
|
454
|
-
* per-entry delay_ms
|
|
455
|
-
* `duration` is this node's own run length in ms, used to offset
|
|
456
|
-
* null = unknown (spring/decay/loop)
|
|
651
|
+
* list of atomic entries, each with an ABSOLUTE start delay (ms) — a parallel or stagger is realized purely
|
|
652
|
+
* through per-entry delay_ms. A sequence of several steps inside one is kept whole instead (flattenSequence).
|
|
653
|
+
* Returns { entries, sequences, duration } where `duration` is this node's own run length in ms, used to offset
|
|
654
|
+
* later siblings in a stagger and to know what a completion waits on; null = unknown (spring/decay/loop).
|
|
457
655
|
*
|
|
458
656
|
* @param node The composition.
|
|
459
|
-
* @param
|
|
657
|
+
* @param environment The expression environment.
|
|
460
658
|
* @param baseDelay When the composition starts, in ms.
|
|
461
659
|
* @param loop The composition repeats forever (inside an Animated.loop).
|
|
462
660
|
*
|
|
463
661
|
* @returns Its atomic entries and its run length.
|
|
464
662
|
*/
|
|
465
|
-
function flattenAnim(node,
|
|
663
|
+
function flattenAnim(node, environment, baseDelay, loop) {
|
|
466
664
|
// Resolve a named animation handle, then require one of the supported Animated.* calls.
|
|
467
|
-
node = resolveAnim(node,
|
|
665
|
+
node = resolveAnim(node, environment);
|
|
468
666
|
if (!isAnimatedCall(node)) {
|
|
469
667
|
throw aotError('AOT: an animation must be Animated.timing/spring/decay/sequence/parallel/stagger/delay/loop(...)');
|
|
470
668
|
}
|
|
471
669
|
// Atomic animations drive one useAnimatedValue directly; timing has a known length, spring/decay do not.
|
|
472
670
|
const kind = node.callee.property.name;
|
|
473
|
-
const
|
|
671
|
+
const callArguments = node.arguments;
|
|
474
672
|
if (kind === 'timing' || kind === 'spring' || kind === 'decay') {
|
|
475
|
-
const
|
|
476
|
-
if (
|
|
673
|
+
const valueRef = callArguments[0];
|
|
674
|
+
if (valueRef?.type !== 'Identifier' ||
|
|
675
|
+
!environment.animations?.has(valueRef.name)) {
|
|
477
676
|
throw aotError(`AOT: Animated.${kind}() first argument must be a useAnimatedValue`);
|
|
478
677
|
}
|
|
479
|
-
const
|
|
480
|
-
const get = animConfigGetter(
|
|
481
|
-
const ownDelay = ownDelayMs(kind, get,
|
|
482
|
-
const duration = kind === 'timing' ? ownDelay + timingDuration(get,
|
|
678
|
+
const slotName = environment.animations.get(valueRef.name).slotName;
|
|
679
|
+
const get = animConfigGetter(callArguments[1]);
|
|
680
|
+
const ownDelay = ownDelayMs(kind, get, environment);
|
|
681
|
+
const duration = kind === 'timing' ? ownDelay + timingDuration(get, environment) : null;
|
|
483
682
|
return {
|
|
484
|
-
entries: [{
|
|
683
|
+
entries: [{ slotName, kind, get, delayMs: baseDelay + ownDelay, loop }],
|
|
684
|
+
sequences: [],
|
|
485
685
|
duration,
|
|
486
686
|
};
|
|
487
687
|
}
|
|
@@ -489,65 +689,62 @@ function flattenAnim(node, env, baseDelay, loop) {
|
|
|
489
689
|
if (kind === 'delay') {
|
|
490
690
|
return {
|
|
491
691
|
entries: [],
|
|
492
|
-
|
|
692
|
+
sequences: [],
|
|
693
|
+
duration: configMs(callArguments[0], environment, 0, "Animated.delay's time"),
|
|
493
694
|
};
|
|
494
695
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
696
|
+
if (kind === 'sequence') {
|
|
697
|
+
return flattenSequence(node, environment, baseDelay, loop);
|
|
698
|
+
}
|
|
699
|
+
// A parallel or stagger flattens into atomic animations with absolute delay_ms offsets.
|
|
700
|
+
if (kind === 'parallel' || kind === 'stagger') {
|
|
701
|
+
const list = kind === 'stagger' ? callArguments[1] : callArguments[0];
|
|
498
702
|
const staggerMs = kind === 'stagger'
|
|
499
|
-
? configMs(
|
|
703
|
+
? configMs(callArguments[0], environment, 0, "Animated.stagger's interval")
|
|
500
704
|
: 0;
|
|
501
705
|
if (list?.type !== 'ArrayExpression') {
|
|
502
706
|
throw aotError(`AOT: Animated.${kind}(...) needs an array of animations`);
|
|
503
707
|
}
|
|
504
|
-
//
|
|
708
|
+
// Every child starts from the same base, a stagger's each an interval after the one before. A value can be
|
|
709
|
+
// driven by one child only: er_animation_value_animate cancels the running anim on a value, so two that run
|
|
710
|
+
// at once would cancel each other.
|
|
505
711
|
const entries = [];
|
|
506
|
-
|
|
507
|
-
|
|
712
|
+
const sequences = [];
|
|
713
|
+
const driven = new Set();
|
|
714
|
+
let groupDuration = 0; // max end-time relative to baseDelay
|
|
508
715
|
let index = 0;
|
|
509
716
|
for (const child of list.elements) {
|
|
510
717
|
if (!child)
|
|
511
718
|
continue;
|
|
512
|
-
const start =
|
|
513
|
-
const
|
|
514
|
-
entries.push(...
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
off += flatAnim.duration;
|
|
719
|
+
const start = baseDelay + index * staggerMs;
|
|
720
|
+
const flatAnimation = flattenAnim(child, environment, start, loop);
|
|
721
|
+
entries.push(...flatAnimation.entries);
|
|
722
|
+
sequences.push(...flatAnimation.sequences);
|
|
723
|
+
const end = start - baseDelay + (flatAnimation.duration ?? 0);
|
|
724
|
+
if (end > groupDuration) {
|
|
725
|
+
groupDuration = end;
|
|
520
726
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
727
|
+
const values = new Set(flatAnimation.entries.map(animationEntry => animationEntry.slotName));
|
|
728
|
+
for (const sequence of flatAnimation.sequences) {
|
|
729
|
+
sequenceValues(sequence, values);
|
|
730
|
+
}
|
|
731
|
+
for (const value of values) {
|
|
732
|
+
if (driven.has(value)) {
|
|
733
|
+
throw aotError('AOT: the same animated value is driven more than once in this composition — animations that run at once on one value cancel each other. Use an Animated.sequence(...) for multi-step animation of one value.');
|
|
525
734
|
}
|
|
735
|
+
driven.add(value);
|
|
526
736
|
}
|
|
527
737
|
index++;
|
|
528
738
|
}
|
|
529
|
-
|
|
530
|
-
// running anim on a value, so concurrent/flat-sequenced same-value steps cancel each other. (A
|
|
531
|
-
// top-level Animated.sequence is handled separately via on_complete chaining, which does support this.)
|
|
532
|
-
const seen = new Set();
|
|
533
|
-
for (const entry of entries) {
|
|
534
|
-
if (seen.has(entry.cVar)) {
|
|
535
|
-
throw aotError('AOT: the same animated value is driven more than once in this composition — concurrent/flat same-value steps cancel each other. Use a top-level Animated.sequence(...) for multi-step animation of one value.');
|
|
536
|
-
}
|
|
537
|
-
seen.add(entry.cVar);
|
|
538
|
-
}
|
|
539
|
-
return {
|
|
540
|
-
entries,
|
|
541
|
-
duration: kind === 'sequence' ? off - baseDelay : groupDur,
|
|
542
|
-
};
|
|
739
|
+
return { entries, sequences, duration: groupDuration };
|
|
543
740
|
}
|
|
544
741
|
// A nested loop can flatten only when it wraps a single atomic animation; complex loops need start-time chaining.
|
|
545
742
|
if (kind === 'loop') {
|
|
546
|
-
const
|
|
547
|
-
if (
|
|
743
|
+
const flatAnimation = flattenAnim(callArguments[0], environment, baseDelay, true);
|
|
744
|
+
if (flatAnimation.entries.length !== 1 || flatAnimation.sequences.length) {
|
|
548
745
|
throw aotError('AOT: an Animated.loop inside another composition can only wrap a single Animated.timing/spring/decay', 'a loop around a sequence works when the loop is the animation you start: Animated.loop(Animated.sequence([...])).start().');
|
|
549
746
|
}
|
|
550
|
-
return { entries:
|
|
747
|
+
return { entries: flatAnimation.entries, sequences: [], duration: null };
|
|
551
748
|
}
|
|
552
749
|
throw aotError(`AOT: Animated.${kind}(...) is not a supported animation`);
|
|
553
750
|
}
|
|
@@ -561,39 +758,40 @@ function flattenAnim(node, env, baseDelay, loop) {
|
|
|
561
758
|
export const isAnimatedCall = (node) => node?.type === 'CallExpression' &&
|
|
562
759
|
node.callee.type === 'MemberExpression' &&
|
|
563
760
|
node.callee.object?.name === 'Animated' &&
|
|
564
|
-
|
|
761
|
+
ANIMATION_KINDS.has(node.callee.property?.name);
|
|
565
762
|
/**
|
|
566
763
|
* An animation handle (`anim` after `const anim = Animated.loop(…)`) resolved to the call it names.
|
|
567
764
|
*
|
|
568
765
|
* @param node An animation, or a handler local bound to one.
|
|
569
|
-
* @param
|
|
766
|
+
* @param environment The expression environment.
|
|
570
767
|
*
|
|
571
768
|
* @returns The animation the node stands for.
|
|
572
769
|
*/
|
|
573
|
-
export const resolveAnim = (node,
|
|
574
|
-
?
|
|
770
|
+
export const resolveAnim = (node, environment) => node?.type === 'Identifier' && environment.animationLocals?.has(node.name)
|
|
771
|
+
? environment.animationLocals.get(node.name)
|
|
575
772
|
: node;
|
|
576
773
|
/**
|
|
577
774
|
* One Animated.timing/spring/decay call as a chain step, started `extraDelay` ms later than its own delay.
|
|
578
775
|
*
|
|
579
776
|
* @param node The call.
|
|
580
|
-
* @param
|
|
777
|
+
* @param environment The expression environment.
|
|
581
778
|
* @param extraDelay Milliseconds added to its own delay.
|
|
582
779
|
*
|
|
583
780
|
* @returns The step.
|
|
584
781
|
*/
|
|
585
|
-
function animStep(node,
|
|
782
|
+
function animStep(node, environment, extraDelay) {
|
|
586
783
|
const kind = node.callee.property.name;
|
|
587
784
|
// A chain step must drive one collected useAnimatedValue.
|
|
588
|
-
const
|
|
589
|
-
if (
|
|
785
|
+
const valueRef = node.arguments[0];
|
|
786
|
+
if (valueRef?.type !== 'Identifier' ||
|
|
787
|
+
!environment.animations?.has(valueRef.name)) {
|
|
590
788
|
throw aotError(`AOT: Animated.${kind}() first argument must be a useAnimatedValue`);
|
|
591
789
|
}
|
|
592
790
|
// Fold this step's own delay and add any delay inherited from an enclosing sequence/delay.
|
|
593
791
|
const get = animConfigGetter(node.arguments[1]);
|
|
594
|
-
const ownDelay = ownDelayMs(kind, get,
|
|
792
|
+
const ownDelay = ownDelayMs(kind, get, environment);
|
|
595
793
|
return {
|
|
596
|
-
|
|
794
|
+
slotName: environment.animations.get(valueRef.name).slotName,
|
|
597
795
|
kind,
|
|
598
796
|
get,
|
|
599
797
|
delayMs: extraDelay + ownDelay,
|
|
@@ -601,35 +799,35 @@ function animStep(node, env, extraDelay) {
|
|
|
601
799
|
};
|
|
602
800
|
}
|
|
603
801
|
/**
|
|
604
|
-
* The
|
|
802
|
+
* The handle of every value an animation drives.
|
|
605
803
|
*
|
|
606
804
|
* @param node The animation.
|
|
607
|
-
* @param
|
|
805
|
+
* @param environment The expression environment.
|
|
608
806
|
* @param accumulator Collects the handles.
|
|
609
807
|
*
|
|
610
808
|
* @returns `accumulator`.
|
|
611
809
|
*/
|
|
612
|
-
export function animValues(node,
|
|
613
|
-
node = resolveAnim(node,
|
|
810
|
+
export function animValues(node, environment, accumulator = new Set()) {
|
|
811
|
+
node = resolveAnim(node, environment);
|
|
614
812
|
// Reject props that the FlatList-to-ScrollView rewrite cannot preserve.
|
|
615
813
|
if (!isAnimatedCall(node)) {
|
|
616
814
|
throw aotError('AOT: an animation must be Animated.timing/spring/decay/sequence/parallel/stagger/delay/loop(...)');
|
|
617
815
|
}
|
|
618
816
|
// Recurse into composed animations, skipping delay nodes because they drive no animated value.
|
|
619
817
|
const kind = node.callee.property.name;
|
|
620
|
-
const
|
|
818
|
+
const callArguments = node.arguments;
|
|
621
819
|
if (kind === 'timing' || kind === 'spring' || kind === 'decay') {
|
|
622
|
-
accumulator.add(animStep(node,
|
|
820
|
+
accumulator.add(animStep(node, environment, 0).slotName);
|
|
623
821
|
}
|
|
624
822
|
else if (kind === 'loop') {
|
|
625
|
-
animValues(
|
|
823
|
+
animValues(callArguments[0], environment, accumulator);
|
|
626
824
|
}
|
|
627
825
|
else if (kind !== 'delay') {
|
|
628
|
-
const list = kind === 'stagger' ?
|
|
826
|
+
const list = kind === 'stagger' ? callArguments[1] : callArguments[0];
|
|
629
827
|
for (const child of list?.elements ??
|
|
630
828
|
[]) {
|
|
631
829
|
if (child) {
|
|
632
|
-
animValues(child,
|
|
830
|
+
animValues(child, environment, accumulator);
|
|
633
831
|
}
|
|
634
832
|
}
|
|
635
833
|
}
|
|
@@ -639,13 +837,13 @@ export function animValues(node, env, accumulator = new Set()) {
|
|
|
639
837
|
* The steps of an `Animated.sequence([...])` for an on_complete chain. A delay() folds into the next step's
|
|
640
838
|
* delay_ms; `trailingDelay` is what follows the last step. A nested parallel/stagger/loop throws.
|
|
641
839
|
*
|
|
642
|
-
* @param
|
|
643
|
-
* @param
|
|
840
|
+
* @param sequenceNode The sequence call.
|
|
841
|
+
* @param environment The expression environment.
|
|
644
842
|
*
|
|
645
843
|
* @returns The steps, and the delay after the last one.
|
|
646
844
|
*/
|
|
647
|
-
function sequenceSteps(
|
|
648
|
-
const list =
|
|
845
|
+
function sequenceSteps(sequenceNode, environment) {
|
|
846
|
+
const list = sequenceNode.arguments[0];
|
|
649
847
|
// Sequence composition is lowered at build time, so its children must be an array literal.
|
|
650
848
|
if (list?.type !== 'ArrayExpression') {
|
|
651
849
|
throw aotError('AOT: Animated.sequence(...) needs an array of animations');
|
|
@@ -656,7 +854,7 @@ function sequenceSteps(seqNode, env) {
|
|
|
656
854
|
for (const element of list.elements) {
|
|
657
855
|
if (!element)
|
|
658
856
|
continue;
|
|
659
|
-
const child = resolveAnim(element,
|
|
857
|
+
const child = resolveAnim(element, environment);
|
|
660
858
|
// Reject non-animation entries in the sequence.
|
|
661
859
|
if (!isAnimatedCall(child)) {
|
|
662
860
|
throw aotError('AOT: Animated.sequence entries must be Animated.timing/spring/decay/delay(...)');
|
|
@@ -664,7 +862,7 @@ function sequenceSteps(seqNode, env) {
|
|
|
664
862
|
// Fold delay-only entries into the following animation step.
|
|
665
863
|
const kind = child.callee.property.name;
|
|
666
864
|
if (kind === 'delay') {
|
|
667
|
-
pendingDelay += configMs(child.arguments[0],
|
|
865
|
+
pendingDelay += configMs(child.arguments[0], environment, 0, "Animated.delay's time");
|
|
668
866
|
continue;
|
|
669
867
|
}
|
|
670
868
|
// Keep sequence chains flat: delay plus timing/spring/decay only.
|
|
@@ -672,14 +870,14 @@ function sequenceSteps(seqNode, env) {
|
|
|
672
870
|
throw aotError('AOT: Animated.sequence entries must be Animated.timing/spring/decay/delay (a nested ' +
|
|
673
871
|
'parallel/stagger/loop inside a sequence is not yet supported — keep the sequence flat)');
|
|
674
872
|
}
|
|
675
|
-
steps.push(animStep(child,
|
|
873
|
+
steps.push(animStep(child, environment, pendingDelay));
|
|
676
874
|
pendingDelay = 0;
|
|
677
875
|
}
|
|
678
876
|
return { steps, trailingDelay: pendingDelay };
|
|
679
877
|
}
|
|
680
878
|
/**
|
|
681
879
|
* Lowers steps to an on_complete CHAIN: step 0 starts inline, and each step's completion callback starts the
|
|
682
|
-
* next. Unlike the flat delay_ms path, this is correct when steps share a value —
|
|
880
|
+
* next. Unlike the flat delay_ms path, this is correct when steps share a value — er_animation_value_animate
|
|
683
881
|
* cancels the running anim on a value, so starting them together would cancel all but the last — and needs
|
|
684
882
|
* no fixed duration. A step that is interrupted (finished == false) ends the chain, as it does in JS. The
|
|
685
883
|
* chain's callbacks and loop slots are added to the output here.
|
|
@@ -688,21 +886,21 @@ function sequenceSteps(seqNode, env) {
|
|
|
688
886
|
* put back where it started before each repeat, or null), trailingDelay (ms before each repeat)}.
|
|
689
887
|
*
|
|
690
888
|
* @param steps The chain's steps.
|
|
691
|
-
* @param
|
|
692
|
-
* @param
|
|
889
|
+
* @param environment The expression environment.
|
|
890
|
+
* @param context The statement compiler's context.
|
|
693
891
|
* @param completion The completion callback to run when the chain ends, if any.
|
|
694
892
|
* @param loop How the chain repeats, or null for once.
|
|
695
893
|
* @param trailing For a chain that runs once: the composition's key and the wait after its last step.
|
|
696
894
|
*
|
|
697
895
|
* @returns The chain.
|
|
698
896
|
*/
|
|
699
|
-
function lowerChain(steps,
|
|
700
|
-
// GLOBAL: callback names
|
|
701
|
-
const id =
|
|
897
|
+
function lowerChain(steps, environment, context, completion, loop = null, trailing = null) {
|
|
898
|
+
// GLOBAL: callback names must be unique across handlers
|
|
899
|
+
const id = context.output.sequenceCount++;
|
|
702
900
|
// Lowered from the tail, the order the callbacks are emitted in.
|
|
703
901
|
const lowered = new Array(steps.length);
|
|
704
902
|
for (let index = steps.length - 1; index >= 0; index--) {
|
|
705
|
-
lowered[index] = lowerAnimation(steps[index],
|
|
903
|
+
lowered[index] = lowerAnimation(steps[index], environment);
|
|
706
904
|
}
|
|
707
905
|
// A repeat restarts step 0 after any trailing sequence delay.
|
|
708
906
|
const chain = {
|
|
@@ -713,39 +911,39 @@ function lowerChain(steps, env, ctx, completion, loop = null, trailing = null) {
|
|
|
713
911
|
? {
|
|
714
912
|
iterations: loop.iterations,
|
|
715
913
|
resetHandle: loop.resetTo,
|
|
716
|
-
restart: lowerAnimation({ ...steps[0], delayMs: steps[0].delayMs + loop.trailingDelay },
|
|
914
|
+
restart: lowerAnimation({ ...steps[0], delayMs: steps[0].delayMs + loop.trailingDelay }, environment),
|
|
717
915
|
finalWait: loop.iterations >= 0 && completion && loop.trailingDelay > 0
|
|
718
916
|
? {
|
|
719
917
|
delayMs: totalMs(loop.trailingDelay),
|
|
720
|
-
owner: waitOwner(
|
|
918
|
+
owner: waitOwner(context, loop.key, true),
|
|
721
919
|
}
|
|
722
920
|
: null,
|
|
723
921
|
}
|
|
724
922
|
: null,
|
|
725
923
|
completion,
|
|
726
924
|
completionWait: !loop && completion && trailing && trailing.delayMs > 0
|
|
727
|
-
? completionWait(
|
|
925
|
+
? completionWait(context, trailing.key, trailing.delayMs, `chain_${id}_${steps.length}`)
|
|
728
926
|
: null,
|
|
729
927
|
};
|
|
730
|
-
|
|
731
|
-
|
|
928
|
+
context.output.animationCallbacks.push({ kind: 'chain', chain });
|
|
929
|
+
context.output.effectDeclarations.push({ kind: 'chain', chain });
|
|
732
930
|
return chain;
|
|
733
931
|
}
|
|
734
932
|
/**
|
|
735
933
|
* A start with nothing to run.
|
|
736
934
|
*
|
|
737
|
-
* @param
|
|
935
|
+
* @param context The statement compiler's context.
|
|
738
936
|
* @param completion The completion callback, if any; it never runs.
|
|
739
937
|
*
|
|
740
938
|
* @returns The start.
|
|
741
939
|
*/
|
|
742
|
-
const emptyStart = (
|
|
940
|
+
const emptyStart = (context, completion) => ({
|
|
743
941
|
kind: 'startAnimations',
|
|
744
942
|
animations: [],
|
|
745
|
-
|
|
943
|
+
sequences: [],
|
|
746
944
|
completion,
|
|
747
945
|
completionWait: null,
|
|
748
|
-
|
|
946
|
+
group: null,
|
|
749
947
|
});
|
|
750
948
|
/** Numbers each composition node once, so a key names the place it is written. */
|
|
751
949
|
const compositionIds = new WeakMap();
|
|
@@ -757,61 +955,69 @@ let nextCompositionId = 0;
|
|
|
757
955
|
* … pulse.stop()`) reach the same node.
|
|
758
956
|
*
|
|
759
957
|
* @param node The composition, resolved.
|
|
760
|
-
* @param
|
|
958
|
+
* @param environment The expression environment.
|
|
761
959
|
*
|
|
762
960
|
* @returns The key.
|
|
763
961
|
*/
|
|
764
|
-
function compositionKey(node,
|
|
962
|
+
function compositionKey(node, environment) {
|
|
765
963
|
let id = node ? compositionIds.get(node) : -1;
|
|
766
964
|
if (id === undefined) {
|
|
767
965
|
id = nextCompositionId++;
|
|
768
966
|
compositionIds.set(node, id);
|
|
769
967
|
}
|
|
770
|
-
return `${
|
|
968
|
+
return `${environment.callbackPrefix ?? ''}|${id}`;
|
|
771
969
|
}
|
|
772
970
|
/**
|
|
773
971
|
* The owner number completion waits of a composition carry, so a stop can end them; numbered on first use.
|
|
774
972
|
*
|
|
775
|
-
* @param
|
|
973
|
+
* @param context The statement compiler's context.
|
|
776
974
|
* @param key The composition's key.
|
|
777
975
|
* @param isStart A start is asking, so the waits are real (a stop alone leaves nothing to end).
|
|
976
|
+
* @param hasWaits The start runs waits of their own, beside any group it runs.
|
|
778
977
|
*
|
|
779
978
|
* @returns The owner.
|
|
780
979
|
*/
|
|
781
|
-
function waitOwner(
|
|
782
|
-
let record =
|
|
980
|
+
function waitOwner(context, key, isStart, hasWaits = isStart) {
|
|
981
|
+
let record = context.output.animationWaits.get(key);
|
|
783
982
|
if (!record) {
|
|
784
|
-
record = {
|
|
785
|
-
|
|
983
|
+
record = {
|
|
984
|
+
owner: context.output.animationWaits.size,
|
|
985
|
+
isStarted: false,
|
|
986
|
+
hasWaits: false,
|
|
987
|
+
};
|
|
988
|
+
context.output.animationWaits.set(key, record);
|
|
786
989
|
}
|
|
787
990
|
if (isStart) {
|
|
788
991
|
record.isStarted = true;
|
|
789
992
|
}
|
|
993
|
+
if (hasWaits) {
|
|
994
|
+
record.hasWaits = true;
|
|
995
|
+
}
|
|
790
996
|
return record.owner;
|
|
791
997
|
}
|
|
792
998
|
/**
|
|
793
999
|
* True when a composition has an Animated.delay anywhere, the only thing a completion can wait on.
|
|
794
1000
|
*
|
|
795
1001
|
* @param node The composition.
|
|
796
|
-
* @param
|
|
1002
|
+
* @param environment The expression environment.
|
|
797
1003
|
*
|
|
798
1004
|
* @returns Whether it does.
|
|
799
1005
|
*/
|
|
800
|
-
function hasDelay(node,
|
|
801
|
-
node = resolveAnim(node,
|
|
1006
|
+
function hasDelay(node, environment) {
|
|
1007
|
+
node = resolveAnim(node, environment);
|
|
802
1008
|
if (!isAnimatedCall(node))
|
|
803
1009
|
return false;
|
|
804
1010
|
// Look through compositions; a timing, spring or decay waits on nothing beyond itself.
|
|
805
1011
|
const kind = node.callee.property.name;
|
|
806
|
-
const
|
|
1012
|
+
const callArguments = node.arguments;
|
|
807
1013
|
if (kind === 'delay')
|
|
808
1014
|
return true;
|
|
809
1015
|
if (kind === 'loop')
|
|
810
|
-
return hasDelay(
|
|
1016
|
+
return hasDelay(callArguments[0], environment);
|
|
811
1017
|
if (kind === 'sequence' || kind === 'parallel' || kind === 'stagger') {
|
|
812
|
-
const list = kind === 'stagger' ?
|
|
1018
|
+
const list = kind === 'stagger' ? callArguments[1] : callArguments[0];
|
|
813
1019
|
return (list?.type === 'ArrayExpression' &&
|
|
814
|
-
list.elements.some(child => child && hasDelay(child,
|
|
1020
|
+
list.elements.some(child => child && hasDelay(child, environment)));
|
|
815
1021
|
}
|
|
816
1022
|
return false;
|
|
817
1023
|
}
|
|
@@ -819,46 +1025,46 @@ function hasDelay(node, env) {
|
|
|
819
1025
|
* The composition whose completion waits `anim.stop()` ends, when it has a delay to wait on.
|
|
820
1026
|
*
|
|
821
1027
|
* @param node The composition being stopped.
|
|
822
|
-
* @param
|
|
823
|
-
* @param
|
|
1028
|
+
* @param environment The expression environment.
|
|
1029
|
+
* @param context The statement compiler's context.
|
|
824
1030
|
*
|
|
825
1031
|
* @returns The owner, or null.
|
|
826
1032
|
*/
|
|
827
|
-
export function stopWaitOwner(node,
|
|
828
|
-
const resolved = resolveAnim(node,
|
|
829
|
-
return hasDelay(resolved,
|
|
830
|
-
? waitOwner(
|
|
1033
|
+
export function stopWaitOwner(node, environment, context) {
|
|
1034
|
+
const resolved = resolveAnim(node, environment);
|
|
1035
|
+
return hasDelay(resolved, environment)
|
|
1036
|
+
? waitOwner(context, compositionKey(resolved, environment), false)
|
|
831
1037
|
: null;
|
|
832
1038
|
}
|
|
833
1039
|
/**
|
|
834
1040
|
* The wait between a composition's last animation finishing and its completion running.
|
|
835
1041
|
*
|
|
836
|
-
* @param
|
|
1042
|
+
* @param context The statement compiler's context.
|
|
837
1043
|
* @param key The composition's key.
|
|
838
1044
|
* @param delayMs The wait.
|
|
839
1045
|
* @param callback The name of the on_complete callback that starts it.
|
|
840
1046
|
*
|
|
841
1047
|
* @returns The wait.
|
|
842
1048
|
*/
|
|
843
|
-
const completionWait = (
|
|
1049
|
+
const completionWait = (context, key, delayMs, callback) => ({
|
|
844
1050
|
delayMs: totalMs(delayMs),
|
|
845
1051
|
callback,
|
|
846
|
-
owner: waitOwner(
|
|
1052
|
+
owner: waitOwner(context, key, true),
|
|
847
1053
|
});
|
|
848
1054
|
/**
|
|
849
1055
|
* A start that drives no value. As in JS, its completion still runs as finished once the composition's delays
|
|
850
1056
|
* have passed, counted down in a completion wait of its own.
|
|
851
1057
|
*
|
|
852
|
-
* @param
|
|
1058
|
+
* @param context The statement compiler's context.
|
|
853
1059
|
* @param completion The completion callback, if any.
|
|
854
1060
|
* @param delayMs How long the composition takes.
|
|
855
1061
|
* @param key The composition's key.
|
|
856
1062
|
*
|
|
857
1063
|
* @returns The start.
|
|
858
1064
|
*/
|
|
859
|
-
function startNothing(
|
|
1065
|
+
function startNothing(context, completion, delayMs, key) {
|
|
860
1066
|
if (!completion) {
|
|
861
|
-
return emptyStart(
|
|
1067
|
+
return emptyStart(context, completion);
|
|
862
1068
|
}
|
|
863
1069
|
const start = {
|
|
864
1070
|
kind: 'completeAfter',
|
|
@@ -867,7 +1073,7 @@ function startNothing(ctx, completion, delayMs, key) {
|
|
|
867
1073
|
owner: null,
|
|
868
1074
|
};
|
|
869
1075
|
if (delayMs > 0) {
|
|
870
|
-
start.owner = waitOwner(
|
|
1076
|
+
start.owner = waitOwner(context, key, true);
|
|
871
1077
|
}
|
|
872
1078
|
return start;
|
|
873
1079
|
}
|
|
@@ -878,23 +1084,23 @@ function startNothing(ctx, completion, delayMs, key) {
|
|
|
878
1084
|
* started before each repeat (resetBeforeIteration), and a looped sequence carries on from where it ended.
|
|
879
1085
|
*
|
|
880
1086
|
* @param loopNode The `Animated.loop(…)` call.
|
|
881
|
-
* @param
|
|
882
|
-
* @param
|
|
1087
|
+
* @param environment The expression environment.
|
|
1088
|
+
* @param context The statement compiler's context.
|
|
883
1089
|
* @param completion The completion callback to run when the loop ends, if any.
|
|
884
1090
|
* @param key The loop's composition key.
|
|
885
1091
|
*
|
|
886
1092
|
* @returns The start, or null when the flat path (the engine's own cfg.loop) handles it.
|
|
887
1093
|
*/
|
|
888
|
-
function lowerLoopStart(loopNode,
|
|
1094
|
+
function lowerLoopStart(loopNode, environment, context, completion, key) {
|
|
889
1095
|
// Fold the loop count at build time; absent or noninteger iterations mean repeat forever.
|
|
890
|
-
const inner = resolveAnim(loopNode.arguments[0],
|
|
1096
|
+
const inner = resolveAnim(loopNode.arguments[0], environment);
|
|
891
1097
|
const kind = isAnimatedCall(inner) ? inner.callee.property.name : null;
|
|
892
1098
|
const get = animConfigGetter(loopNode.arguments[1]);
|
|
893
1099
|
let iterations = -1;
|
|
894
1100
|
if (get('iterations')) {
|
|
895
1101
|
let value;
|
|
896
1102
|
try {
|
|
897
|
-
value = evalStatic(get('iterations'), foldScope(
|
|
1103
|
+
value = evalStatic(get('iterations'), foldScope(environment, environment.constants ?? {}));
|
|
898
1104
|
}
|
|
899
1105
|
catch {
|
|
900
1106
|
throw aotError('AOT: Animated.loop iterations must be known at build time', 'use a number or a module-level constant.');
|
|
@@ -905,19 +1111,19 @@ function lowerLoopStart(loopNode, env, ctx, completion, key) {
|
|
|
905
1111
|
: -1;
|
|
906
1112
|
}
|
|
907
1113
|
// Use the engine's native loop only for endless reset timing loops; other loop shapes need callback chaining.
|
|
908
|
-
const reset = evalStaticOr(get('resetBeforeIteration'),
|
|
1114
|
+
const reset = evalStaticOr(get('resetBeforeIteration'), environment, true) !== false;
|
|
909
1115
|
let steps;
|
|
910
1116
|
let trailingDelay = 0;
|
|
911
1117
|
let resetTo = null;
|
|
912
1118
|
if (kind === 'sequence') {
|
|
913
|
-
({ steps, trailingDelay } = sequenceSteps(inner,
|
|
1119
|
+
({ steps, trailingDelay } = sequenceSteps(inner, environment));
|
|
914
1120
|
}
|
|
915
1121
|
else if (kind === 'timing' || kind === 'spring' || kind === 'decay') {
|
|
916
1122
|
if (kind === 'timing' && iterations < 0 && reset)
|
|
917
1123
|
return null;
|
|
918
|
-
steps = [animStep(inner,
|
|
1124
|
+
steps = [animStep(inner, environment, 0)];
|
|
919
1125
|
if (reset) {
|
|
920
|
-
resetTo = steps[0].
|
|
1126
|
+
resetTo = steps[0].slotName;
|
|
921
1127
|
}
|
|
922
1128
|
}
|
|
923
1129
|
else {
|
|
@@ -925,23 +1131,23 @@ function lowerLoopStart(loopNode, env, ctx, completion, key) {
|
|
|
925
1131
|
}
|
|
926
1132
|
// A zero-iteration loop starts nothing but still reports successful completion.
|
|
927
1133
|
if (iterations === 0) {
|
|
928
|
-
return startNothing(
|
|
1134
|
+
return startNothing(context, completion, 0, key);
|
|
929
1135
|
}
|
|
930
1136
|
// A loop of delays alone completes after its passes; an endless one never does.
|
|
931
1137
|
if (!steps.length) {
|
|
932
1138
|
return iterations < 0
|
|
933
|
-
? emptyStart(
|
|
934
|
-
: startNothing(
|
|
1139
|
+
? emptyStart(context, completion)
|
|
1140
|
+
: startNothing(context, completion, iterations * trailingDelay, key);
|
|
935
1141
|
}
|
|
936
|
-
// A timing with no duration and no delay completes inside
|
|
1142
|
+
// A timing with no duration and no delay completes inside er_animation_value_animate, so a loop made only of
|
|
937
1143
|
// those would restart itself forever without returning.
|
|
938
|
-
const instant = (
|
|
939
|
-
|
|
940
|
-
timingDuration(
|
|
1144
|
+
const instant = (animationEntry) => animationEntry.kind === 'timing' &&
|
|
1145
|
+
animationEntry.delayMs === 0 &&
|
|
1146
|
+
timingDuration(animationEntry.get, environment) === 0;
|
|
941
1147
|
if (trailingDelay === 0 && steps.every(instant)) {
|
|
942
1148
|
throw aotError('AOT: every step of this Animated.loop finishes instantly, so it would never stop repeating', 'give a step a duration or a delay.');
|
|
943
1149
|
}
|
|
944
|
-
return lowerChain(steps,
|
|
1150
|
+
return lowerChain(steps, environment, context, completion, {
|
|
945
1151
|
iterations,
|
|
946
1152
|
resetTo,
|
|
947
1153
|
trailingDelay,
|
|
@@ -949,97 +1155,138 @@ function lowerLoopStart(loopNode, env, ctx, completion, key) {
|
|
|
949
1155
|
});
|
|
950
1156
|
}
|
|
951
1157
|
/**
|
|
952
|
-
* Lowers a `.start(onComplete)` completion callback to a
|
|
1158
|
+
* Lowers a `.start(onComplete)` completion callback to a function (ERAnimationCompleteFn) set as the
|
|
953
1159
|
* animation's on_complete, and adds it to the output; its body runs setters/refs/etc. and re-applies state via
|
|
954
|
-
*
|
|
1160
|
+
* the update if needed.
|
|
955
1161
|
*
|
|
956
|
-
* @param
|
|
957
|
-
* @param
|
|
1162
|
+
* @param functionNode The callback.
|
|
1163
|
+
* @param environment The expression environment.
|
|
958
1164
|
* @param state The component's state table.
|
|
959
|
-
* @param
|
|
1165
|
+
* @param context The statement compiler's context.
|
|
960
1166
|
*
|
|
961
1167
|
* @returns The completion.
|
|
962
1168
|
*/
|
|
963
|
-
function lowerCompletion(
|
|
964
|
-
// Generate a
|
|
965
|
-
const id =
|
|
966
|
-
const name = `
|
|
967
|
-
const locals = new Map(
|
|
968
|
-
const
|
|
969
|
-
if (
|
|
970
|
-
for (const property of
|
|
1169
|
+
function lowerCompletion(functionNode, environment, state, context) {
|
|
1170
|
+
// Generate a completion callback and expose start(({finished}) => ...) as a local int.
|
|
1171
|
+
const id = context.output.sequenceCount++;
|
|
1172
|
+
const name = `done_${id}`;
|
|
1173
|
+
const locals = new Map(environment.locals);
|
|
1174
|
+
const parameter = functionNode.params[0];
|
|
1175
|
+
if (parameter?.type === 'ObjectPattern') {
|
|
1176
|
+
for (const property of parameter.properties) {
|
|
971
1177
|
if ((property.key?.name ??
|
|
972
1178
|
property.key?.value) === 'finished') {
|
|
973
1179
|
locals.set(property.value?.name ?? 'finished', {
|
|
974
|
-
|
|
975
|
-
|
|
1180
|
+
name: 'finished',
|
|
1181
|
+
slotKind: 'int',
|
|
976
1182
|
});
|
|
977
1183
|
}
|
|
978
1184
|
}
|
|
979
1185
|
}
|
|
980
1186
|
// Lower the callback body as statements; it re-renders if it changed React state.
|
|
981
|
-
const
|
|
982
|
-
const list =
|
|
983
|
-
?
|
|
984
|
-
: [{ type: 'ExpressionStatement', expression:
|
|
985
|
-
const
|
|
1187
|
+
const functionBody = functionNode.body;
|
|
1188
|
+
const list = functionBody.type === 'BlockStatement'
|
|
1189
|
+
? functionBody.body
|
|
1190
|
+
: [{ type: 'ExpressionStatement', expression: functionBody }];
|
|
1191
|
+
const completionContext = {
|
|
986
1192
|
stateChanged: false,
|
|
987
|
-
|
|
988
|
-
out: ctx.out,
|
|
1193
|
+
output: context.output,
|
|
989
1194
|
};
|
|
990
|
-
const body =
|
|
991
|
-
const completion = { name, body, updatesState:
|
|
992
|
-
|
|
1195
|
+
const body = lowerBody(list, { ...environment, locals }, state, completionContext);
|
|
1196
|
+
const completion = { name, body, updatesState: completionContext.stateChanged };
|
|
1197
|
+
context.output.animationCallbacks.push({ kind: 'completion', completion });
|
|
993
1198
|
return completion;
|
|
994
1199
|
}
|
|
1200
|
+
/**
|
|
1201
|
+
* Whether one interrupted animation of a composition stops the rest: a parallel's do unless it is given
|
|
1202
|
+
* `stopTogether: false`, and a stagger's run on.
|
|
1203
|
+
*
|
|
1204
|
+
* @param node The parallel or stagger.
|
|
1205
|
+
* @param environment The expression environment.
|
|
1206
|
+
*
|
|
1207
|
+
* @returns Whether they stop together.
|
|
1208
|
+
*/
|
|
1209
|
+
function stopsTogether(node, environment) {
|
|
1210
|
+
if (node.callee.property.name !== 'parallel')
|
|
1211
|
+
return false;
|
|
1212
|
+
const stopTogether = animConfigGetter(node.arguments[1])('stopTogether');
|
|
1213
|
+
return evalStaticOr(stopTogether, environment, true) !== false;
|
|
1214
|
+
}
|
|
995
1215
|
/**
|
|
996
1216
|
* Lowers `<animation>.start()` — a single Animated.timing/spring/decay or a composition
|
|
997
1217
|
* (sequence/parallel/stagger/delay/loop). A sequence, and a loop the engine cannot repeat on its own, become
|
|
998
1218
|
* an on_complete chain (lowerChain); everything else flattens to one animation per atomic entry, composition
|
|
999
|
-
* expressed through per-entry delay_ms
|
|
1219
|
+
* expressed through per-entry delay_ms, run as a group when a completion waits on several or a parallel stops
|
|
1220
|
+
* them together. Native-driven; sets no React state.
|
|
1000
1221
|
*
|
|
1001
|
-
* @param
|
|
1002
|
-
* @param
|
|
1222
|
+
* @param expression The `.start(…)` call.
|
|
1223
|
+
* @param environment The expression environment.
|
|
1003
1224
|
* @param state The component's state table.
|
|
1004
|
-
* @param
|
|
1225
|
+
* @param context The statement compiler's context.
|
|
1005
1226
|
*
|
|
1006
1227
|
* @returns The start.
|
|
1007
1228
|
*/
|
|
1008
|
-
export function lowerAnimateStart(
|
|
1229
|
+
export function lowerAnimateStart(expression, environment, state, context) {
|
|
1009
1230
|
// Resolve the animation being started and handle cases that need callback chaining before falling back to flat emission.
|
|
1010
|
-
const completion = isFn(
|
|
1011
|
-
? lowerCompletion(
|
|
1231
|
+
const completion = isFn(expression.arguments[0])
|
|
1232
|
+
? lowerCompletion(expression.arguments[0], environment, state, context)
|
|
1012
1233
|
: null;
|
|
1013
|
-
const receiver = resolveAnim(
|
|
1234
|
+
const receiver = resolveAnim(expression.callee.object, environment);
|
|
1014
1235
|
const kind = isAnimatedCall(receiver) ? receiver.callee.property.name : null;
|
|
1015
|
-
const key = compositionKey(receiver,
|
|
1236
|
+
const key = compositionKey(receiver, environment);
|
|
1016
1237
|
if (kind === 'sequence') {
|
|
1017
|
-
const { steps, trailingDelay } = sequenceSteps(receiver,
|
|
1238
|
+
const { steps, trailingDelay } = sequenceSteps(receiver, environment);
|
|
1018
1239
|
return steps.length
|
|
1019
|
-
? lowerChain(steps,
|
|
1240
|
+
? lowerChain(steps, environment, context, completion, null, {
|
|
1020
1241
|
key,
|
|
1021
1242
|
delayMs: trailingDelay,
|
|
1022
1243
|
})
|
|
1023
|
-
: startNothing(
|
|
1244
|
+
: startNothing(context, completion, trailingDelay, key);
|
|
1024
1245
|
}
|
|
1025
1246
|
if (kind === 'loop') {
|
|
1026
|
-
const start = lowerLoopStart(receiver,
|
|
1247
|
+
const start = lowerLoopStart(receiver, environment, context, completion, key);
|
|
1027
1248
|
if (start)
|
|
1028
1249
|
return start;
|
|
1029
1250
|
}
|
|
1030
|
-
|
|
1031
|
-
const { entries, duration } =
|
|
1032
|
-
if (!entries.length) {
|
|
1033
|
-
return startNothing(
|
|
1034
|
-
}
|
|
1035
|
-
if (completion && entries.length > 1) {
|
|
1036
|
-
throw aotError('AOT: a .start(onComplete) callback on a parallel/stagger animation is not yet supported', 'attach the completion callback to a single animation or an Animated.sequence(...). For "after all parallel anims", restructure as a sequence.');
|
|
1251
|
+
const flat = flattenAnim(receiver, environment, 0, false);
|
|
1252
|
+
const { entries, sequences, duration } = flat;
|
|
1253
|
+
if (!entries.length && !sequences.length) {
|
|
1254
|
+
return startNothing(context, completion, duration ?? 0, key);
|
|
1037
1255
|
}
|
|
1038
1256
|
// Each entry starts on its own, numbered after the configs already in this body.
|
|
1039
|
-
const start = emptyStart(
|
|
1040
|
-
for (const
|
|
1041
|
-
start.animations.push(lowerAnimation(
|
|
1042
|
-
|
|
1257
|
+
const start = emptyStart(context, completion);
|
|
1258
|
+
for (const animationEntry of entries) {
|
|
1259
|
+
start.animations.push(lowerAnimation(animationEntry, environment));
|
|
1260
|
+
}
|
|
1261
|
+
// Several animations run as a group when a completion waits on them all, one stopping stops the rest, or a
|
|
1262
|
+
// sequence runs among them.
|
|
1263
|
+
const runners = entries.length + sequences.length;
|
|
1264
|
+
const stopTogether = runners > 1 && stopsTogether(receiver, environment);
|
|
1265
|
+
if (sequences.length || (runners > 1 && (completion || stopTogether))) {
|
|
1266
|
+
const waitMs = completion ? outlastingDelay(flat, environment) : null;
|
|
1267
|
+
const groupEntries = 1 +
|
|
1268
|
+
(waitMs == null ? 0 : 1) +
|
|
1269
|
+
entries.length +
|
|
1270
|
+
sequences.reduce((count, sequence) => count + sequenceEntries(sequence, environment), 0);
|
|
1271
|
+
if (groupEntries > MAX_GROUP_ENTRIES) {
|
|
1272
|
+
const mostAnimations = MAX_GROUP_ENTRIES - 1 - (waitMs == null ? 0 : 1);
|
|
1273
|
+
throw aotError(sequences.length
|
|
1274
|
+
? `AOT: this parallel/stagger takes ${groupEntries} entries to run as one group, of at most ${MAX_GROUP_ENTRIES} (one for itself, and one for each animation, sequence and delay in it)`
|
|
1275
|
+
: `AOT: this parallel/stagger can run at most ${mostAnimations} animations as one group`, 'split the composition into smaller ones.');
|
|
1276
|
+
}
|
|
1277
|
+
context.output.animationGroupEntries += groupEntries;
|
|
1278
|
+
start.sequences = sequences.map(sequence => lowerSequence(sequence, environment));
|
|
1279
|
+
start.group = {
|
|
1280
|
+
stopsTogether: stopTogether,
|
|
1281
|
+
wait: waitMs == null
|
|
1282
|
+
? null
|
|
1283
|
+
: { delayMs: totalMs(waitMs), owner: waitOwner(context, key, true) },
|
|
1284
|
+
// A group with sequences is kept, so starting it again stops the run before.
|
|
1285
|
+
owner: sequences.length
|
|
1286
|
+
? waitOwner(context, key, true, waitMs != null)
|
|
1287
|
+
: null,
|
|
1288
|
+
};
|
|
1289
|
+
return start;
|
|
1043
1290
|
}
|
|
1044
1291
|
// A spring or decay has no fixed end, so a delay beside it that runs past its start is joined at run time.
|
|
1045
1292
|
const [only] = entries;
|
|
@@ -1048,17 +1295,21 @@ export function lowerAnimateStart(expr, env, state, ctx) {
|
|
|
1048
1295
|
!only.loop &&
|
|
1049
1296
|
duration != null &&
|
|
1050
1297
|
duration > only.delayMs) {
|
|
1051
|
-
start.
|
|
1052
|
-
|
|
1053
|
-
|
|
1298
|
+
start.group = {
|
|
1299
|
+
stopsTogether: true,
|
|
1300
|
+
wait: {
|
|
1301
|
+
delayMs: totalMs(duration),
|
|
1302
|
+
owner: waitOwner(context, key, true),
|
|
1303
|
+
},
|
|
1304
|
+
owner: null,
|
|
1054
1305
|
};
|
|
1055
1306
|
}
|
|
1056
1307
|
// A delay beside the one timing that outlasts it holds the completion back until the composition ends.
|
|
1057
1308
|
if (completion && only.kind === 'timing' && !only.loop && duration != null) {
|
|
1058
|
-
const end = only.delayMs + timingDuration(only.get,
|
|
1309
|
+
const end = only.delayMs + timingDuration(only.get, environment);
|
|
1059
1310
|
if (duration > end) {
|
|
1060
|
-
start.completionWait = completionWait(
|
|
1061
|
-
|
|
1311
|
+
start.completionWait = completionWait(context, key, duration - end, `wait_${context.output.sequenceCount++}`);
|
|
1312
|
+
context.output.animationCallbacks.push({
|
|
1062
1313
|
kind: 'completionWait',
|
|
1063
1314
|
completion,
|
|
1064
1315
|
wait: start.completionWait,
|