@tamagui/animations-react-native 3.0.0-beta.924.1 → 3.0.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/dist/cjs/createAnimations.native.cjs +243 -74
- package/dist/cjs/createAnimations.native.js +243 -74
- package/dist/cjs/createAnimations.native.js.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/types.cjs +16 -0
- package/dist/cjs/types.native.cjs +18 -0
- package/dist/cjs/types.native.js +20 -0
- package/dist/cjs/types.native.js.map +1 -0
- package/dist/esm/createAnimations.native.js +242 -73
- package/dist/esm/createAnimations.native.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/types.mjs +0 -0
- package/dist/esm/types.native.js +0 -0
- package/package.json +9 -8
- package/src/{createAnimations.tsx → createAnimations.native.tsx} +524 -132
- package/src/index.native.ts +1 -1
- package/src/index.ts +15 -2
- package/src/types.ts +4 -0
- package/types/{createAnimations.d.ts → createAnimations.native.d.ts} +6 -15
- package/types/createAnimations.native.d.ts.map +11 -0
- package/types/index.d.ts +10 -2
- package/types/index.d.ts.map +2 -2
- package/types/index.native.d.ts +1 -1
- package/types/index.native.d.ts.map +1 -1
- package/types/types.d.ts +5 -0
- package/types/types.d.ts.map +11 -0
- package/dist/cjs/createAnimations.cjs +0 -617
- package/dist/esm/createAnimations.mjs +0 -584
- package/dist/esm/createAnimations.mjs.map +0 -1
- package/types/createAnimations.d.ts.map +0 -11
|
@@ -1,617 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all) __defProp(target, name, {
|
|
9
|
-
get: all[name],
|
|
10
|
-
enumerable: true
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
-
get: () => from[key],
|
|
17
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
-
value: mod,
|
|
24
|
-
enumerable: true
|
|
25
|
-
}) : target, mod));
|
|
26
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
-
var createAnimations_exports = {};
|
|
28
|
-
__export(createAnimations_exports, {
|
|
29
|
-
AnimatedText: () => AnimatedText,
|
|
30
|
-
AnimatedView: () => AnimatedView,
|
|
31
|
-
createAnimations: () => createAnimations,
|
|
32
|
-
useAnimatedNumber: () => useAnimatedNumber,
|
|
33
|
-
useAnimatedNumberReaction: () => useAnimatedNumberReaction,
|
|
34
|
-
useAnimatedNumberStyle: () => useAnimatedNumberStyle,
|
|
35
|
-
useAnimatedNumbersStyle: () => useAnimatedNumbersStyle
|
|
36
|
-
});
|
|
37
|
-
module.exports = __toCommonJS(createAnimations_exports);
|
|
38
|
-
var import_animation_helpers = require("@tamagui/animation-helpers");
|
|
39
|
-
var import_constants = require("@tamagui/constants");
|
|
40
|
-
var import_use_presence = require("@tamagui/use-presence");
|
|
41
|
-
var import_web = require("@tamagui/web");
|
|
42
|
-
var import_internal_runtime = require("@tamagui/web/internal-runtime");
|
|
43
|
-
var import_react = __toESM(require("react"), 1);
|
|
44
|
-
var import_react_native = require("react-native-web");
|
|
45
|
-
const isFabric = !import_constants.isWeb && typeof global !== "undefined" && !!global.__nativeFabricUIManager;
|
|
46
|
-
const resolveDynamicValue = (value, isDark) => {
|
|
47
|
-
if (value && typeof value === "object" && "dynamic" in value) {
|
|
48
|
-
const dynamicValue = isDark ? value.dynamic.dark : value.dynamic.light;
|
|
49
|
-
return dynamicValue;
|
|
50
|
-
}
|
|
51
|
-
return value;
|
|
52
|
-
};
|
|
53
|
-
const animatedStyleKey = {
|
|
54
|
-
transform: true,
|
|
55
|
-
opacity: true
|
|
56
|
-
};
|
|
57
|
-
const colorStyleKey = {
|
|
58
|
-
backgroundColor: true,
|
|
59
|
-
color: true,
|
|
60
|
-
borderColor: true,
|
|
61
|
-
borderLeftColor: true,
|
|
62
|
-
borderRightColor: true,
|
|
63
|
-
borderTopColor: true,
|
|
64
|
-
borderBottomColor: true
|
|
65
|
-
};
|
|
66
|
-
const layoutStyleKey = {
|
|
67
|
-
height: true,
|
|
68
|
-
width: true,
|
|
69
|
-
minHeight: true,
|
|
70
|
-
maxHeight: true,
|
|
71
|
-
minWidth: true,
|
|
72
|
-
maxWidth: true
|
|
73
|
-
};
|
|
74
|
-
function hasAnimatedLayoutKey(style, isDark, animateOnly) {
|
|
75
|
-
for (const key in layoutStyleKey) {
|
|
76
|
-
if (animateOnly && !animateOnly.includes(key)) continue;
|
|
77
|
-
if (typeof resolveDynamicValue(style[key], isDark) === "number") return true;
|
|
78
|
-
}
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
function isAnimatableColor(value) {
|
|
82
|
-
return typeof value === "string" && (0, import_react_native.processColor)(value) != null;
|
|
83
|
-
}
|
|
84
|
-
const costlyToAnimateStyleKey = {
|
|
85
|
-
borderRadius: true,
|
|
86
|
-
borderTopLeftRadius: true,
|
|
87
|
-
borderTopRightRadius: true,
|
|
88
|
-
borderBottomLeftRadius: true,
|
|
89
|
-
borderBottomRightRadius: true,
|
|
90
|
-
borderWidth: true,
|
|
91
|
-
borderLeftWidth: true,
|
|
92
|
-
borderRightWidth: true,
|
|
93
|
-
borderTopWidth: true,
|
|
94
|
-
borderBottomWidth: true,
|
|
95
|
-
...colorStyleKey
|
|
96
|
-
};
|
|
97
|
-
const AnimatedView = import_react_native.Animated.View;
|
|
98
|
-
const AnimatedText = import_react_native.Animated.Text;
|
|
99
|
-
function useAnimatedNumber(initial) {
|
|
100
|
-
const state = import_react.default.useRef(null);
|
|
101
|
-
if (!state.current) {
|
|
102
|
-
state.current = {
|
|
103
|
-
composite: null,
|
|
104
|
-
val: new import_react_native.Animated.Value(initial),
|
|
105
|
-
strategy: { type: "spring" }
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
getInstance() {
|
|
110
|
-
return state.current.val;
|
|
111
|
-
},
|
|
112
|
-
getValue() {
|
|
113
|
-
return state.current.val["_value"];
|
|
114
|
-
},
|
|
115
|
-
stop() {
|
|
116
|
-
state.current.composite?.stop();
|
|
117
|
-
state.current.composite = null;
|
|
118
|
-
},
|
|
119
|
-
setValue(next, { type, ...config } = { type: "spring" }, onFinish) {
|
|
120
|
-
const val = state.current.val;
|
|
121
|
-
const handleFinish = onFinish ? ({ finished }) => finished ? onFinish() : null : void 0;
|
|
122
|
-
if (type === "direct") {
|
|
123
|
-
val.setValue(next);
|
|
124
|
-
} else if (type === "spring") {
|
|
125
|
-
state.current.composite?.stop();
|
|
126
|
-
const composite = import_react_native.Animated.spring(val, {
|
|
127
|
-
...config,
|
|
128
|
-
toValue: next,
|
|
129
|
-
useNativeDriver: isFabric
|
|
130
|
-
});
|
|
131
|
-
composite.start(handleFinish);
|
|
132
|
-
state.current.composite = composite;
|
|
133
|
-
} else {
|
|
134
|
-
state.current.composite?.stop();
|
|
135
|
-
const composite = import_react_native.Animated.timing(val, {
|
|
136
|
-
...config,
|
|
137
|
-
toValue: next,
|
|
138
|
-
useNativeDriver: isFabric
|
|
139
|
-
});
|
|
140
|
-
composite.start(handleFinish);
|
|
141
|
-
state.current.composite = composite;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
const useAnimatedNumberReaction = ({ value }, onValue) => {
|
|
147
|
-
const onChange = (0, import_web.useEvent)((current) => {
|
|
148
|
-
onValue(current.value);
|
|
149
|
-
});
|
|
150
|
-
import_react.default.useEffect(() => {
|
|
151
|
-
const id = value.getInstance().addListener(onChange);
|
|
152
|
-
return () => {
|
|
153
|
-
value.getInstance().removeListener(id);
|
|
154
|
-
};
|
|
155
|
-
}, [value, onChange]);
|
|
156
|
-
};
|
|
157
|
-
const useAnimatedNumberStyle = (value, getStyle) => {
|
|
158
|
-
const instance = value.getInstance();
|
|
159
|
-
const animatedStyle = getStyle(instance);
|
|
160
|
-
const usesAnimatedNode = hasAnimatedNode(animatedStyle);
|
|
161
|
-
const [current, setCurrent] = import_react.default.useState(value.getValue());
|
|
162
|
-
import_react.default.useEffect(() => {
|
|
163
|
-
if (usesAnimatedNode) return;
|
|
164
|
-
const id = instance.addListener(({ value: next }) => {
|
|
165
|
-
setCurrent(next);
|
|
166
|
-
});
|
|
167
|
-
return () => {
|
|
168
|
-
instance.removeListener(id);
|
|
169
|
-
};
|
|
170
|
-
}, [instance, usesAnimatedNode]);
|
|
171
|
-
return usesAnimatedNode ? animatedStyle : getStyle(current);
|
|
172
|
-
};
|
|
173
|
-
function hasAnimatedNode(value) {
|
|
174
|
-
if (!value || typeof value !== "object") return false;
|
|
175
|
-
if (typeof value.__getValue === "function") return true;
|
|
176
|
-
if (Array.isArray(value)) return value.some(hasAnimatedNode);
|
|
177
|
-
return Object.values(value).some(hasAnimatedNode);
|
|
178
|
-
}
|
|
179
|
-
const useAnimatedNumbersStyle = (vals, getStyle) => {
|
|
180
|
-
return getStyle(...vals.map((v) => v.getInstance()));
|
|
181
|
-
};
|
|
182
|
-
function createAnimations(animations, options) {
|
|
183
|
-
const nativeDriver = options?.useNativeDriver ?? isFabric;
|
|
184
|
-
return {
|
|
185
|
-
inputStyle: "value",
|
|
186
|
-
outputStyle: "inline",
|
|
187
|
-
avoidReRenders: true,
|
|
188
|
-
animations,
|
|
189
|
-
needsCustomComponent: true,
|
|
190
|
-
View: AnimatedView,
|
|
191
|
-
Text: AnimatedText,
|
|
192
|
-
useAnimatedNumber,
|
|
193
|
-
useAnimatedNumberReaction,
|
|
194
|
-
useAnimatedNumberStyle,
|
|
195
|
-
useAnimatedNumbersStyle,
|
|
196
|
-
usePresence: import_use_presence.usePresence,
|
|
197
|
-
ResetPresence: import_use_presence.ResetPresence,
|
|
198
|
-
useAnimations: ({ props, onTransition, style, componentState, presence, stateRef, useStyleEmitter }) => {
|
|
199
|
-
const isDisabled = import_constants.isWeb && componentState.unmounted === true;
|
|
200
|
-
const isExiting = presence?.[0] === false;
|
|
201
|
-
const sendExitComplete = presence?.[1];
|
|
202
|
-
const onTransitionRef = import_react.default.useRef(onTransition);
|
|
203
|
-
onTransitionRef.current = onTransition;
|
|
204
|
-
const emit = (phase, cause, finished) => {
|
|
205
|
-
onTransitionRef.current?.(phase === "end" ? {
|
|
206
|
-
phase,
|
|
207
|
-
cause,
|
|
208
|
-
finished
|
|
209
|
-
} : {
|
|
210
|
-
phase,
|
|
211
|
-
cause
|
|
212
|
-
});
|
|
213
|
-
};
|
|
214
|
-
const [, themeState] = (0, import_internal_runtime.useThemeWithState)({});
|
|
215
|
-
const isDark = themeState?.scheme === "dark" || themeState?.name?.startsWith("dark");
|
|
216
|
-
const animateStyles = import_react.default.useRef({});
|
|
217
|
-
const animatedTranforms = import_react.default.useRef([]);
|
|
218
|
-
const animationsState = import_react.default.useRef(/* @__PURE__ */ new WeakMap());
|
|
219
|
-
const pseudoActiveRef = import_react.default.useRef(false);
|
|
220
|
-
const exitCycleIdRef = import_react.default.useRef(0);
|
|
221
|
-
const exitCompletedRef = import_react.default.useRef(false);
|
|
222
|
-
const wasExitingRef = import_react.default.useRef(false);
|
|
223
|
-
const enterStartedRef = import_react.default.useRef(false);
|
|
224
|
-
const exitStartedRef = import_react.default.useRef(false);
|
|
225
|
-
const updateInFlightRef = import_react.default.useRef(false);
|
|
226
|
-
const updateCycleIdRef = import_react.default.useRef(0);
|
|
227
|
-
const prevStyleSigRef = import_react.default.useRef(null);
|
|
228
|
-
const justStartedExiting = isExiting && !wasExitingRef.current;
|
|
229
|
-
const justStoppedExiting = !isExiting && wasExitingRef.current;
|
|
230
|
-
if (justStartedExiting) {
|
|
231
|
-
exitCycleIdRef.current++;
|
|
232
|
-
exitCompletedRef.current = false;
|
|
233
|
-
}
|
|
234
|
-
if (justStoppedExiting) {
|
|
235
|
-
exitCycleIdRef.current++;
|
|
236
|
-
}
|
|
237
|
-
const animateOnly = props.animateOnly || [];
|
|
238
|
-
const hasTransitionOnly = !!props.animateOnly;
|
|
239
|
-
const isEntering = !!componentState.unmounted;
|
|
240
|
-
const wasEnteringRef = import_react.default.useRef(isEntering);
|
|
241
|
-
const justFinishedEntering = wasEnteringRef.current && !isEntering;
|
|
242
|
-
import_react.default.useEffect(() => {
|
|
243
|
-
wasEnteringRef.current = isEntering;
|
|
244
|
-
});
|
|
245
|
-
const args = [
|
|
246
|
-
JSON.stringify(style),
|
|
247
|
-
componentState,
|
|
248
|
-
isExiting,
|
|
249
|
-
!!onTransition,
|
|
250
|
-
isDark,
|
|
251
|
-
justFinishedEntering,
|
|
252
|
-
hasTransitionOnly
|
|
253
|
-
];
|
|
254
|
-
const res = import_react.default.useMemo(() => {
|
|
255
|
-
const runners = [];
|
|
256
|
-
const completions = [];
|
|
257
|
-
const animationState = isExiting ? "exit" : isEntering || justFinishedEntering ? "enter" : "default";
|
|
258
|
-
const nonAnimatedStyle = {};
|
|
259
|
-
const useNativeDriverForNode = nativeDriver && !hasAnimatedLayoutKey(style, isDark, hasTransitionOnly ? animateOnly : void 0);
|
|
260
|
-
const seenAnimateKeys = /* @__PURE__ */ new Set();
|
|
261
|
-
let sawTransform = false;
|
|
262
|
-
let transformCount = 0;
|
|
263
|
-
for (const key in style) {
|
|
264
|
-
const rawVal = style[key];
|
|
265
|
-
const val = resolveDynamicValue(rawVal, isDark);
|
|
266
|
-
if (val === void 0) continue;
|
|
267
|
-
if (isDisabled) {
|
|
268
|
-
continue;
|
|
269
|
-
}
|
|
270
|
-
if (animatedStyleKey[key] == null && !costlyToAnimateStyleKey[key] && !layoutStyleKey[key]) {
|
|
271
|
-
nonAnimatedStyle[key] = val;
|
|
272
|
-
continue;
|
|
273
|
-
}
|
|
274
|
-
if (hasTransitionOnly && !animateOnly.includes(key)) {
|
|
275
|
-
nonAnimatedStyle[key] = val;
|
|
276
|
-
continue;
|
|
277
|
-
}
|
|
278
|
-
if (layoutStyleKey[key] && typeof val !== "number") {
|
|
279
|
-
nonAnimatedStyle[key] = val;
|
|
280
|
-
continue;
|
|
281
|
-
}
|
|
282
|
-
if (colorStyleKey[key] && !isAnimatableColor(val)) {
|
|
283
|
-
nonAnimatedStyle[key] = val;
|
|
284
|
-
continue;
|
|
285
|
-
}
|
|
286
|
-
if (key !== "transform") {
|
|
287
|
-
animateStyles.current[key] = update(key, animateStyles.current[key], val);
|
|
288
|
-
seenAnimateKeys.add(key);
|
|
289
|
-
continue;
|
|
290
|
-
}
|
|
291
|
-
if (!val) continue;
|
|
292
|
-
if (typeof val === "string") {
|
|
293
|
-
console.warn(`Warning: Tamagui can't animate string transforms yet!`);
|
|
294
|
-
continue;
|
|
295
|
-
}
|
|
296
|
-
sawTransform = true;
|
|
297
|
-
for (const transform of val) {
|
|
298
|
-
if (!transform) continue;
|
|
299
|
-
const index = transformCount++;
|
|
300
|
-
const tkey = Object.keys(transform)[0];
|
|
301
|
-
const currentTransform = animatedTranforms.current[index]?.[tkey];
|
|
302
|
-
animatedTranforms.current[index] = { [tkey]: update(tkey, currentTransform, transform[tkey]) };
|
|
303
|
-
animatedTranforms.current = [...animatedTranforms.current];
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
if (!isExiting && !isDisabled && !pseudoActiveRef.current) {
|
|
307
|
-
for (const k in animateStyles.current) {
|
|
308
|
-
if (!seenAnimateKeys.has(k)) delete animateStyles.current[k];
|
|
309
|
-
}
|
|
310
|
-
if (!sawTransform) {
|
|
311
|
-
if (animatedTranforms.current.length) animatedTranforms.current = [];
|
|
312
|
-
} else if (animatedTranforms.current.length > transformCount) {
|
|
313
|
-
animatedTranforms.current = animatedTranforms.current.slice(0, transformCount);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
const animatedTransformStyle = animatedTranforms.current.length > 0 ? { transform: animatedTranforms.current.map((r) => {
|
|
317
|
-
const key = Object.keys(r)[0];
|
|
318
|
-
const val = animationsState.current.get(r[key])?.interpolation || r[key];
|
|
319
|
-
return { [key]: val };
|
|
320
|
-
}) } : {};
|
|
321
|
-
const animatedStyle = {
|
|
322
|
-
...Object.fromEntries(Object.entries(animateStyles.current).map(([k, v]) => [k, animationsState.current.get(v)?.interpolation || v])),
|
|
323
|
-
...animatedTransformStyle
|
|
324
|
-
};
|
|
325
|
-
return {
|
|
326
|
-
runners,
|
|
327
|
-
completions,
|
|
328
|
-
style: [nonAnimatedStyle, animatedStyle]
|
|
329
|
-
};
|
|
330
|
-
function update(key, animated, valIn) {
|
|
331
|
-
const isColorStyleKey = colorStyleKey[key];
|
|
332
|
-
const [val, type] = isColorStyleKey ? [0, void 0] : getValue(valIn);
|
|
333
|
-
let animateToValue = val;
|
|
334
|
-
const value = animated || new import_react_native.Animated.Value(val);
|
|
335
|
-
const curInterpolation = animationsState.current.get(value);
|
|
336
|
-
let interpolateArgs;
|
|
337
|
-
if (type) {
|
|
338
|
-
interpolateArgs = getInterpolated(curInterpolation?.current ?? value["_value"], val, type);
|
|
339
|
-
animationsState.current.set(value, {
|
|
340
|
-
interpolation: value.interpolate(interpolateArgs),
|
|
341
|
-
current: val
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
if (isColorStyleKey) {
|
|
345
|
-
animateToValue = curInterpolation?.animateToValue ? 0 : 1;
|
|
346
|
-
interpolateArgs = getColorInterpolated(curInterpolation?.current, valIn, animateToValue);
|
|
347
|
-
animationsState.current.set(value, {
|
|
348
|
-
current: valIn,
|
|
349
|
-
interpolation: value.interpolate(interpolateArgs),
|
|
350
|
-
animateToValue: curInterpolation?.animateToValue ? 0 : 1
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
if (value) {
|
|
354
|
-
const animationConfig = getAnimationConfig(key, animations, props.transition, animationState);
|
|
355
|
-
let resolve;
|
|
356
|
-
const promise = new Promise((res2) => {
|
|
357
|
-
resolve = res2;
|
|
358
|
-
});
|
|
359
|
-
completions.push(promise);
|
|
360
|
-
runners.push(() => {
|
|
361
|
-
value.stopAnimation();
|
|
362
|
-
function getAnimation() {
|
|
363
|
-
return import_react_native.Animated[animationConfig.type || "spring"](value, {
|
|
364
|
-
toValue: animateToValue,
|
|
365
|
-
...animationConfig,
|
|
366
|
-
useNativeDriver: useNativeDriverForNode
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
const animation = animationConfig.delay ? import_react_native.Animated.sequence([import_react_native.Animated.delay(animationConfig.delay), getAnimation()]) : getAnimation();
|
|
370
|
-
animation.start(({ finished }) => {
|
|
371
|
-
if (finished || isExiting) {
|
|
372
|
-
resolve();
|
|
373
|
-
}
|
|
374
|
-
});
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
if (process.env.NODE_ENV === "development") {
|
|
378
|
-
if (props["debug"] === "verbose") {
|
|
379
|
-
console.info(" 💠 animate", key, `from (${value["_value"]}) to`, valIn, `(${val})`, "type", type, "interpolate", interpolateArgs);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
return value;
|
|
383
|
-
}
|
|
384
|
-
}, args);
|
|
385
|
-
import_react.default.useEffect(() => {
|
|
386
|
-
wasExitingRef.current = isExiting;
|
|
387
|
-
});
|
|
388
|
-
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
389
|
-
if (justStoppedExiting && exitStartedRef.current && !exitCompletedRef.current) {
|
|
390
|
-
exitStartedRef.current = false;
|
|
391
|
-
emit("end", "exit", false);
|
|
392
|
-
}
|
|
393
|
-
}, [justStoppedExiting]);
|
|
394
|
-
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
395
|
-
res.runners.forEach((r) => r());
|
|
396
|
-
const cycleId = exitCycleIdRef.current;
|
|
397
|
-
const cause = isExiting ? "exit" : isEntering || justFinishedEntering ? "enter" : "update";
|
|
398
|
-
if (cause === "exit") {
|
|
399
|
-
if (enterStartedRef.current) {
|
|
400
|
-
enterStartedRef.current = false;
|
|
401
|
-
emit("end", "enter", false);
|
|
402
|
-
}
|
|
403
|
-
if (updateInFlightRef.current) {
|
|
404
|
-
updateInFlightRef.current = false;
|
|
405
|
-
updateCycleIdRef.current++;
|
|
406
|
-
emit("end", "update", false);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
if (cause === "update") {
|
|
410
|
-
const sig = args[0];
|
|
411
|
-
if (prevStyleSigRef.current === null || prevStyleSigRef.current === sig) {
|
|
412
|
-
prevStyleSigRef.current = sig;
|
|
413
|
-
return;
|
|
414
|
-
}
|
|
415
|
-
prevStyleSigRef.current = sig;
|
|
416
|
-
if (res.completions.length === 0) return;
|
|
417
|
-
if (updateInFlightRef.current) {
|
|
418
|
-
emit("end", "update", false);
|
|
419
|
-
}
|
|
420
|
-
updateInFlightRef.current = true;
|
|
421
|
-
const uid = ++updateCycleIdRef.current;
|
|
422
|
-
emit("start", "update");
|
|
423
|
-
Promise.all(res.completions).then(() => {
|
|
424
|
-
if (uid !== updateCycleIdRef.current) return;
|
|
425
|
-
updateInFlightRef.current = false;
|
|
426
|
-
emit("end", "update", true);
|
|
427
|
-
});
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
prevStyleSigRef.current = args[0];
|
|
431
|
-
if (res.completions.length === 0) {
|
|
432
|
-
emit("start", cause);
|
|
433
|
-
emit("end", cause, true);
|
|
434
|
-
if (isExiting && !exitCompletedRef.current) {
|
|
435
|
-
exitCompletedRef.current = true;
|
|
436
|
-
sendExitComplete?.();
|
|
437
|
-
}
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
if (cause === "enter" && !enterStartedRef.current) {
|
|
441
|
-
enterStartedRef.current = true;
|
|
442
|
-
emit("start", "enter");
|
|
443
|
-
}
|
|
444
|
-
if (cause === "exit" && !exitStartedRef.current) {
|
|
445
|
-
exitStartedRef.current = true;
|
|
446
|
-
emit("start", "exit");
|
|
447
|
-
}
|
|
448
|
-
Promise.all(res.completions).then(() => {
|
|
449
|
-
if (isExiting && cycleId !== exitCycleIdRef.current) return;
|
|
450
|
-
if (isExiting && exitCompletedRef.current) return;
|
|
451
|
-
if (isExiting) {
|
|
452
|
-
if (exitStartedRef.current) {
|
|
453
|
-
exitStartedRef.current = false;
|
|
454
|
-
emit("end", "exit", true);
|
|
455
|
-
}
|
|
456
|
-
exitCompletedRef.current = true;
|
|
457
|
-
sendExitComplete?.();
|
|
458
|
-
} else if (enterStartedRef.current) {
|
|
459
|
-
enterStartedRef.current = false;
|
|
460
|
-
emit("end", "enter", true);
|
|
461
|
-
}
|
|
462
|
-
});
|
|
463
|
-
}, args);
|
|
464
|
-
useStyleEmitter?.((nextStyle, _effectiveTransition, pseudoActive) => {
|
|
465
|
-
pseudoActiveRef.current = pseudoActive === true;
|
|
466
|
-
const runners = [];
|
|
467
|
-
const seenAnimateKeys = /* @__PURE__ */ new Set();
|
|
468
|
-
let transformCount = 0;
|
|
469
|
-
let animatedShapeChanged = false;
|
|
470
|
-
const useNativeDriverForNode = nativeDriver && !hasAnimatedLayoutKey(nextStyle, isDark) && !Object.keys(animateStyles.current).some((key) => layoutStyleKey[key]);
|
|
471
|
-
for (const key in nextStyle) {
|
|
472
|
-
const rawVal = nextStyle[key];
|
|
473
|
-
const val = resolveDynamicValue(rawVal, isDark);
|
|
474
|
-
if (val === void 0) continue;
|
|
475
|
-
if (key === "transform" && Array.isArray(val)) {
|
|
476
|
-
for (const transform of val) {
|
|
477
|
-
if (!transform) continue;
|
|
478
|
-
const index = transformCount++;
|
|
479
|
-
const tkey = Object.keys(transform)[0];
|
|
480
|
-
const currentTransform = animatedTranforms.current[index]?.[tkey];
|
|
481
|
-
if (!currentTransform) animatedShapeChanged = true;
|
|
482
|
-
animatedTranforms.current[index] = { [tkey]: update(tkey, currentTransform, transform[tkey]) };
|
|
483
|
-
}
|
|
484
|
-
} else if (animatedStyleKey[key] != null || costlyToAnimateStyleKey[key] || layoutStyleKey[key]) {
|
|
485
|
-
if (layoutStyleKey[key] && typeof val !== "number") continue;
|
|
486
|
-
if (colorStyleKey[key] && !isAnimatableColor(val)) continue;
|
|
487
|
-
if (!animateStyles.current[key]) animatedShapeChanged = true;
|
|
488
|
-
animateStyles.current[key] = update(key, animateStyles.current[key], val);
|
|
489
|
-
seenAnimateKeys.add(key);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
for (const key in animateStyles.current) {
|
|
493
|
-
if (!seenAnimateKeys.has(key)) {
|
|
494
|
-
delete animateStyles.current[key];
|
|
495
|
-
animatedShapeChanged = true;
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
if (animatedTranforms.current.length > transformCount) {
|
|
499
|
-
animatedTranforms.current = animatedTranforms.current.slice(0, transformCount);
|
|
500
|
-
animatedShapeChanged = true;
|
|
501
|
-
}
|
|
502
|
-
runners.forEach((r) => r());
|
|
503
|
-
if (animatedShapeChanged && stateRef.current.nextState) {
|
|
504
|
-
stateRef.current.baseSetStateShallow?.(stateRef.current.nextState);
|
|
505
|
-
}
|
|
506
|
-
function update(key, animated, valIn) {
|
|
507
|
-
const isColor = colorStyleKey[key];
|
|
508
|
-
const [numVal, type] = isColor ? [0, void 0] : getValue(valIn);
|
|
509
|
-
let animateToValue = numVal;
|
|
510
|
-
const value = animated || new import_react_native.Animated.Value(numVal);
|
|
511
|
-
const curInterpolation = animationsState.current.get(value);
|
|
512
|
-
if (type) {
|
|
513
|
-
animationsState.current.set(value, {
|
|
514
|
-
interpolation: value.interpolate(getInterpolated(curInterpolation?.current ?? value["_value"], numVal, type)),
|
|
515
|
-
current: numVal
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
if (isColor) {
|
|
519
|
-
animateToValue = curInterpolation?.animateToValue ? 0 : 1;
|
|
520
|
-
animationsState.current.set(value, {
|
|
521
|
-
current: valIn,
|
|
522
|
-
interpolation: value.interpolate(getColorInterpolated(curInterpolation?.current, valIn, animateToValue)),
|
|
523
|
-
animateToValue: curInterpolation?.animateToValue ? 0 : 1
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
const animationConfig = getAnimationConfig(key, animations, props.transition, "default");
|
|
527
|
-
runners.push(() => {
|
|
528
|
-
value.stopAnimation();
|
|
529
|
-
const anim = import_react_native.Animated[animationConfig.type || "spring"](value, {
|
|
530
|
-
toValue: animateToValue,
|
|
531
|
-
...animationConfig,
|
|
532
|
-
useNativeDriver: useNativeDriverForNode
|
|
533
|
-
});
|
|
534
|
-
(animationConfig.delay ? import_react_native.Animated.sequence([import_react_native.Animated.delay(animationConfig.delay), anim]) : anim).start();
|
|
535
|
-
});
|
|
536
|
-
return value;
|
|
537
|
-
}
|
|
538
|
-
});
|
|
539
|
-
if (process.env.NODE_ENV === "development") {
|
|
540
|
-
if (props["debug"] === "verbose") {
|
|
541
|
-
console.info(`Animated`, {
|
|
542
|
-
response: res,
|
|
543
|
-
inputStyle: style,
|
|
544
|
-
isExiting
|
|
545
|
-
});
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
return res;
|
|
549
|
-
}
|
|
550
|
-
};
|
|
551
|
-
}
|
|
552
|
-
function getColorInterpolated(currentColor, nextColor, animateToValue) {
|
|
553
|
-
const inputRange = [0, 1];
|
|
554
|
-
const outputRange = [currentColor ? currentColor : nextColor, nextColor];
|
|
555
|
-
if (animateToValue === 0) {
|
|
556
|
-
outputRange.reverse();
|
|
557
|
-
}
|
|
558
|
-
return {
|
|
559
|
-
inputRange,
|
|
560
|
-
outputRange
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
function getInterpolated(current, next, postfix = "deg") {
|
|
564
|
-
if (next === current) {
|
|
565
|
-
current = next - 1e-9;
|
|
566
|
-
}
|
|
567
|
-
const inputRange = [current, next];
|
|
568
|
-
const outputRange = [`${current}${postfix}`, `${next}${postfix}`];
|
|
569
|
-
if (next < current) {
|
|
570
|
-
inputRange.reverse();
|
|
571
|
-
outputRange.reverse();
|
|
572
|
-
}
|
|
573
|
-
return {
|
|
574
|
-
inputRange,
|
|
575
|
-
outputRange
|
|
576
|
-
};
|
|
577
|
-
}
|
|
578
|
-
function getAnimationConfig(key, animations, transition, animationState = "default") {
|
|
579
|
-
const normalized = (0, import_animation_helpers.normalizeTransition)(transition);
|
|
580
|
-
const shortKey = transformShorthands[key];
|
|
581
|
-
const propAnimation = normalized.properties[key] ?? normalized.properties[shortKey];
|
|
582
|
-
let animationType = null;
|
|
583
|
-
let extraConf = {};
|
|
584
|
-
if (typeof propAnimation === "string") {
|
|
585
|
-
animationType = propAnimation;
|
|
586
|
-
} else if (propAnimation && typeof propAnimation === "object") {
|
|
587
|
-
animationType = propAnimation.type || (0, import_animation_helpers.getEffectiveAnimation)(normalized, animationState);
|
|
588
|
-
extraConf = propAnimation;
|
|
589
|
-
} else {
|
|
590
|
-
animationType = (0, import_animation_helpers.getEffectiveAnimation)(normalized, animationState);
|
|
591
|
-
}
|
|
592
|
-
if (normalized.delay && !extraConf.delay) {
|
|
593
|
-
extraConf = {
|
|
594
|
-
...extraConf,
|
|
595
|
-
delay: normalized.delay
|
|
596
|
-
};
|
|
597
|
-
}
|
|
598
|
-
const found = animationType ? animations[animationType] : {};
|
|
599
|
-
return {
|
|
600
|
-
...found,
|
|
601
|
-
...normalized.config,
|
|
602
|
-
...extraConf
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
const transformShorthands = {
|
|
606
|
-
x: "translateX",
|
|
607
|
-
y: "translateY",
|
|
608
|
-
translateX: "x",
|
|
609
|
-
translateY: "y"
|
|
610
|
-
};
|
|
611
|
-
function getValue(input, isColor = false) {
|
|
612
|
-
if (typeof input !== "string") {
|
|
613
|
-
return [input];
|
|
614
|
-
}
|
|
615
|
-
const [_, number, after] = input.match(/(-?(?:\d+\.?\d*|\.\d+))(deg|%|px)?/) ?? [];
|
|
616
|
-
return [+number, after];
|
|
617
|
-
}
|