@hanzogui/animations-react-native 3.0.5 → 4.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/createAnimations.cjs +356 -252
- package/dist/cjs/createAnimations.native.js +410 -315
- 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 +325 -224
- package/dist/esm/createAnimations.mjs.map +1 -1
- package/dist/esm/createAnimations.native.js +379 -287
- package/dist/esm/createAnimations.native.js.map +1 -1
- 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 +6 -6
- package/src/createAnimations.tsx +9 -1
- package/types/createAnimations.d.ts +1 -0
- package/types/createAnimations.d.ts.map +2 -2
|
@@ -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
|
|
10
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
11
11
|
}
|
|
12
|
-
var isFabric = !isWeb && typeof global
|
|
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
|
-
|
|
47
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
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") {
|
|
83
89
|
var _state_current_composite;
|
|
84
|
-
(_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();
|
|
85
91
|
var composite = Animated.spring(val, {
|
|
86
92
|
...config,
|
|
87
93
|
toValue: next,
|
|
88
94
|
useNativeDriver: isFabric
|
|
89
95
|
});
|
|
90
|
-
composite.start(handleFinish)
|
|
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
|
|
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)
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
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:
|
|
138
|
+
isReactNative: true,
|
|
126
139
|
inputStyle: "value",
|
|
127
140
|
outputStyle: "inline",
|
|
128
|
-
avoidReRenders:
|
|
141
|
+
avoidReRenders: true,
|
|
129
142
|
animations,
|
|
130
|
-
needsCustomComponent:
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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)
|
|
292
|
+
valIn, animateToValue);
|
|
293
|
+
animationsState.current.set(value, {
|
|
264
294
|
current: valIn,
|
|
265
295
|
interpolation: value.interpolate(interpolateArgs),
|
|
266
|
-
animateToValue: curInterpolation
|
|
267
|
-
})
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
-
|
|
294
|
-
|
|
331
|
+
return value;
|
|
332
|
+
}
|
|
333
|
+
}, args);
|
|
334
|
+
React.useEffect(function () {
|
|
295
335
|
wasExitingRef.current = isExiting;
|
|
296
|
-
})
|
|
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
|
|
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 =
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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)
|
|
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
|
-
|
|
315
|
-
if (val
|
|
316
|
-
|
|
317
|
-
|
|
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 =
|
|
321
|
-
var [index, transform] = _step.value
|
|
322
|
-
|
|
323
|
-
if (transform)
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
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 =
|
|
386
|
+
_didIteratorError = true;
|
|
387
|
+
_iteratorError = err;
|
|
333
388
|
} finally {
|
|
334
389
|
try {
|
|
335
|
-
!_iteratorNormalCompletion && _iterator.return != null
|
|
390
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
391
|
+
_iterator.return();
|
|
392
|
+
}
|
|
336
393
|
} finally {
|
|
337
|
-
if (_didIteratorError)
|
|
394
|
+
if (_didIteratorError) {
|
|
395
|
+
throw _iteratorError;
|
|
396
|
+
}
|
|
338
397
|
}
|
|
339
398
|
}
|
|
340
|
-
} else (animatedStyleKey[key] != null || costlyToAnimateStyleKey[key])
|
|
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
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
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
|
|
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
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
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
|
-
|
|
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
|
-
})
|
|
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
|
-
}
|
|
375
|
-
|
|
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
|
-
|
|
385
|
-
|
|
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
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
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
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
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] :
|
|
429
|
-
if (typeof input
|
|
430
|
-
|
|
431
|
-
|
|
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
|