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