@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.
- package/dist/cjs/createAnimations.cjs +385 -220
- package/dist/cjs/createAnimations.native.js +451 -273
- package/dist/cjs/createAnimations.native.js.map +1 -1
- package/dist/cjs/index.cjs +7 -5
- package/dist/cjs/index.native.js +7 -5
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/polyfill.cjs +3 -1
- package/dist/cjs/polyfill.native.js +3 -1
- package/dist/cjs/polyfill.native.js.map +1 -1
- package/dist/esm/createAnimations.mjs +355 -193
- package/dist/esm/createAnimations.mjs.map +1 -1
- package/dist/esm/createAnimations.native.js +421 -246
- package/dist/esm/createAnimations.native.js.map +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.js.map +1 -6
- package/dist/esm/polyfill.mjs +3 -1
- package/dist/esm/polyfill.mjs.map +1 -1
- package/dist/esm/polyfill.native.js +3 -1
- package/dist/esm/polyfill.native.js.map +1 -1
- package/package.json +10 -13
- package/src/createAnimations.tsx +187 -25
- package/types/createAnimations.d.ts +5 -1
- package/types/createAnimations.d.ts.map +5 -10
- package/types/index.d.ts.map +2 -2
- package/types/polyfill.d.ts.map +2 -2
- package/dist/cjs/createAnimations.js +0 -297
- package/dist/cjs/createAnimations.js.map +0 -6
- package/dist/cjs/index.js +0 -16
- package/dist/cjs/index.js.map +0 -6
- package/dist/cjs/polyfill.js +0 -2
- package/dist/cjs/polyfill.js.map +0 -6
- package/dist/esm/createAnimations.js +0 -278
- package/dist/esm/createAnimations.js.map +0 -6
- package/dist/esm/polyfill.js +0 -2
- package/dist/esm/polyfill.js.map +0 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (type === "direct")
|
|
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
|
|
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:
|
|
94
|
+
useNativeDriver: isFabric
|
|
88
95
|
});
|
|
89
|
-
composite.start(handleFinish)
|
|
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
|
|
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:
|
|
104
|
+
useNativeDriver: isFabric
|
|
97
105
|
});
|
|
98
|
-
composite1.start(handleFinish)
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
function
|
|
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:
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
var
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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)
|
|
292
|
+
valIn, animateToValue);
|
|
293
|
+
animationsState.current.set(value, {
|
|
254
294
|
current: valIn,
|
|
255
295
|
interpolation: value.interpolate(interpolateArgs),
|
|
256
|
-
animateToValue: curInterpolation
|
|
257
|
-
})
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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
|
-
|
|
284
|
-
|
|
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
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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)
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
305
|
-
|
|
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
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
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
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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] :
|
|
346
|
-
if (typeof input
|
|
347
|
-
|
|
348
|
-
|
|
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
|