@tamagui/animations-react-native 2.0.0-rc.4 → 2.0.0-rc.40

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