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