@hanzogui/animations-reanimated 2.0.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/LICENSE +21 -0
- package/dist/cjs/createAnimations.cjs +507 -0
- package/dist/cjs/createAnimations.native.js +623 -0
- package/dist/cjs/createAnimations.native.js.map +1 -0
- package/dist/cjs/index.cjs +18 -0
- package/dist/cjs/index.native.js +21 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/esm/createAnimations.mjs +473 -0
- package/dist/esm/createAnimations.mjs.map +1 -0
- package/dist/esm/createAnimations.native.js +586 -0
- package/dist/esm/createAnimations.native.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +2 -0
- package/dist/esm/index.native.js.map +1 -0
- package/package.json +52 -0
- package/src/createAnimations.tsx +935 -0
- package/src/index.ts +1 -0
- package/types/createAnimations.d.ts +40 -0
- package/types/createAnimations.d.ts.map +11 -0
- package/types/index.d.ts +3 -0
- package/types/index.d.ts.map +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nate Wienert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var createAnimations_exports = {};
|
|
33
|
+
__export(createAnimations_exports, {
|
|
34
|
+
createAnimations: () => createAnimations
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(createAnimations_exports);
|
|
37
|
+
var import_animation_helpers = require("@hanzogui/animation-helpers"),
|
|
38
|
+
import_core = require("@hanzogui/core"),
|
|
39
|
+
import_use_presence = require("@hanzogui/use-presence"),
|
|
40
|
+
import_react = __toESM(require("react"), 1),
|
|
41
|
+
import_react_native_reanimated = __toESM(require("react-native-reanimated"), 1),
|
|
42
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
43
|
+
const getDefaultExport = module2 => {
|
|
44
|
+
const mod = module2;
|
|
45
|
+
return (mod.__esModule || mod[Symbol.toStringTag] === "Module") && mod.default || mod;
|
|
46
|
+
},
|
|
47
|
+
Animated = getDefaultExport(import_react_native_reanimated.default),
|
|
48
|
+
resolveDynamicValue = (value, isDark) => {
|
|
49
|
+
if (value !== null && typeof value == "object" && "dynamic" in value && typeof value.dynamic == "object") {
|
|
50
|
+
const dynamic = value.dynamic;
|
|
51
|
+
return isDark ? dynamic.dark : dynamic.light;
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
},
|
|
55
|
+
applyAnimation = (targetValue, config, callback) => {
|
|
56
|
+
"worklet";
|
|
57
|
+
|
|
58
|
+
const delay = config.delay;
|
|
59
|
+
let animatedValue;
|
|
60
|
+
return config.type === "timing" ? animatedValue = (0, import_react_native_reanimated.withTiming)(targetValue, config, callback) : animatedValue = (0, import_react_native_reanimated.withSpring)(targetValue, config, callback), delay && delay > 0 && (animatedValue = (0, import_react_native_reanimated.withDelay)(delay, animatedValue)), animatedValue;
|
|
61
|
+
},
|
|
62
|
+
ANIMATABLE_PROPERTIES = {
|
|
63
|
+
// Transform
|
|
64
|
+
transform: !0,
|
|
65
|
+
// Opacity
|
|
66
|
+
opacity: !0,
|
|
67
|
+
// Dimensions
|
|
68
|
+
height: !0,
|
|
69
|
+
width: !0,
|
|
70
|
+
minWidth: !0,
|
|
71
|
+
minHeight: !0,
|
|
72
|
+
maxWidth: !0,
|
|
73
|
+
maxHeight: !0,
|
|
74
|
+
// Background
|
|
75
|
+
backgroundColor: !0,
|
|
76
|
+
// Border colors
|
|
77
|
+
borderColor: !0,
|
|
78
|
+
borderLeftColor: !0,
|
|
79
|
+
borderRightColor: !0,
|
|
80
|
+
borderTopColor: !0,
|
|
81
|
+
borderBottomColor: !0,
|
|
82
|
+
// Border radius
|
|
83
|
+
borderRadius: !0,
|
|
84
|
+
borderTopLeftRadius: !0,
|
|
85
|
+
borderTopRightRadius: !0,
|
|
86
|
+
borderBottomLeftRadius: !0,
|
|
87
|
+
borderBottomRightRadius: !0,
|
|
88
|
+
// Border width
|
|
89
|
+
borderWidth: !0,
|
|
90
|
+
borderLeftWidth: !0,
|
|
91
|
+
borderRightWidth: !0,
|
|
92
|
+
borderTopWidth: !0,
|
|
93
|
+
borderBottomWidth: !0,
|
|
94
|
+
// Text
|
|
95
|
+
color: !0,
|
|
96
|
+
fontSize: !0,
|
|
97
|
+
fontWeight: !0,
|
|
98
|
+
lineHeight: !0,
|
|
99
|
+
letterSpacing: !0,
|
|
100
|
+
// Position
|
|
101
|
+
left: !0,
|
|
102
|
+
right: !0,
|
|
103
|
+
top: !0,
|
|
104
|
+
bottom: !0,
|
|
105
|
+
// Margin
|
|
106
|
+
margin: !0,
|
|
107
|
+
marginTop: !0,
|
|
108
|
+
marginBottom: !0,
|
|
109
|
+
marginLeft: !0,
|
|
110
|
+
marginRight: !0,
|
|
111
|
+
marginHorizontal: !0,
|
|
112
|
+
marginVertical: !0,
|
|
113
|
+
// Padding
|
|
114
|
+
padding: !0,
|
|
115
|
+
paddingTop: !0,
|
|
116
|
+
paddingBottom: !0,
|
|
117
|
+
paddingLeft: !0,
|
|
118
|
+
paddingRight: !0,
|
|
119
|
+
paddingHorizontal: !0,
|
|
120
|
+
paddingVertical: !0,
|
|
121
|
+
// Flex/Gap
|
|
122
|
+
gap: !0,
|
|
123
|
+
rowGap: !0,
|
|
124
|
+
columnGap: !0,
|
|
125
|
+
flex: !0,
|
|
126
|
+
flexGrow: !0,
|
|
127
|
+
flexShrink: !0
|
|
128
|
+
},
|
|
129
|
+
canAnimateProperty = (key, value, animateOnly) => !(!ANIMATABLE_PROPERTIES[key] || value === "auto" || typeof value == "string" && value.startsWith("calc") || animateOnly && !animateOnly.includes(key));
|
|
130
|
+
function createWebAnimatedComponent(defaultTag) {
|
|
131
|
+
const isText = defaultTag === "span",
|
|
132
|
+
Component = Animated.createAnimatedComponent((0, import_react.forwardRef)((propsIn, ref) => {
|
|
133
|
+
const {
|
|
134
|
+
forwardedRef,
|
|
135
|
+
render = defaultTag,
|
|
136
|
+
...rest
|
|
137
|
+
} = propsIn,
|
|
138
|
+
hostRef = (0, import_react.useRef)(null),
|
|
139
|
+
composedRefs = (0, import_core.useComposedRefs)(forwardedRef, ref, hostRef),
|
|
140
|
+
stateRef = (0, import_react.useRef)({
|
|
141
|
+
get host() {
|
|
142
|
+
return hostRef.current;
|
|
143
|
+
}
|
|
144
|
+
}),
|
|
145
|
+
[, themeState] = (0, import_core.useThemeWithState)({}),
|
|
146
|
+
viewProps = (0, import_core.getSplitStyles)(rest, isText ? import_core.Text.staticConfig : import_core.View.staticConfig, themeState?.theme ?? {}, themeState?.name ?? "", {
|
|
147
|
+
unmounted: !1
|
|
148
|
+
}, {
|
|
149
|
+
isAnimated: !1,
|
|
150
|
+
noClass: !0
|
|
151
|
+
})?.viewProps ?? {},
|
|
152
|
+
Element = render,
|
|
153
|
+
transformedProps = import_core.hooks.usePropsTransform?.(render, viewProps, stateRef, !1);
|
|
154
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Element, {
|
|
155
|
+
...transformedProps,
|
|
156
|
+
ref: composedRefs
|
|
157
|
+
});
|
|
158
|
+
}));
|
|
159
|
+
return Component.acceptRenderProp = !0, Component;
|
|
160
|
+
}
|
|
161
|
+
const AnimatedView = createWebAnimatedComponent("div"),
|
|
162
|
+
AnimatedText = createWebAnimatedComponent("span");
|
|
163
|
+
function buildTransitionConfig(transition, animations, animationState, styleKeys) {
|
|
164
|
+
const normalized = (0, import_animation_helpers.normalizeTransition)(transition),
|
|
165
|
+
effectiveKey = (0, import_animation_helpers.getEffectiveAnimation)(normalized, animationState);
|
|
166
|
+
let base = effectiveKey ? animations[effectiveKey] ?? {
|
|
167
|
+
type: "spring"
|
|
168
|
+
} : {
|
|
169
|
+
type: "spring"
|
|
170
|
+
};
|
|
171
|
+
normalized.delay && (base = {
|
|
172
|
+
...base,
|
|
173
|
+
delay: normalized.delay
|
|
174
|
+
}), normalized.config && (base = {
|
|
175
|
+
...base,
|
|
176
|
+
...normalized.config
|
|
177
|
+
}, base.type !== "timing" && normalized.config.duration !== void 0 && normalized.config.damping === void 0 && normalized.config.stiffness === void 0 && normalized.config.mass === void 0 && (base = {
|
|
178
|
+
...base,
|
|
179
|
+
type: "timing"
|
|
180
|
+
}));
|
|
181
|
+
const propertyConfigs = {};
|
|
182
|
+
for (const key of styleKeys) {
|
|
183
|
+
const propAnimation = normalized.properties[key];
|
|
184
|
+
if (typeof propAnimation == "string") propertyConfigs[key] = animations[propAnimation] ?? base;else if (propAnimation && typeof propAnimation == "object") {
|
|
185
|
+
const configType = propAnimation.type,
|
|
186
|
+
baseForProp = configType ? animations[configType] ?? base : base;
|
|
187
|
+
propertyConfigs[key] = {
|
|
188
|
+
...baseForProp,
|
|
189
|
+
...propAnimation
|
|
190
|
+
};
|
|
191
|
+
} else propertyConfigs[key] = base;
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
baseConfig: base,
|
|
195
|
+
propertyConfigs
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function getStyleKeys(style) {
|
|
199
|
+
const keys = new Set(Object.keys(style));
|
|
200
|
+
if (style.transform && Array.isArray(style.transform)) for (const t of style.transform) t && typeof t == "object" && keys.add(Object.keys(t)[0]);
|
|
201
|
+
return keys;
|
|
202
|
+
}
|
|
203
|
+
function createAnimations(animationsConfig) {
|
|
204
|
+
const animations = {};
|
|
205
|
+
for (const key in animationsConfig) animations[key] = {
|
|
206
|
+
type: "spring",
|
|
207
|
+
...animationsConfig[key]
|
|
208
|
+
};
|
|
209
|
+
return {
|
|
210
|
+
needsCustomComponent: !0,
|
|
211
|
+
View: import_core.isWeb ? AnimatedView : Animated.View,
|
|
212
|
+
Text: import_core.isWeb ? AnimatedText : Animated.Text,
|
|
213
|
+
isReactNative: !0,
|
|
214
|
+
inputStyle: "value",
|
|
215
|
+
outputStyle: "inline",
|
|
216
|
+
avoidReRenders: !0,
|
|
217
|
+
animations,
|
|
218
|
+
usePresence: import_use_presence.usePresence,
|
|
219
|
+
ResetPresence: import_use_presence.ResetPresence,
|
|
220
|
+
// =========================================================================
|
|
221
|
+
// useAnimatedNumber - For imperative animated values
|
|
222
|
+
// =========================================================================
|
|
223
|
+
useAnimatedNumber(initial) {
|
|
224
|
+
const sharedValue = (0, import_react_native_reanimated.useSharedValue)(initial);
|
|
225
|
+
return (0, import_react.useMemo)(() => ({
|
|
226
|
+
getInstance() {
|
|
227
|
+
"worklet";
|
|
228
|
+
|
|
229
|
+
return sharedValue;
|
|
230
|
+
},
|
|
231
|
+
getValue() {
|
|
232
|
+
"worklet";
|
|
233
|
+
|
|
234
|
+
return sharedValue.value;
|
|
235
|
+
},
|
|
236
|
+
setValue(next, config = {
|
|
237
|
+
type: "spring"
|
|
238
|
+
}, onFinish) {
|
|
239
|
+
"worklet";
|
|
240
|
+
|
|
241
|
+
const handleFinish = onFinish ? () => {
|
|
242
|
+
"worklet";
|
|
243
|
+
|
|
244
|
+
(0, import_react_native_reanimated.runOnJS)(onFinish)();
|
|
245
|
+
} : void 0;
|
|
246
|
+
config.type === "direct" ? (sharedValue.value = next, onFinish?.()) : config.type === "spring" ? sharedValue.value = (0, import_react_native_reanimated.withSpring)(next, config, handleFinish) : sharedValue.value = (0, import_react_native_reanimated.withTiming)(next, config, handleFinish);
|
|
247
|
+
},
|
|
248
|
+
stop() {
|
|
249
|
+
"worklet";
|
|
250
|
+
|
|
251
|
+
(0, import_react_native_reanimated.cancelAnimation)(sharedValue);
|
|
252
|
+
}
|
|
253
|
+
}), [sharedValue]);
|
|
254
|
+
},
|
|
255
|
+
// =========================================================================
|
|
256
|
+
// useAnimatedNumberReaction - React to animated value changes
|
|
257
|
+
// =========================================================================
|
|
258
|
+
useAnimatedNumberReaction({
|
|
259
|
+
value
|
|
260
|
+
}, onValue) {
|
|
261
|
+
const instance = value.getInstance();
|
|
262
|
+
return (0, import_react_native_reanimated.useAnimatedReaction)(() => instance.value, (next, prev) => {
|
|
263
|
+
prev !== next && (0, import_react_native_reanimated.runOnJS)(onValue)(next);
|
|
264
|
+
}, [onValue, instance]);
|
|
265
|
+
},
|
|
266
|
+
// =========================================================================
|
|
267
|
+
// useAnimatedNumberStyle - Create animated styles from values
|
|
268
|
+
// =========================================================================
|
|
269
|
+
useAnimatedNumberStyle(val, getStyle) {
|
|
270
|
+
const instance = val.getInstance(),
|
|
271
|
+
derivedValue = (0, import_react_native_reanimated.useDerivedValue)(() => instance.value, [instance, getStyle]);
|
|
272
|
+
return (0, import_react_native_reanimated.useAnimatedStyle)(() => getStyle(derivedValue.value), [val, getStyle, derivedValue, instance]);
|
|
273
|
+
},
|
|
274
|
+
// =========================================================================
|
|
275
|
+
// useAnimations - Main animation hook for components
|
|
276
|
+
// =========================================================================
|
|
277
|
+
useAnimations(animationProps) {
|
|
278
|
+
const {
|
|
279
|
+
props,
|
|
280
|
+
presence,
|
|
281
|
+
style,
|
|
282
|
+
componentState,
|
|
283
|
+
useStyleEmitter,
|
|
284
|
+
themeName,
|
|
285
|
+
stateRef,
|
|
286
|
+
styleState
|
|
287
|
+
} = animationProps,
|
|
288
|
+
isHydrating = componentState.unmounted === !0,
|
|
289
|
+
isMounting = componentState.unmounted === "should-enter",
|
|
290
|
+
isEntering = !!componentState.unmounted,
|
|
291
|
+
isExiting = presence?.[0] === !1,
|
|
292
|
+
wasEnteringRef = (0, import_react.useRef)(isEntering),
|
|
293
|
+
justFinishedEntering = wasEnteringRef.current && !isEntering;
|
|
294
|
+
import_react.default.useEffect(() => {
|
|
295
|
+
wasEnteringRef.current = isEntering;
|
|
296
|
+
});
|
|
297
|
+
const effectiveTransition = styleState?.effectiveTransition ?? props.transition,
|
|
298
|
+
normalized = (0, import_animation_helpers.normalizeTransition)(effectiveTransition),
|
|
299
|
+
animationState = isExiting ? "exit" : isMounting || justFinishedEntering ? "enter" : "default",
|
|
300
|
+
animationKey = (0, import_animation_helpers.getEffectiveAnimation)(normalized, animationState),
|
|
301
|
+
disableAnimation = isHydrating || !animationKey,
|
|
302
|
+
isDark = themeName?.startsWith("dark") || !1,
|
|
303
|
+
sendExitComplete = presence?.[1],
|
|
304
|
+
exitCycleIdRef = (0, import_react.useRef)(0),
|
|
305
|
+
pendingExitKeysRef = (0, import_react.useRef)(/* @__PURE__ */new Set()),
|
|
306
|
+
exitCompletedRef = (0, import_react.useRef)(!1),
|
|
307
|
+
wasExitingRef = (0, import_react.useRef)(!1),
|
|
308
|
+
justStartedExiting = isExiting && !wasExitingRef.current,
|
|
309
|
+
justStoppedExiting = !isExiting && wasExitingRef.current,
|
|
310
|
+
markExitKeyDone = (0, import_core.useEvent)((key, cycleId, finished) => {
|
|
311
|
+
cycleId === exitCycleIdRef.current && (exitCompletedRef.current || (pendingExitKeysRef.current.delete(key), pendingExitKeysRef.current.size === 0 && (exitCompletedRef.current = !0, sendExitComplete?.())));
|
|
312
|
+
}),
|
|
313
|
+
isExitingRef = (0, import_react_native_reanimated.useSharedValue)(isExiting),
|
|
314
|
+
exitCycleIdShared = (0, import_react_native_reanimated.useSharedValue)(exitCycleIdRef.current);
|
|
315
|
+
justStartedExiting && (exitCycleIdRef.current++, exitCompletedRef.current = !1, pendingExitKeysRef.current.clear()), justStoppedExiting && (exitCycleIdRef.current++, pendingExitKeysRef.current.clear()), (0, import_core.useIsomorphicLayoutEffect)(() => {
|
|
316
|
+
isExitingRef.value = isExiting, exitCycleIdShared.value = exitCycleIdRef.current;
|
|
317
|
+
}, [isExiting, exitCycleIdRef.current]), import_react.default.useEffect(() => {
|
|
318
|
+
wasExitingRef.current = isExiting;
|
|
319
|
+
});
|
|
320
|
+
const animatedTargetsRef = (0, import_react_native_reanimated.useSharedValue)(null),
|
|
321
|
+
staticTargetsRef = (0, import_react_native_reanimated.useSharedValue)(null),
|
|
322
|
+
transformTargetsRef = (0, import_react_native_reanimated.useSharedValue)(null),
|
|
323
|
+
{
|
|
324
|
+
animatedStyles,
|
|
325
|
+
staticStyles
|
|
326
|
+
} = (0, import_react.useMemo)(() => {
|
|
327
|
+
const animated = {},
|
|
328
|
+
staticStyles2 = {},
|
|
329
|
+
animateOnly = props.animateOnly;
|
|
330
|
+
for (const key in style) {
|
|
331
|
+
const rawValue = style[key],
|
|
332
|
+
value = resolveDynamicValue(rawValue, isDark);
|
|
333
|
+
if (value !== void 0) {
|
|
334
|
+
if (disableAnimation) {
|
|
335
|
+
staticStyles2[key] = value;
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
canAnimateProperty(key, value, animateOnly) ? animated[key] = value : staticStyles2[key] = value;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
if (isMounting) for (const key in animated) staticStyles2[key] = animated[key];
|
|
342
|
+
return {
|
|
343
|
+
animatedStyles: animated,
|
|
344
|
+
staticStyles: staticStyles2
|
|
345
|
+
};
|
|
346
|
+
}, [disableAnimation, style, isDark, isMounting, props.animateOnly]),
|
|
347
|
+
{
|
|
348
|
+
baseConfig,
|
|
349
|
+
propertyConfigs
|
|
350
|
+
} = (0, import_react.useMemo)(() => isHydrating ? {
|
|
351
|
+
baseConfig: {
|
|
352
|
+
type: "timing",
|
|
353
|
+
duration: 0
|
|
354
|
+
},
|
|
355
|
+
propertyConfigs: {}
|
|
356
|
+
} : buildTransitionConfig(props.transition, animations, animationState, getStyleKeys(animatedStyles)), [isHydrating, props.transition, animatedStyles, animationState]),
|
|
357
|
+
configRef = (0, import_react_native_reanimated.useSharedValue)({
|
|
358
|
+
baseConfig,
|
|
359
|
+
propertyConfigs,
|
|
360
|
+
disableAnimation,
|
|
361
|
+
isHydrating
|
|
362
|
+
});
|
|
363
|
+
(0, import_core.useIsomorphicLayoutEffect)(() => {
|
|
364
|
+
configRef.set({
|
|
365
|
+
baseConfig,
|
|
366
|
+
propertyConfigs,
|
|
367
|
+
disableAnimation,
|
|
368
|
+
isHydrating
|
|
369
|
+
});
|
|
370
|
+
}, [baseConfig, propertyConfigs, disableAnimation, isHydrating]), useStyleEmitter?.((nextStyle, effectiveTransition2) => {
|
|
371
|
+
const animateOnly = props.animateOnly,
|
|
372
|
+
animated = {},
|
|
373
|
+
statics = {},
|
|
374
|
+
transforms = [],
|
|
375
|
+
transitionToUse = effectiveTransition2 ?? props.transition,
|
|
376
|
+
{
|
|
377
|
+
baseConfig: newBase,
|
|
378
|
+
propertyConfigs: newPropertyConfigs
|
|
379
|
+
} = buildTransitionConfig(transitionToUse, animations, animationState, getStyleKeys(nextStyle));
|
|
380
|
+
configRef.set({
|
|
381
|
+
baseConfig: newBase,
|
|
382
|
+
propertyConfigs: newPropertyConfigs,
|
|
383
|
+
disableAnimation: configRef.get().disableAnimation,
|
|
384
|
+
isHydrating: configRef.get().isHydrating
|
|
385
|
+
});
|
|
386
|
+
for (const key in nextStyle) {
|
|
387
|
+
const rawValue = nextStyle[key],
|
|
388
|
+
value = resolveDynamicValue(rawValue, isDark);
|
|
389
|
+
if (value != null) {
|
|
390
|
+
if (configRef.get().disableAnimation) {
|
|
391
|
+
statics[key] = value;
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
if (key === "transform" && Array.isArray(value)) {
|
|
395
|
+
for (const t of value) if (t && typeof t == "object") {
|
|
396
|
+
const tKey = Object.keys(t)[0],
|
|
397
|
+
tVal = t[tKey];
|
|
398
|
+
(typeof tVal == "number" || typeof tVal == "string") && transforms.push(t);
|
|
399
|
+
}
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
canAnimateProperty(key, value, animateOnly) ? animated[key] = value : statics[key] = value;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
animatedTargetsRef.set(animated), staticTargetsRef.set(statics), transformTargetsRef.set(transforms), process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile" && console.info("[animations-reanimated] useStyleEmitter update", {
|
|
406
|
+
animated,
|
|
407
|
+
statics,
|
|
408
|
+
transforms
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
const exitKeysRegistered = (0, import_react.useRef)(!1);
|
|
412
|
+
if (justStartedExiting && sendExitComplete) {
|
|
413
|
+
const exitKeys = [],
|
|
414
|
+
animateOnly = props.animateOnly;
|
|
415
|
+
for (const key in animatedStyles) key !== "transform" && canAnimateProperty(key, animatedStyles[key], animateOnly) && exitKeys.push(key);
|
|
416
|
+
const transforms = animatedStyles.transform;
|
|
417
|
+
if (transforms && Array.isArray(transforms)) for (const t of transforms) {
|
|
418
|
+
if (!t) continue;
|
|
419
|
+
const tKey = Object.keys(t)[0];
|
|
420
|
+
if (tKey) {
|
|
421
|
+
if (animateOnly && !animateOnly.includes(tKey)) continue;
|
|
422
|
+
exitKeys.push(`transform:${tKey}`);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
pendingExitKeysRef.current = new Set(exitKeys), exitKeysRegistered.current = exitKeys.length > 0;
|
|
426
|
+
}
|
|
427
|
+
import_react.default.useEffect(() => {
|
|
428
|
+
!justStartedExiting || !sendExitComplete || !exitKeysRegistered.current && pendingExitKeysRef.current.size === 0 && (exitCompletedRef.current || (exitCompletedRef.current = !0, sendExitComplete()));
|
|
429
|
+
}, [justStartedExiting, sendExitComplete]);
|
|
430
|
+
const animatedStyle = (0, import_react_native_reanimated.useAnimatedStyle)(() => {
|
|
431
|
+
"worklet";
|
|
432
|
+
|
|
433
|
+
if (disableAnimation || isHydrating) return {};
|
|
434
|
+
const result = {},
|
|
435
|
+
config = configRef.get(),
|
|
436
|
+
emitterAnimated = animatedTargetsRef.value,
|
|
437
|
+
emitterStatic = staticTargetsRef.value,
|
|
438
|
+
emitterTransforms = transformTargetsRef.value,
|
|
439
|
+
hasEmitterUpdates = emitterAnimated !== null,
|
|
440
|
+
animatedValues = hasEmitterUpdates ? emitterAnimated : animatedStyles,
|
|
441
|
+
staticValues = hasEmitterUpdates ? emitterStatic : {},
|
|
442
|
+
currentlyExiting = isExitingRef.value,
|
|
443
|
+
currentCycleId = exitCycleIdShared.value;
|
|
444
|
+
for (const key in staticValues) result[key] = staticValues[key];
|
|
445
|
+
for (const key in animatedValues) {
|
|
446
|
+
if (key === "transform") continue;
|
|
447
|
+
const targetValue = animatedValues[key],
|
|
448
|
+
propConfig = config.propertyConfigs[key] ?? config.baseConfig;
|
|
449
|
+
let callback;
|
|
450
|
+
if (currentlyExiting) {
|
|
451
|
+
const capturedKey = key,
|
|
452
|
+
capturedCycleId = currentCycleId;
|
|
453
|
+
callback = finished => {
|
|
454
|
+
"worklet";
|
|
455
|
+
|
|
456
|
+
(0, import_react_native_reanimated.runOnJS)(markExitKeyDone)(capturedKey, capturedCycleId, finished ?? !1);
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
result[key] = applyAnimation(targetValue, propConfig, callback);
|
|
460
|
+
}
|
|
461
|
+
const transforms = hasEmitterUpdates ? emitterTransforms : animatedStyles.transform;
|
|
462
|
+
if (transforms && Array.isArray(transforms)) {
|
|
463
|
+
const validTransforms = [];
|
|
464
|
+
for (const t of transforms) {
|
|
465
|
+
if (!t) continue;
|
|
466
|
+
const keys = Object.keys(t);
|
|
467
|
+
if (keys.length === 0) continue;
|
|
468
|
+
const value = t[keys[0]];
|
|
469
|
+
if (typeof value == "number" || typeof value == "string") {
|
|
470
|
+
const transformKey = Object.keys(t)[0],
|
|
471
|
+
targetValue = t[transformKey],
|
|
472
|
+
propConfig = config.propertyConfigs[transformKey] ?? config.baseConfig;
|
|
473
|
+
let callback;
|
|
474
|
+
if (currentlyExiting) {
|
|
475
|
+
const capturedKey = `transform:${transformKey}`,
|
|
476
|
+
capturedCycleId = currentCycleId;
|
|
477
|
+
callback = finished => {
|
|
478
|
+
"worklet";
|
|
479
|
+
|
|
480
|
+
(0, import_react_native_reanimated.runOnJS)(markExitKeyDone)(capturedKey, capturedCycleId, finished ?? !1);
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
validTransforms.push({
|
|
484
|
+
[transformKey]: applyAnimation(targetValue, propConfig, callback)
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
validTransforms.length > 0 && (result.transform = validTransforms);
|
|
489
|
+
}
|
|
490
|
+
return result;
|
|
491
|
+
}, [animatedStyles, baseConfig, propertyConfigs, disableAnimation, isHydrating,
|
|
492
|
+
// Pass SharedValues so the mapper watches them on web (see useAnimatedStyle.ts line 470-472)
|
|
493
|
+
animatedTargetsRef, staticTargetsRef, transformTargetsRef, isExitingRef, exitCycleIdShared, markExitKeyDone]);
|
|
494
|
+
return process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile" && console.info("[animations-reanimated] useAnimations", {
|
|
495
|
+
animationKey,
|
|
496
|
+
componentState,
|
|
497
|
+
isExiting,
|
|
498
|
+
animatedStyles,
|
|
499
|
+
staticStyles,
|
|
500
|
+
baseConfig,
|
|
501
|
+
propertyConfigs
|
|
502
|
+
}), {
|
|
503
|
+
style: [staticStyles, animatedStyle]
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
}
|