@tamagui/animations-react-native 2.7.6 → 3.0.0-beta.637.1

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