@tamagui/animations-reanimated 1.0.0-beta.179 → 1.0.0-beta.207
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.js +56 -58
- package/dist/cjs/createAnimations.js.map +2 -2
- package/dist/esm/createAnimations.js +56 -47
- package/dist/esm/createAnimations.js.map +2 -2
- package/dist/jsx/createAnimations.js +56 -47
- package/package.json +5 -5
- package/types/createAnimations.d.ts.map +1 -1
|
@@ -2,22 +2,8 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
-
var __spreadValues = (a, b) => {
|
|
11
|
-
for (var prop in b || (b = {}))
|
|
12
|
-
if (__hasOwnProp.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
if (__getOwnPropSymbols)
|
|
15
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
-
if (__propIsEnum.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
}
|
|
19
|
-
return a;
|
|
20
|
-
};
|
|
21
7
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
22
8
|
var __export = (target, all) => {
|
|
23
9
|
for (var name in all)
|
|
@@ -51,12 +37,13 @@ function createAnimations(animations) {
|
|
|
51
37
|
animations,
|
|
52
38
|
View: AnimatedView,
|
|
53
39
|
Text: AnimatedText,
|
|
54
|
-
useAnimations: (props,
|
|
55
|
-
const {
|
|
40
|
+
useAnimations: (props, helpers) => {
|
|
41
|
+
const { styleKey, mergedStyles, state, pseudos, onDidAnimate, delay } = helpers;
|
|
56
42
|
const [isPresent, safeToUnmount] = (0, import_animate_presence.usePresence)();
|
|
57
43
|
const presence = (0, import_react.useContext)(import_animate_presence.AnimatePresenceContext);
|
|
58
44
|
const isMounted = (0, import_react_native_reanimated.useSharedValue)(false);
|
|
59
|
-
const
|
|
45
|
+
const isHovering = (0, import_react_native_reanimated.useSharedValue)(false);
|
|
46
|
+
const hasExitStyle = !!pseudos.exitStyle;
|
|
60
47
|
const custom = (0, import_react.useCallback)(() => {
|
|
61
48
|
"worklet";
|
|
62
49
|
return presence == null ? void 0 : presence.custom;
|
|
@@ -70,6 +57,9 @@ function createAnimations(animations) {
|
|
|
70
57
|
(0, import_react.useEffect)(() => {
|
|
71
58
|
isMounted.value = true;
|
|
72
59
|
}, [isMounted]);
|
|
60
|
+
(0, import_react.useEffect)(() => {
|
|
61
|
+
isHovering.value = true;
|
|
62
|
+
}, [state.hover]);
|
|
73
63
|
(0, import_react.useEffect)(/* @__PURE__ */ __name(function allowUnMountIfMissingExit() {
|
|
74
64
|
if (!isPresent && !hasExitStyle) {
|
|
75
65
|
reanimatedSafeToUnmount();
|
|
@@ -77,20 +67,23 @@ function createAnimations(animations) {
|
|
|
77
67
|
}, "allowUnMountIfMissingExit"), [hasExitStyle, isPresent, reanimatedSafeToUnmount]);
|
|
78
68
|
const animatedStyle = (0, import_react_native_reanimated.useAnimatedStyle)(() => {
|
|
79
69
|
var _a, _b;
|
|
70
|
+
isHovering.value;
|
|
71
|
+
const style = mergedStyles({
|
|
72
|
+
isExiting: !isPresent
|
|
73
|
+
});
|
|
80
74
|
const final = {
|
|
81
75
|
transform: []
|
|
82
76
|
};
|
|
83
|
-
const isExiting = !isPresent && !!exitStyle;
|
|
77
|
+
const isExiting = !isPresent && !!pseudos.exitStyle;
|
|
84
78
|
const transition = animations[props.animation];
|
|
85
|
-
const mergedStyles = __spreadValues(__spreadValues({}, style), isExiting && exitStyle);
|
|
86
79
|
const exitingStyleProps = {};
|
|
87
|
-
if (exitStyle) {
|
|
88
|
-
for (const key of Object.keys(exitStyle)) {
|
|
80
|
+
if (pseudos.exitStyle) {
|
|
81
|
+
for (const key of Object.keys(pseudos.exitStyle)) {
|
|
89
82
|
exitingStyleProps[key] = true;
|
|
90
83
|
}
|
|
91
84
|
}
|
|
92
|
-
for (const key in
|
|
93
|
-
const value =
|
|
85
|
+
for (const key in style) {
|
|
86
|
+
const value = style[key];
|
|
94
87
|
const { animation, config, shouldRepeat, repeatCount, repeatReverse } = animationConfig(key, transition);
|
|
95
88
|
const callback = /* @__PURE__ */ __name((completed, recentValue) => {
|
|
96
89
|
if (onDidAnimate) {
|
|
@@ -110,56 +103,61 @@ function createAnimations(animations) {
|
|
|
110
103
|
if (key === "transform") {
|
|
111
104
|
if (!Array.isArray(value)) {
|
|
112
105
|
console.error(`Invalid transform value. Needs to be an array.`);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
for (const transformObject of value) {
|
|
109
|
+
const key2 = Object.keys(transformObject)[0];
|
|
110
|
+
const transformValue = transformObject[key2];
|
|
111
|
+
const transform = {};
|
|
112
|
+
if (((_a = transition == null ? void 0 : transition[key2]) == null ? void 0 : _a.delay) != null) {
|
|
113
|
+
delayMs = ((_b = transition == null ? void 0 : transition[key2]) == null ? void 0 : _b.delay) ?? null;
|
|
114
|
+
}
|
|
115
|
+
let finalValue2 = animation(transformValue, config, callback);
|
|
116
|
+
if (shouldRepeat) {
|
|
117
|
+
finalValue2 = (0, import_react_native_reanimated.withRepeat)(finalValue2, repeatCount, repeatReverse);
|
|
118
|
+
}
|
|
119
|
+
if (delayMs != null) {
|
|
120
|
+
transform[key2] = (0, import_react_native_reanimated.withDelay)(delayMs, finalValue2);
|
|
121
|
+
} else {
|
|
122
|
+
transform[key2] = finalValue2;
|
|
123
|
+
}
|
|
124
|
+
if (Object.keys(transform).length) {
|
|
125
|
+
final["transform"].push(transform);
|
|
133
126
|
}
|
|
134
127
|
}
|
|
135
|
-
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (typeof value === "object") {
|
|
136
131
|
final[key] = {};
|
|
137
132
|
for (const innerStyleKey of Object.keys(value || {})) {
|
|
138
|
-
let
|
|
133
|
+
let finalValue2 = animation(value, config, callback);
|
|
139
134
|
if (shouldRepeat) {
|
|
140
|
-
|
|
135
|
+
finalValue2 = (0, import_react_native_reanimated.withRepeat)(finalValue2, repeatCount, repeatReverse);
|
|
141
136
|
}
|
|
142
137
|
if (delayMs != null) {
|
|
143
|
-
final[key][innerStyleKey] = (0, import_react_native_reanimated.withDelay)(delayMs,
|
|
138
|
+
final[key][innerStyleKey] = (0, import_react_native_reanimated.withDelay)(delayMs, finalValue2);
|
|
144
139
|
} else {
|
|
145
|
-
final[key][innerStyleKey] =
|
|
140
|
+
final[key][innerStyleKey] = finalValue2;
|
|
146
141
|
}
|
|
147
142
|
}
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
let finalValue = animation(value, config, callback);
|
|
146
|
+
if (shouldRepeat) {
|
|
147
|
+
finalValue = (0, import_react_native_reanimated.withRepeat)(finalValue, repeatCount, repeatReverse);
|
|
148
|
+
}
|
|
149
|
+
if (delayMs != null && typeof delayMs === "number") {
|
|
150
|
+
final[key] = (0, import_react_native_reanimated.withDelay)(delayMs, finalValue);
|
|
148
151
|
} else {
|
|
149
|
-
|
|
150
|
-
if (shouldRepeat) {
|
|
151
|
-
finalValue = (0, import_react_native_reanimated.withRepeat)(finalValue, repeatCount, repeatReverse);
|
|
152
|
-
}
|
|
153
|
-
if (delayMs != null && typeof delayMs === "number") {
|
|
154
|
-
final[key] = (0, import_react_native_reanimated.withDelay)(delayMs, finalValue);
|
|
155
|
-
} else {
|
|
156
|
-
final[key] = finalValue;
|
|
157
|
-
}
|
|
152
|
+
final[key] = finalValue;
|
|
158
153
|
}
|
|
159
154
|
}
|
|
155
|
+
if (process.env.NODE_ENV === "development" && props["debug"]) {
|
|
156
|
+
console.log("animation style", JSON.stringify(final, null, 2));
|
|
157
|
+
}
|
|
160
158
|
return final;
|
|
161
159
|
}, [
|
|
162
|
-
|
|
160
|
+
styleKey,
|
|
163
161
|
custom,
|
|
164
162
|
delay,
|
|
165
163
|
hasExitStyle,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/createAnimations.tsx"],
|
|
4
|
-
"sourcesContent": ["import { AnimatePresenceContext, usePresence } from '@tamagui/animate-presence'\nimport { AnimationDriver, UseAnimationProps, UseAnimationState } from '@tamagui/core'\nimport { createContext, useCallback, useContext, useEffect } from 'react'\nimport {\n PerpectiveTransform,\n RotateTransform,\n RotateXTransform,\n RotateYTransform,\n RotateZTransform,\n ScaleTransform,\n ScaleXTransform,\n ScaleYTransform,\n SkewXTransform,\n SkewYTransform,\n TranslateXTransform,\n TranslateYTransform,\n} from 'react-native'\nimport Animated, {\n WithDecayConfig,\n WithSpringConfig,\n WithTimingConfig,\n runOnJS,\n useAnimatedStyle,\n useSharedValue,\n withDecay,\n withDelay,\n withRepeat,\n withSpring,\n withTiming,\n} from 'react-native-reanimated'\n\nconst AnimatedView = Animated.View\nconst AnimatedText = Animated.Text\n\nAnimatedView['displayName'] = 'AnimatedView'\nAnimatedText['displayName'] = 'AnimatedText'\n\nexport function createAnimations<A extends Object>(animations: A): AnimationDriver<A> {\n return {\n avoidClasses: true,\n animations,\n View: AnimatedView,\n Text: AnimatedText,\n useAnimations: (props: UseAnimationProps, state: UseAnimationState) => {\n const { style, exitStyle, onDidAnimate, delay } = state\n const [isPresent, safeToUnmount] = usePresence()\n const presence = useContext(AnimatePresenceContext)\n const isMounted = useSharedValue(false)\n const hasExitStyle = !!exitStyle\n const custom = useCallback(() => {\n 'worklet'\n return presence?.custom\n }, [presence])\n\n const reanimatedOnDidAnimated = useCallback<NonNullable<typeof onDidAnimate>>(\n (...args) => {\n onDidAnimate?.(...args)\n },\n [onDidAnimate]\n )\n const reanimatedSafeToUnmount = useCallback(() => {\n safeToUnmount?.()\n }, [safeToUnmount])\n\n useEffect(() => {\n isMounted.value = true\n }, [isMounted])\n\n useEffect(\n function allowUnMountIfMissingExit() {\n if (!isPresent && !hasExitStyle) {\n reanimatedSafeToUnmount()\n }\n },\n [hasExitStyle, isPresent, reanimatedSafeToUnmount]\n )\n\n const animatedStyle = useAnimatedStyle(() => {\n const final = {\n transform: [] as any[],\n }\n\n const isExiting = !isPresent && !!exitStyle\n const transition = animations[props.animation]\n\n const mergedStyles = {\n ...style,\n // ...isExiting && exitStyle(custom()),\n ...(isExiting && exitStyle),\n }\n\n // console.log('wut', style, hoverStyle, pressStyle, isExiting)\n\n const exitingStyleProps: Record<string, boolean> = {}\n if (exitStyle) {\n for (const key of Object.keys(exitStyle)) {\n exitingStyleProps[key] = true\n }\n }\n\n for (const key in mergedStyles) {\n const value = mergedStyles[key]\n const { animation, config, shouldRepeat, repeatCount, repeatReverse } = animationConfig(\n key,\n transition\n )\n\n const callback: (completed: boolean, value?: any) => void = (completed, recentValue) => {\n if (onDidAnimate) {\n runOnJS(reanimatedOnDidAnimated)(key as any, completed, recentValue, {\n attemptedValue: value,\n })\n }\n if (isExiting) {\n exitingStyleProps[key] = false\n const areStylesExiting = Object.values(exitingStyleProps).some(Boolean)\n // if this is true, then we've finished our exit animations\n if (!areStylesExiting) {\n runOnJS(reanimatedSafeToUnmount)()\n }\n }\n }\n\n let { delayMs = null } = animationDelay(key, transition, delay)\n\n if (key === 'transform') {\n if (!Array.isArray(value)) {\n console.error(`Invalid transform value. Needs to be an array.`)\n } else {\n for (const transformObject of value) {\n const key = Object.keys(transformObject)[0]\n const transformValue = transformObject[key]\n const transform = {} as any\n if (transition?.[key]?.delay != null) {\n delayMs = transition?.[key]?.delay ?? null\n }\n let finalValue = animation(transformValue, config, callback)\n if (shouldRepeat) {\n finalValue = withRepeat(finalValue, repeatCount, repeatReverse)\n }\n if (delayMs != null) {\n transform[key] = withDelay(delayMs, finalValue)\n } else {\n transform[key] = finalValue\n }\n if (Object.keys(transform).length) {\n final['transform'].push(transform)\n }\n }\n }\n } else if (typeof value === 'object') {\n // shadows\n final[key] = {}\n for (const innerStyleKey of Object.keys(value || {})) {\n let finalValue = animation(value, config, callback)\n if (shouldRepeat) {\n finalValue = withRepeat(finalValue, repeatCount, repeatReverse)\n }\n if (delayMs != null) {\n final[key][innerStyleKey] = withDelay(delayMs, finalValue)\n } else {\n final[key][innerStyleKey] = finalValue\n }\n }\n } else {\n let finalValue = animation(value, config, callback)\n if (shouldRepeat) {\n finalValue = withRepeat(finalValue, repeatCount, repeatReverse)\n }\n if (delayMs != null && typeof delayMs === 'number') {\n final[key] = withDelay(delayMs, finalValue)\n } else {\n final[key] = finalValue\n }\n }\n\n // end for (key in mergedStyles)\n }\n\n return final\n }, [\n style,\n custom,\n delay,\n // disableInitialAnimation,\n // exitProp,\n // exitTransitionProp,\n // fromProp,\n hasExitStyle,\n isMounted,\n isPresent,\n onDidAnimate,\n reanimatedOnDidAnimated,\n reanimatedSafeToUnmount,\n // state,\n // stylePriority,\n // transitionProp,\n ])\n\n return {\n style: animatedStyle,\n }\n },\n }\n}\n\nfunction animationDelay<Animate>(\n key: string,\n transition: MotiTransition<Animate> | undefined,\n defaultDelay?: number\n) {\n 'worklet'\n let delayMs: TransitionConfig['delay'] = defaultDelay\n\n if (transition[key as keyof Animate]?.delay != null) {\n delayMs = transition[key as keyof Animate]?.delay\n } else if (transition?.delay != null) {\n delayMs = transition.delay\n }\n\n return {\n delayMs,\n }\n}\n\ntype MotiTransition<A> = any\ntype Transforms = PerpectiveTransform &\n RotateTransform &\n RotateXTransform &\n RotateYTransform &\n RotateZTransform &\n ScaleTransform &\n ScaleXTransform &\n ScaleYTransform &\n TranslateXTransform &\n TranslateYTransform &\n SkewXTransform &\n SkewYTransform\ntype TransitionConfigWithoutRepeats = (\n | ({ type?: 'spring' } & WithSpringConfig)\n | ({ type: 'timing' } & WithTimingConfig)\n | ({ type: 'decay' } & WithDecayConfig)\n) & {\n delay?: number\n}\n\ntype TransitionConfig = TransitionConfigWithoutRepeats & {\n /**\n * Number of times this animation should repeat. To make it infinite, use the `loop` boolean.\n *\n * Default: `0`\n *\n * It's worth noting that this value isn't *exactly* a `repeat`. Instead, it uses Reanimated's `withRepeat` function under the hood, which repeats back to the **previous value**. If you want a repeated animation, I recommend setting it to `true` from the start, and make sure you have a `from` value.\n *\n * As a result, this value cannot be reliably changed on the fly. If you would like animations to repeat based on the `from` value, `repeat` must be a number when the component initializes. You can set it to `0` to stop it, but you won't be able to start it again. You might be better off using the sequence array API if you need to update its repetitiveness on the fly.\n */\n repeat?: number\n /**\n * Setting this to `true` is the same as `repeat: Infinity`\n *\n * Default: `false`\n *\n * Note: this value cannot be set on the fly. If you would like animations to repeat based on the `from` value, it must be `true` when the component initializes. You can set it to `false` to stop it, but you won't be able to start it again. You might be better off using the sequence array API if you need to update its repetitiveness on the fly.\n */\n loop?: boolean\n /**\n * Whether or not the animation repetition should alternate in direction.\n *\n * By default, this is `true`.\n *\n * If `false`, any animations with `loop` or `repeat` will not go back and forth. Instead, they will go from 0 -> 1, and again from 0 -> 1.\n *\n * If `true`, then animations will go 0 -> 1 -> 0.\n *\n * Setting this to `true` is like setting `animationDirection: alternate` in CSS.\n */\n repeatReverse?: boolean\n}\n\nconst isColor = (styleKey: string) => {\n 'worklet'\n return [\n 'backgroundColor',\n 'borderBottomColor',\n 'borderColor',\n 'borderEndColor',\n 'borderLeftColor',\n 'borderRightColor',\n 'borderStartColor',\n 'borderTopColor',\n 'color',\n ].includes(styleKey)\n}\n\nfunction animationConfig<Animate>(\n styleProp: string,\n transition: MotiTransition<Animate> | undefined\n) {\n 'worklet'\n const key = styleProp\n let repeatCount = 0\n let repeatReverse = true\n let animationType: Required<TransitionConfig>['type'] = 'spring'\n\n if (isColor(key) || key === 'opacity') {\n animationType = 'timing'\n }\n\n // say that we're looking at `width`\n // first, check if we have transition.width.type\n if (transition[key as keyof Animate]?.type) {\n animationType = (transition as any)[key]?.type\n } else if (transition?.type) {\n // otherwise, fallback to transition.type\n animationType = transition.type\n }\n\n const loop = transition[key as keyof Animate]?.loop ?? transition?.loop\n\n if (loop != null) {\n repeatCount = loop ? -1 : 0\n }\n\n if (transition[key as keyof Animate]?.repeat != null) {\n repeatCount = transition[key as keyof Animate]?.repeat\n } else if (transition?.repeat != null) {\n repeatCount = transition.repeat\n }\n\n if (transition[key as keyof Animate]?.repeatReverse != null) {\n repeatReverse = transition[key as keyof Animate]?.repeatReverse\n } else if (transition?.repeatReverse != null) {\n repeatReverse = transition.repeatReverse\n }\n\n let config = {}\n // so sad, but fix it later :(\n let animation = (...props: any): any => props\n\n if (animationType === 'timing') {\n const duration =\n (transition[key as keyof Animate] as WithTimingConfig)?.duration ??\n (transition as WithTimingConfig)?.duration\n\n const easing =\n (transition[key as keyof Animate] as WithTimingConfig)?.easing ??\n (transition as WithTimingConfig)?.easing\n\n if (easing) {\n config['easing'] = easing\n }\n if (duration != null) {\n config['duration'] = duration\n }\n animation = withTiming\n } else if (animationType === 'spring') {\n animation = withSpring\n config = {} as WithSpringConfig\n configKeys.forEach((configKey) => {\n 'worklet'\n const styleSpecificConfig = transition?.[key]?.[configKey]\n const transitionConfigForKey = transition?.[configKey]\n if (styleSpecificConfig != null) {\n config[configKey] = styleSpecificConfig\n } else if (transitionConfigForKey != null) {\n config[configKey] = transitionConfigForKey\n }\n })\n } else if (animationType === 'decay') {\n animation = withDecay\n config = {\n velocity: 2,\n deceleration: 2,\n }\n const configKeys: (keyof WithDecayConfig)[] = [\n 'clamp',\n 'velocity',\n 'deceleration',\n 'velocityFactor',\n ]\n configKeys.forEach((configKey) => {\n 'worklet'\n // is this necessary ^ don't think so...?\n const styleSpecificConfig = transition?.[key]?.[configKey]\n const transitionConfigForKey = transition?.[configKey]\n\n if (styleSpecificConfig != null) {\n config[configKey] = styleSpecificConfig\n } else if (transitionConfigForKey != null) {\n config[configKey] = transitionConfigForKey\n }\n })\n }\n\n return {\n animation,\n config,\n repeatReverse,\n repeatCount,\n shouldRepeat: !!repeatCount,\n }\n}\n\nconst configKeys: (keyof WithSpringConfig)[] = [\n 'damping',\n 'mass',\n 'overshootClamping',\n 'restDisplacementThreshold',\n 'restSpeedThreshold',\n 'stiffness',\n 'velocity',\n]\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { AnimatePresenceContext, usePresence } from '@tamagui/animate-presence'\nimport { AnimationDriver, UseAnimationHelpers, UseAnimationProps } from '@tamagui/core'\nimport { createContext, useCallback, useContext, useEffect } from 'react'\nimport {\n PerpectiveTransform,\n RotateTransform,\n RotateXTransform,\n RotateYTransform,\n RotateZTransform,\n ScaleTransform,\n ScaleXTransform,\n ScaleYTransform,\n SkewXTransform,\n SkewYTransform,\n TranslateXTransform,\n TranslateYTransform,\n} from 'react-native'\nimport Animated, {\n WithDecayConfig,\n WithSpringConfig,\n WithTimingConfig,\n runOnJS,\n useAnimatedStyle,\n useSharedValue,\n withDecay,\n withDelay,\n withRepeat,\n withSpring,\n withTiming,\n} from 'react-native-reanimated'\n\nconst AnimatedView = Animated.View\nconst AnimatedText = Animated.Text\n\nAnimatedView['displayName'] = 'AnimatedView'\nAnimatedText['displayName'] = 'AnimatedText'\n\nexport function createAnimations<A extends Object>(animations: A): AnimationDriver<A> {\n return {\n avoidClasses: true,\n animations,\n View: AnimatedView,\n Text: AnimatedText,\n useAnimations: (props: UseAnimationProps, helpers: UseAnimationHelpers) => {\n const { styleKey, mergedStyles, state, pseudos, onDidAnimate, delay } = helpers\n const [isPresent, safeToUnmount] = usePresence()\n const presence = useContext(AnimatePresenceContext)\n const isMounted = useSharedValue(false)\n const isHovering = useSharedValue(false)\n const hasExitStyle = !!pseudos.exitStyle\n const custom = useCallback(() => {\n 'worklet'\n return presence?.custom\n }, [presence])\n\n const reanimatedOnDidAnimated = useCallback<NonNullable<typeof onDidAnimate>>(\n (...args) => {\n onDidAnimate?.(...args)\n },\n [onDidAnimate]\n )\n const reanimatedSafeToUnmount = useCallback(() => {\n safeToUnmount?.()\n }, [safeToUnmount])\n\n useEffect(() => {\n isMounted.value = true\n }, [isMounted])\n\n useEffect(() => {\n isHovering.value = true\n }, [state.hover])\n\n useEffect(\n function allowUnMountIfMissingExit() {\n if (!isPresent && !hasExitStyle) {\n reanimatedSafeToUnmount()\n }\n },\n [hasExitStyle, isPresent, reanimatedSafeToUnmount]\n )\n\n const animatedStyle = useAnimatedStyle(() => {\n // read this testing effect\n isHovering.value\n\n const style = mergedStyles({\n isExiting: !isPresent,\n })\n\n const final = {\n transform: [] as any[],\n }\n\n const isExiting = !isPresent && !!pseudos.exitStyle\n const transition = animations[props.animation]\n\n const exitingStyleProps: Record<string, boolean> = {}\n if (pseudos.exitStyle) {\n for (const key of Object.keys(pseudos.exitStyle)) {\n exitingStyleProps[key] = true\n }\n }\n\n for (const key in style) {\n const value = style[key]\n const { animation, config, shouldRepeat, repeatCount, repeatReverse } = animationConfig(\n key,\n transition\n )\n\n const callback: (completed: boolean, value?: any) => void = (completed, recentValue) => {\n if (onDidAnimate) {\n runOnJS(reanimatedOnDidAnimated)(key as any, completed, recentValue, {\n attemptedValue: value,\n })\n }\n if (isExiting) {\n exitingStyleProps[key] = false\n const areStylesExiting = Object.values(exitingStyleProps).some(Boolean)\n // if this is true, then we've finished our exit animations\n if (!areStylesExiting) {\n runOnJS(reanimatedSafeToUnmount)()\n }\n }\n }\n\n let { delayMs = null } = animationDelay(key, transition, delay)\n\n if (key === 'transform') {\n if (!Array.isArray(value)) {\n console.error(`Invalid transform value. Needs to be an array.`)\n continue\n }\n\n for (const transformObject of value) {\n const key = Object.keys(transformObject)[0]\n const transformValue = transformObject[key]\n const transform = {} as any\n if (transition?.[key]?.delay != null) {\n delayMs = transition?.[key]?.delay ?? null\n }\n let finalValue = animation(transformValue, config, callback)\n if (shouldRepeat) {\n finalValue = withRepeat(finalValue, repeatCount, repeatReverse)\n }\n if (delayMs != null) {\n transform[key] = withDelay(delayMs, finalValue)\n } else {\n transform[key] = finalValue\n }\n if (Object.keys(transform).length) {\n final['transform'].push(transform)\n }\n }\n continue\n }\n\n if (typeof value === 'object') {\n // shadows\n final[key] = {}\n for (const innerStyleKey of Object.keys(value || {})) {\n let finalValue = animation(value, config, callback)\n if (shouldRepeat) {\n finalValue = withRepeat(finalValue, repeatCount, repeatReverse)\n }\n if (delayMs != null) {\n final[key][innerStyleKey] = withDelay(delayMs, finalValue)\n } else {\n final[key][innerStyleKey] = finalValue\n }\n }\n continue\n }\n\n let finalValue = animation(value, config, callback)\n if (shouldRepeat) {\n finalValue = withRepeat(finalValue, repeatCount, repeatReverse)\n }\n if (delayMs != null && typeof delayMs === 'number') {\n final[key] = withDelay(delayMs, finalValue)\n } else {\n final[key] = finalValue\n }\n\n // end for (key in mergedStyles)\n }\n\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n console.log('animation style', JSON.stringify(final, null, 2))\n }\n\n return final\n }, [\n styleKey,\n custom,\n delay,\n // disableInitialAnimation,\n // exitProp,\n // exitTransitionProp,\n // fromProp,\n hasExitStyle,\n isMounted,\n isPresent,\n onDidAnimate,\n reanimatedOnDidAnimated,\n reanimatedSafeToUnmount,\n // state,\n // stylePriority,\n // transitionProp,\n ])\n\n return {\n style: animatedStyle,\n }\n },\n }\n}\n\nfunction animationDelay<Animate>(\n key: string,\n transition: MotiTransition<Animate> | undefined,\n defaultDelay?: number\n) {\n 'worklet'\n let delayMs: TransitionConfig['delay'] = defaultDelay\n\n if (transition[key as keyof Animate]?.delay != null) {\n delayMs = transition[key as keyof Animate]?.delay\n } else if (transition?.delay != null) {\n delayMs = transition.delay\n }\n\n return {\n delayMs,\n }\n}\n\ntype MotiTransition<A> = any\ntype Transforms = PerpectiveTransform &\n RotateTransform &\n RotateXTransform &\n RotateYTransform &\n RotateZTransform &\n ScaleTransform &\n ScaleXTransform &\n ScaleYTransform &\n TranslateXTransform &\n TranslateYTransform &\n SkewXTransform &\n SkewYTransform\ntype TransitionConfigWithoutRepeats = (\n | ({ type?: 'spring' } & WithSpringConfig)\n | ({ type: 'timing' } & WithTimingConfig)\n | ({ type: 'decay' } & WithDecayConfig)\n) & {\n delay?: number\n}\n\ntype TransitionConfig = TransitionConfigWithoutRepeats & {\n /**\n * Number of times this animation should repeat. To make it infinite, use the `loop` boolean.\n *\n * Default: `0`\n *\n * It's worth noting that this value isn't *exactly* a `repeat`. Instead, it uses Reanimated's `withRepeat` function under the hood, which repeats back to the **previous value**. If you want a repeated animation, I recommend setting it to `true` from the start, and make sure you have a `from` value.\n *\n * As a result, this value cannot be reliably changed on the fly. If you would like animations to repeat based on the `from` value, `repeat` must be a number when the component initializes. You can set it to `0` to stop it, but you won't be able to start it again. You might be better off using the sequence array API if you need to update its repetitiveness on the fly.\n */\n repeat?: number\n /**\n * Setting this to `true` is the same as `repeat: Infinity`\n *\n * Default: `false`\n *\n * Note: this value cannot be set on the fly. If you would like animations to repeat based on the `from` value, it must be `true` when the component initializes. You can set it to `false` to stop it, but you won't be able to start it again. You might be better off using the sequence array API if you need to update its repetitiveness on the fly.\n */\n loop?: boolean\n /**\n * Whether or not the animation repetition should alternate in direction.\n *\n * By default, this is `true`.\n *\n * If `false`, any animations with `loop` or `repeat` will not go back and forth. Instead, they will go from 0 -> 1, and again from 0 -> 1.\n *\n * If `true`, then animations will go 0 -> 1 -> 0.\n *\n * Setting this to `true` is like setting `animationDirection: alternate` in CSS.\n */\n repeatReverse?: boolean\n}\n\nconst isColor = (styleKey: string) => {\n 'worklet'\n return [\n 'backgroundColor',\n 'borderBottomColor',\n 'borderColor',\n 'borderEndColor',\n 'borderLeftColor',\n 'borderRightColor',\n 'borderStartColor',\n 'borderTopColor',\n 'color',\n ].includes(styleKey)\n}\n\nfunction animationConfig<Animate>(\n styleProp: string,\n transition: MotiTransition<Animate> | undefined\n) {\n 'worklet'\n const key = styleProp\n let repeatCount = 0\n let repeatReverse = true\n let animationType: Required<TransitionConfig>['type'] = 'spring'\n\n if (isColor(key) || key === 'opacity') {\n animationType = 'timing'\n }\n\n // say that we're looking at `width`\n // first, check if we have transition.width.type\n if (transition[key as keyof Animate]?.type) {\n animationType = (transition as any)[key]?.type\n } else if (transition?.type) {\n // otherwise, fallback to transition.type\n animationType = transition.type\n }\n\n const loop = transition[key as keyof Animate]?.loop ?? transition?.loop\n\n if (loop != null) {\n repeatCount = loop ? -1 : 0\n }\n\n if (transition[key as keyof Animate]?.repeat != null) {\n repeatCount = transition[key as keyof Animate]?.repeat\n } else if (transition?.repeat != null) {\n repeatCount = transition.repeat\n }\n\n if (transition[key as keyof Animate]?.repeatReverse != null) {\n repeatReverse = transition[key as keyof Animate]?.repeatReverse\n } else if (transition?.repeatReverse != null) {\n repeatReverse = transition.repeatReverse\n }\n\n let config = {}\n // so sad, but fix it later :(\n let animation = (...props: any): any => props\n\n if (animationType === 'timing') {\n const duration =\n (transition[key as keyof Animate] as WithTimingConfig)?.duration ??\n (transition as WithTimingConfig)?.duration\n\n const easing =\n (transition[key as keyof Animate] as WithTimingConfig)?.easing ??\n (transition as WithTimingConfig)?.easing\n\n if (easing) {\n config['easing'] = easing\n }\n if (duration != null) {\n config['duration'] = duration\n }\n animation = withTiming\n } else if (animationType === 'spring') {\n animation = withSpring\n config = {} as WithSpringConfig\n configKeys.forEach((configKey) => {\n 'worklet'\n const styleSpecificConfig = transition?.[key]?.[configKey]\n const transitionConfigForKey = transition?.[configKey]\n if (styleSpecificConfig != null) {\n config[configKey] = styleSpecificConfig\n } else if (transitionConfigForKey != null) {\n config[configKey] = transitionConfigForKey\n }\n })\n } else if (animationType === 'decay') {\n animation = withDecay\n config = {\n velocity: 2,\n deceleration: 2,\n }\n const configKeys: (keyof WithDecayConfig)[] = [\n 'clamp',\n 'velocity',\n 'deceleration',\n 'velocityFactor',\n ]\n configKeys.forEach((configKey) => {\n 'worklet'\n // is this necessary ^ don't think so...?\n const styleSpecificConfig = transition?.[key]?.[configKey]\n const transitionConfigForKey = transition?.[configKey]\n\n if (styleSpecificConfig != null) {\n config[configKey] = styleSpecificConfig\n } else if (transitionConfigForKey != null) {\n config[configKey] = transitionConfigForKey\n }\n })\n }\n\n return {\n animation,\n config,\n repeatReverse,\n repeatCount,\n shouldRepeat: !!repeatCount,\n }\n}\n\nconst configKeys: (keyof WithSpringConfig)[] = [\n 'damping',\n 'mass',\n 'overshootClamping',\n 'restDisplacementThreshold',\n 'restSpeedThreshold',\n 'stiffness',\n 'velocity',\n]\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAoD;AAEpD,mBAAkE;AAelE,qCAYO;AAEP,MAAM,eAAe,uCAAS;AAC9B,MAAM,eAAe,uCAAS;AAE9B,aAAa,iBAAiB;AAC9B,aAAa,iBAAiB;AAEvB,0BAA4C,YAAmC;AACpF,SAAO;AAAA,IACL,cAAc;AAAA,IACd;AAAA,IACA,MAAM;AAAA,IACN,MAAM;AAAA,IACN,eAAe,CAAC,OAA0B,YAAiC;AACzE,YAAM,EAAE,UAAU,cAAc,OAAO,SAAS,cAAc,UAAU;AACxE,YAAM,CAAC,WAAW,iBAAiB,yCAAY;AAC/C,YAAM,WAAW,6BAAW,8CAAsB;AAClD,YAAM,YAAY,mDAAe,KAAK;AACtC,YAAM,aAAa,mDAAe,KAAK;AACvC,YAAM,eAAe,CAAC,CAAC,QAAQ;AAC/B,YAAM,SAAS,8BAAY,MAAM;AAC/B;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AAA,MACtB;AAAA,IACF,CAAC;AAAA,EACH,WAAW,kBAAkB,SAAS;AACpC,gBAAY;AACZ,aAAS;AAAA,MACP,UAAU;AAAA,MACV,cAAc;AAAA,IAChB;AACA,UAAM,cAAwC;AAAA,MAC5C;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AACA,gBAAW,QAAQ,CAAC,cAAc;AAzYtC;AA0YM;AAEA,YAAM,sBAAsB,gDAAa,SAAb,oBAAoB;AAChD,YAAM,yBAAyB,yCAAa;AAE5C,UAAI,uBAAuB,MAAM;AAC/B,eAAO,aAAa;AAAA,MACtB,WAAW,0BAA0B,MAAM;AACzC,eAAO,aAAa;AAAA,MACtB;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,CAAC,CAAC;AAAA,EAClB;AACF;AA3GS;AA6GT,MAAM,aAAyC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -22,12 +22,13 @@ function createAnimations(animations) {
|
|
|
22
22
|
animations,
|
|
23
23
|
View: AnimatedView,
|
|
24
24
|
Text: AnimatedText,
|
|
25
|
-
useAnimations: (props,
|
|
26
|
-
const {
|
|
25
|
+
useAnimations: (props, helpers) => {
|
|
26
|
+
const { styleKey, mergedStyles, state, pseudos, onDidAnimate, delay } = helpers;
|
|
27
27
|
const [isPresent, safeToUnmount] = usePresence();
|
|
28
28
|
const presence = useContext(AnimatePresenceContext);
|
|
29
29
|
const isMounted = useSharedValue(false);
|
|
30
|
-
const
|
|
30
|
+
const isHovering = useSharedValue(false);
|
|
31
|
+
const hasExitStyle = !!pseudos.exitStyle;
|
|
31
32
|
const custom = useCallback(() => {
|
|
32
33
|
"worklet";
|
|
33
34
|
return presence == null ? void 0 : presence.custom;
|
|
@@ -41,6 +42,9 @@ function createAnimations(animations) {
|
|
|
41
42
|
useEffect(() => {
|
|
42
43
|
isMounted.value = true;
|
|
43
44
|
}, [isMounted]);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
isHovering.value = true;
|
|
47
|
+
}, [state.hover]);
|
|
44
48
|
useEffect(/* @__PURE__ */ __name(function allowUnMountIfMissingExit() {
|
|
45
49
|
if (!isPresent && !hasExitStyle) {
|
|
46
50
|
reanimatedSafeToUnmount();
|
|
@@ -48,23 +52,23 @@ function createAnimations(animations) {
|
|
|
48
52
|
}, "allowUnMountIfMissingExit"), [hasExitStyle, isPresent, reanimatedSafeToUnmount]);
|
|
49
53
|
const animatedStyle = useAnimatedStyle(() => {
|
|
50
54
|
var _a, _b, _c;
|
|
55
|
+
isHovering.value;
|
|
56
|
+
const style = mergedStyles({
|
|
57
|
+
isExiting: !isPresent
|
|
58
|
+
});
|
|
51
59
|
const final = {
|
|
52
60
|
transform: []
|
|
53
61
|
};
|
|
54
|
-
const isExiting = !isPresent && !!exitStyle;
|
|
62
|
+
const isExiting = !isPresent && !!pseudos.exitStyle;
|
|
55
63
|
const transition = animations[props.animation];
|
|
56
|
-
const mergedStyles = {
|
|
57
|
-
...style,
|
|
58
|
-
...isExiting && exitStyle
|
|
59
|
-
};
|
|
60
64
|
const exitingStyleProps = {};
|
|
61
|
-
if (exitStyle) {
|
|
62
|
-
for (const key of Object.keys(exitStyle)) {
|
|
65
|
+
if (pseudos.exitStyle) {
|
|
66
|
+
for (const key of Object.keys(pseudos.exitStyle)) {
|
|
63
67
|
exitingStyleProps[key] = true;
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
|
-
for (const key in
|
|
67
|
-
const value =
|
|
70
|
+
for (const key in style) {
|
|
71
|
+
const value = style[key];
|
|
68
72
|
const { animation, config, shouldRepeat, repeatCount, repeatReverse } = animationConfig(key, transition);
|
|
69
73
|
const callback = /* @__PURE__ */ __name((completed, recentValue) => {
|
|
70
74
|
if (onDidAnimate) {
|
|
@@ -84,56 +88,61 @@ function createAnimations(animations) {
|
|
|
84
88
|
if (key === "transform") {
|
|
85
89
|
if (!Array.isArray(value)) {
|
|
86
90
|
console.error(`Invalid transform value. Needs to be an array.`);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
for (const transformObject of value) {
|
|
94
|
+
const key2 = Object.keys(transformObject)[0];
|
|
95
|
+
const transformValue = transformObject[key2];
|
|
96
|
+
const transform = {};
|
|
97
|
+
if (((_a = transition == null ? void 0 : transition[key2]) == null ? void 0 : _a.delay) != null) {
|
|
98
|
+
delayMs = (_c = (_b = transition == null ? void 0 : transition[key2]) == null ? void 0 : _b.delay) != null ? _c : null;
|
|
99
|
+
}
|
|
100
|
+
let finalValue2 = animation(transformValue, config, callback);
|
|
101
|
+
if (shouldRepeat) {
|
|
102
|
+
finalValue2 = withRepeat(finalValue2, repeatCount, repeatReverse);
|
|
103
|
+
}
|
|
104
|
+
if (delayMs != null) {
|
|
105
|
+
transform[key2] = withDelay(delayMs, finalValue2);
|
|
106
|
+
} else {
|
|
107
|
+
transform[key2] = finalValue2;
|
|
108
|
+
}
|
|
109
|
+
if (Object.keys(transform).length) {
|
|
110
|
+
final["transform"].push(transform);
|
|
107
111
|
}
|
|
108
112
|
}
|
|
109
|
-
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (typeof value === "object") {
|
|
110
116
|
final[key] = {};
|
|
111
117
|
for (const innerStyleKey of Object.keys(value || {})) {
|
|
112
|
-
let
|
|
118
|
+
let finalValue2 = animation(value, config, callback);
|
|
113
119
|
if (shouldRepeat) {
|
|
114
|
-
|
|
120
|
+
finalValue2 = withRepeat(finalValue2, repeatCount, repeatReverse);
|
|
115
121
|
}
|
|
116
122
|
if (delayMs != null) {
|
|
117
|
-
final[key][innerStyleKey] = withDelay(delayMs,
|
|
123
|
+
final[key][innerStyleKey] = withDelay(delayMs, finalValue2);
|
|
118
124
|
} else {
|
|
119
|
-
final[key][innerStyleKey] =
|
|
125
|
+
final[key][innerStyleKey] = finalValue2;
|
|
120
126
|
}
|
|
121
127
|
}
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
let finalValue = animation(value, config, callback);
|
|
131
|
+
if (shouldRepeat) {
|
|
132
|
+
finalValue = withRepeat(finalValue, repeatCount, repeatReverse);
|
|
133
|
+
}
|
|
134
|
+
if (delayMs != null && typeof delayMs === "number") {
|
|
135
|
+
final[key] = withDelay(delayMs, finalValue);
|
|
122
136
|
} else {
|
|
123
|
-
|
|
124
|
-
if (shouldRepeat) {
|
|
125
|
-
finalValue = withRepeat(finalValue, repeatCount, repeatReverse);
|
|
126
|
-
}
|
|
127
|
-
if (delayMs != null && typeof delayMs === "number") {
|
|
128
|
-
final[key] = withDelay(delayMs, finalValue);
|
|
129
|
-
} else {
|
|
130
|
-
final[key] = finalValue;
|
|
131
|
-
}
|
|
137
|
+
final[key] = finalValue;
|
|
132
138
|
}
|
|
133
139
|
}
|
|
140
|
+
if (process.env.NODE_ENV === "development" && props["debug"]) {
|
|
141
|
+
console.log("animation style", JSON.stringify(final, null, 2));
|
|
142
|
+
}
|
|
134
143
|
return final;
|
|
135
144
|
}, [
|
|
136
|
-
|
|
145
|
+
styleKey,
|
|
137
146
|
custom,
|
|
138
147
|
delay,
|
|
139
148
|
hasExitStyle,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/createAnimations.tsx"],
|
|
4
|
-
"sourcesContent": ["import { AnimatePresenceContext, usePresence } from '@tamagui/animate-presence'\nimport { AnimationDriver, UseAnimationProps, UseAnimationState } from '@tamagui/core'\nimport { createContext, useCallback, useContext, useEffect } from 'react'\nimport {\n PerpectiveTransform,\n RotateTransform,\n RotateXTransform,\n RotateYTransform,\n RotateZTransform,\n ScaleTransform,\n ScaleXTransform,\n ScaleYTransform,\n SkewXTransform,\n SkewYTransform,\n TranslateXTransform,\n TranslateYTransform,\n} from 'react-native'\nimport Animated, {\n WithDecayConfig,\n WithSpringConfig,\n WithTimingConfig,\n runOnJS,\n useAnimatedStyle,\n useSharedValue,\n withDecay,\n withDelay,\n withRepeat,\n withSpring,\n withTiming,\n} from 'react-native-reanimated'\n\nconst AnimatedView = Animated.View\nconst AnimatedText = Animated.Text\n\nAnimatedView['displayName'] = 'AnimatedView'\nAnimatedText['displayName'] = 'AnimatedText'\n\nexport function createAnimations<A extends Object>(animations: A): AnimationDriver<A> {\n return {\n avoidClasses: true,\n animations,\n View: AnimatedView,\n Text: AnimatedText,\n useAnimations: (props: UseAnimationProps, state: UseAnimationState) => {\n const { style, exitStyle, onDidAnimate, delay } = state\n const [isPresent, safeToUnmount] = usePresence()\n const presence = useContext(AnimatePresenceContext)\n const isMounted = useSharedValue(false)\n const hasExitStyle = !!exitStyle\n const custom = useCallback(() => {\n 'worklet'\n return presence?.custom\n }, [presence])\n\n const reanimatedOnDidAnimated = useCallback<NonNullable<typeof onDidAnimate>>(\n (...args) => {\n onDidAnimate?.(...args)\n },\n [onDidAnimate]\n )\n const reanimatedSafeToUnmount = useCallback(() => {\n safeToUnmount?.()\n }, [safeToUnmount])\n\n useEffect(() => {\n isMounted.value = true\n }, [isMounted])\n\n useEffect(\n function allowUnMountIfMissingExit() {\n if (!isPresent && !hasExitStyle) {\n reanimatedSafeToUnmount()\n }\n },\n [hasExitStyle, isPresent, reanimatedSafeToUnmount]\n )\n\n const animatedStyle = useAnimatedStyle(() => {\n const final = {\n transform: [] as any[],\n }\n\n const isExiting = !isPresent && !!exitStyle\n const transition = animations[props.animation]\n\n const mergedStyles = {\n ...style,\n // ...isExiting && exitStyle(custom()),\n ...(isExiting && exitStyle),\n }\n\n // console.log('wut', style, hoverStyle, pressStyle, isExiting)\n\n const exitingStyleProps: Record<string, boolean> = {}\n if (exitStyle) {\n for (const key of Object.keys(exitStyle)) {\n exitingStyleProps[key] = true\n }\n }\n\n for (const key in mergedStyles) {\n const value = mergedStyles[key]\n const { animation, config, shouldRepeat, repeatCount, repeatReverse } = animationConfig(\n key,\n transition\n )\n\n const callback: (completed: boolean, value?: any) => void = (completed, recentValue) => {\n if (onDidAnimate) {\n runOnJS(reanimatedOnDidAnimated)(key as any, completed, recentValue, {\n attemptedValue: value,\n })\n }\n if (isExiting) {\n exitingStyleProps[key] = false\n const areStylesExiting = Object.values(exitingStyleProps).some(Boolean)\n // if this is true, then we've finished our exit animations\n if (!areStylesExiting) {\n runOnJS(reanimatedSafeToUnmount)()\n }\n }\n }\n\n let { delayMs = null } = animationDelay(key, transition, delay)\n\n if (key === 'transform') {\n if (!Array.isArray(value)) {\n console.error(`Invalid transform value. Needs to be an array.`)\n } else {\n for (const transformObject of value) {\n const key = Object.keys(transformObject)[0]\n const transformValue = transformObject[key]\n const transform = {} as any\n if (transition?.[key]?.delay != null) {\n delayMs = transition?.[key]?.delay ?? null\n }\n let finalValue = animation(transformValue, config, callback)\n if (shouldRepeat) {\n finalValue = withRepeat(finalValue, repeatCount, repeatReverse)\n }\n if (delayMs != null) {\n transform[key] = withDelay(delayMs, finalValue)\n } else {\n transform[key] = finalValue\n }\n if (Object.keys(transform).length) {\n final['transform'].push(transform)\n }\n }\n }\n } else if (typeof value === 'object') {\n // shadows\n final[key] = {}\n for (const innerStyleKey of Object.keys(value || {})) {\n let finalValue = animation(value, config, callback)\n if (shouldRepeat) {\n finalValue = withRepeat(finalValue, repeatCount, repeatReverse)\n }\n if (delayMs != null) {\n final[key][innerStyleKey] = withDelay(delayMs, finalValue)\n } else {\n final[key][innerStyleKey] = finalValue\n }\n }\n } else {\n let finalValue = animation(value, config, callback)\n if (shouldRepeat) {\n finalValue = withRepeat(finalValue, repeatCount, repeatReverse)\n }\n if (delayMs != null && typeof delayMs === 'number') {\n final[key] = withDelay(delayMs, finalValue)\n } else {\n final[key] = finalValue\n }\n }\n\n // end for (key in mergedStyles)\n }\n\n return final\n }, [\n style,\n custom,\n delay,\n // disableInitialAnimation,\n // exitProp,\n // exitTransitionProp,\n // fromProp,\n hasExitStyle,\n isMounted,\n isPresent,\n onDidAnimate,\n reanimatedOnDidAnimated,\n reanimatedSafeToUnmount,\n // state,\n // stylePriority,\n // transitionProp,\n ])\n\n return {\n style: animatedStyle,\n }\n },\n }\n}\n\nfunction animationDelay<Animate>(\n key: string,\n transition: MotiTransition<Animate> | undefined,\n defaultDelay?: number\n) {\n 'worklet'\n let delayMs: TransitionConfig['delay'] = defaultDelay\n\n if (transition[key as keyof Animate]?.delay != null) {\n delayMs = transition[key as keyof Animate]?.delay\n } else if (transition?.delay != null) {\n delayMs = transition.delay\n }\n\n return {\n delayMs,\n }\n}\n\ntype MotiTransition<A> = any\ntype Transforms = PerpectiveTransform &\n RotateTransform &\n RotateXTransform &\n RotateYTransform &\n RotateZTransform &\n ScaleTransform &\n ScaleXTransform &\n ScaleYTransform &\n TranslateXTransform &\n TranslateYTransform &\n SkewXTransform &\n SkewYTransform\ntype TransitionConfigWithoutRepeats = (\n | ({ type?: 'spring' } & WithSpringConfig)\n | ({ type: 'timing' } & WithTimingConfig)\n | ({ type: 'decay' } & WithDecayConfig)\n) & {\n delay?: number\n}\n\ntype TransitionConfig = TransitionConfigWithoutRepeats & {\n /**\n * Number of times this animation should repeat. To make it infinite, use the `loop` boolean.\n *\n * Default: `0`\n *\n * It's worth noting that this value isn't *exactly* a `repeat`. Instead, it uses Reanimated's `withRepeat` function under the hood, which repeats back to the **previous value**. If you want a repeated animation, I recommend setting it to `true` from the start, and make sure you have a `from` value.\n *\n * As a result, this value cannot be reliably changed on the fly. If you would like animations to repeat based on the `from` value, `repeat` must be a number when the component initializes. You can set it to `0` to stop it, but you won't be able to start it again. You might be better off using the sequence array API if you need to update its repetitiveness on the fly.\n */\n repeat?: number\n /**\n * Setting this to `true` is the same as `repeat: Infinity`\n *\n * Default: `false`\n *\n * Note: this value cannot be set on the fly. If you would like animations to repeat based on the `from` value, it must be `true` when the component initializes. You can set it to `false` to stop it, but you won't be able to start it again. You might be better off using the sequence array API if you need to update its repetitiveness on the fly.\n */\n loop?: boolean\n /**\n * Whether or not the animation repetition should alternate in direction.\n *\n * By default, this is `true`.\n *\n * If `false`, any animations with `loop` or `repeat` will not go back and forth. Instead, they will go from 0 -> 1, and again from 0 -> 1.\n *\n * If `true`, then animations will go 0 -> 1 -> 0.\n *\n * Setting this to `true` is like setting `animationDirection: alternate` in CSS.\n */\n repeatReverse?: boolean\n}\n\nconst isColor = (styleKey: string) => {\n 'worklet'\n return [\n 'backgroundColor',\n 'borderBottomColor',\n 'borderColor',\n 'borderEndColor',\n 'borderLeftColor',\n 'borderRightColor',\n 'borderStartColor',\n 'borderTopColor',\n 'color',\n ].includes(styleKey)\n}\n\nfunction animationConfig<Animate>(\n styleProp: string,\n transition: MotiTransition<Animate> | undefined\n) {\n 'worklet'\n const key = styleProp\n let repeatCount = 0\n let repeatReverse = true\n let animationType: Required<TransitionConfig>['type'] = 'spring'\n\n if (isColor(key) || key === 'opacity') {\n animationType = 'timing'\n }\n\n // say that we're looking at `width`\n // first, check if we have transition.width.type\n if (transition[key as keyof Animate]?.type) {\n animationType = (transition as any)[key]?.type\n } else if (transition?.type) {\n // otherwise, fallback to transition.type\n animationType = transition.type\n }\n\n const loop = transition[key as keyof Animate]?.loop ?? transition?.loop\n\n if (loop != null) {\n repeatCount = loop ? -1 : 0\n }\n\n if (transition[key as keyof Animate]?.repeat != null) {\n repeatCount = transition[key as keyof Animate]?.repeat\n } else if (transition?.repeat != null) {\n repeatCount = transition.repeat\n }\n\n if (transition[key as keyof Animate]?.repeatReverse != null) {\n repeatReverse = transition[key as keyof Animate]?.repeatReverse\n } else if (transition?.repeatReverse != null) {\n repeatReverse = transition.repeatReverse\n }\n\n let config = {}\n // so sad, but fix it later :(\n let animation = (...props: any): any => props\n\n if (animationType === 'timing') {\n const duration =\n (transition[key as keyof Animate] as WithTimingConfig)?.duration ??\n (transition as WithTimingConfig)?.duration\n\n const easing =\n (transition[key as keyof Animate] as WithTimingConfig)?.easing ??\n (transition as WithTimingConfig)?.easing\n\n if (easing) {\n config['easing'] = easing\n }\n if (duration != null) {\n config['duration'] = duration\n }\n animation = withTiming\n } else if (animationType === 'spring') {\n animation = withSpring\n config = {} as WithSpringConfig\n configKeys.forEach((configKey) => {\n 'worklet'\n const styleSpecificConfig = transition?.[key]?.[configKey]\n const transitionConfigForKey = transition?.[configKey]\n if (styleSpecificConfig != null) {\n config[configKey] = styleSpecificConfig\n } else if (transitionConfigForKey != null) {\n config[configKey] = transitionConfigForKey\n }\n })\n } else if (animationType === 'decay') {\n animation = withDecay\n config = {\n velocity: 2,\n deceleration: 2,\n }\n const configKeys: (keyof WithDecayConfig)[] = [\n 'clamp',\n 'velocity',\n 'deceleration',\n 'velocityFactor',\n ]\n configKeys.forEach((configKey) => {\n 'worklet'\n // is this necessary ^ don't think so...?\n const styleSpecificConfig = transition?.[key]?.[configKey]\n const transitionConfigForKey = transition?.[configKey]\n\n if (styleSpecificConfig != null) {\n config[configKey] = styleSpecificConfig\n } else if (transitionConfigForKey != null) {\n config[configKey] = transitionConfigForKey\n }\n })\n }\n\n return {\n animation,\n config,\n repeatReverse,\n repeatCount,\n shouldRepeat: !!repeatCount,\n }\n}\n\nconst configKeys: (keyof WithSpringConfig)[] = [\n 'damping',\n 'mass',\n 'overshootClamping',\n 'restDisplacementThreshold',\n 'restSpeedThreshold',\n 'stiffness',\n 'velocity',\n]\n"],
|
|
5
|
-
"mappings": ";;AAAA;AAEA;AAeA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,MAAM,eAAe,SAAS;AAC9B,MAAM,eAAe,SAAS;AAE9B,aAAa,iBAAiB;AAC9B,aAAa,iBAAiB;AAEvB,0BAA4C,YAAmC;AACpF,SAAO;AAAA,IACL,cAAc;AAAA,IACd;AAAA,IACA,MAAM;AAAA,IACN,MAAM;AAAA,IACN,eAAe,CAAC,OAA0B,
|
|
4
|
+
"sourcesContent": ["import { AnimatePresenceContext, usePresence } from '@tamagui/animate-presence'\nimport { AnimationDriver, UseAnimationHelpers, UseAnimationProps } from '@tamagui/core'\nimport { createContext, useCallback, useContext, useEffect } from 'react'\nimport {\n PerpectiveTransform,\n RotateTransform,\n RotateXTransform,\n RotateYTransform,\n RotateZTransform,\n ScaleTransform,\n ScaleXTransform,\n ScaleYTransform,\n SkewXTransform,\n SkewYTransform,\n TranslateXTransform,\n TranslateYTransform,\n} from 'react-native'\nimport Animated, {\n WithDecayConfig,\n WithSpringConfig,\n WithTimingConfig,\n runOnJS,\n useAnimatedStyle,\n useSharedValue,\n withDecay,\n withDelay,\n withRepeat,\n withSpring,\n withTiming,\n} from 'react-native-reanimated'\n\nconst AnimatedView = Animated.View\nconst AnimatedText = Animated.Text\n\nAnimatedView['displayName'] = 'AnimatedView'\nAnimatedText['displayName'] = 'AnimatedText'\n\nexport function createAnimations<A extends Object>(animations: A): AnimationDriver<A> {\n return {\n avoidClasses: true,\n animations,\n View: AnimatedView,\n Text: AnimatedText,\n useAnimations: (props: UseAnimationProps, helpers: UseAnimationHelpers) => {\n const { styleKey, mergedStyles, state, pseudos, onDidAnimate, delay } = helpers\n const [isPresent, safeToUnmount] = usePresence()\n const presence = useContext(AnimatePresenceContext)\n const isMounted = useSharedValue(false)\n const isHovering = useSharedValue(false)\n const hasExitStyle = !!pseudos.exitStyle\n const custom = useCallback(() => {\n 'worklet'\n return presence?.custom\n }, [presence])\n\n const reanimatedOnDidAnimated = useCallback<NonNullable<typeof onDidAnimate>>(\n (...args) => {\n onDidAnimate?.(...args)\n },\n [onDidAnimate]\n )\n const reanimatedSafeToUnmount = useCallback(() => {\n safeToUnmount?.()\n }, [safeToUnmount])\n\n useEffect(() => {\n isMounted.value = true\n }, [isMounted])\n\n useEffect(() => {\n isHovering.value = true\n }, [state.hover])\n\n useEffect(\n function allowUnMountIfMissingExit() {\n if (!isPresent && !hasExitStyle) {\n reanimatedSafeToUnmount()\n }\n },\n [hasExitStyle, isPresent, reanimatedSafeToUnmount]\n )\n\n const animatedStyle = useAnimatedStyle(() => {\n // read this testing effect\n isHovering.value\n\n const style = mergedStyles({\n isExiting: !isPresent,\n })\n\n const final = {\n transform: [] as any[],\n }\n\n const isExiting = !isPresent && !!pseudos.exitStyle\n const transition = animations[props.animation]\n\n const exitingStyleProps: Record<string, boolean> = {}\n if (pseudos.exitStyle) {\n for (const key of Object.keys(pseudos.exitStyle)) {\n exitingStyleProps[key] = true\n }\n }\n\n for (const key in style) {\n const value = style[key]\n const { animation, config, shouldRepeat, repeatCount, repeatReverse } = animationConfig(\n key,\n transition\n )\n\n const callback: (completed: boolean, value?: any) => void = (completed, recentValue) => {\n if (onDidAnimate) {\n runOnJS(reanimatedOnDidAnimated)(key as any, completed, recentValue, {\n attemptedValue: value,\n })\n }\n if (isExiting) {\n exitingStyleProps[key] = false\n const areStylesExiting = Object.values(exitingStyleProps).some(Boolean)\n // if this is true, then we've finished our exit animations\n if (!areStylesExiting) {\n runOnJS(reanimatedSafeToUnmount)()\n }\n }\n }\n\n let { delayMs = null } = animationDelay(key, transition, delay)\n\n if (key === 'transform') {\n if (!Array.isArray(value)) {\n console.error(`Invalid transform value. Needs to be an array.`)\n continue\n }\n\n for (const transformObject of value) {\n const key = Object.keys(transformObject)[0]\n const transformValue = transformObject[key]\n const transform = {} as any\n if (transition?.[key]?.delay != null) {\n delayMs = transition?.[key]?.delay ?? null\n }\n let finalValue = animation(transformValue, config, callback)\n if (shouldRepeat) {\n finalValue = withRepeat(finalValue, repeatCount, repeatReverse)\n }\n if (delayMs != null) {\n transform[key] = withDelay(delayMs, finalValue)\n } else {\n transform[key] = finalValue\n }\n if (Object.keys(transform).length) {\n final['transform'].push(transform)\n }\n }\n continue\n }\n\n if (typeof value === 'object') {\n // shadows\n final[key] = {}\n for (const innerStyleKey of Object.keys(value || {})) {\n let finalValue = animation(value, config, callback)\n if (shouldRepeat) {\n finalValue = withRepeat(finalValue, repeatCount, repeatReverse)\n }\n if (delayMs != null) {\n final[key][innerStyleKey] = withDelay(delayMs, finalValue)\n } else {\n final[key][innerStyleKey] = finalValue\n }\n }\n continue\n }\n\n let finalValue = animation(value, config, callback)\n if (shouldRepeat) {\n finalValue = withRepeat(finalValue, repeatCount, repeatReverse)\n }\n if (delayMs != null && typeof delayMs === 'number') {\n final[key] = withDelay(delayMs, finalValue)\n } else {\n final[key] = finalValue\n }\n\n // end for (key in mergedStyles)\n }\n\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n console.log('animation style', JSON.stringify(final, null, 2))\n }\n\n return final\n }, [\n styleKey,\n custom,\n delay,\n // disableInitialAnimation,\n // exitProp,\n // exitTransitionProp,\n // fromProp,\n hasExitStyle,\n isMounted,\n isPresent,\n onDidAnimate,\n reanimatedOnDidAnimated,\n reanimatedSafeToUnmount,\n // state,\n // stylePriority,\n // transitionProp,\n ])\n\n return {\n style: animatedStyle,\n }\n },\n }\n}\n\nfunction animationDelay<Animate>(\n key: string,\n transition: MotiTransition<Animate> | undefined,\n defaultDelay?: number\n) {\n 'worklet'\n let delayMs: TransitionConfig['delay'] = defaultDelay\n\n if (transition[key as keyof Animate]?.delay != null) {\n delayMs = transition[key as keyof Animate]?.delay\n } else if (transition?.delay != null) {\n delayMs = transition.delay\n }\n\n return {\n delayMs,\n }\n}\n\ntype MotiTransition<A> = any\ntype Transforms = PerpectiveTransform &\n RotateTransform &\n RotateXTransform &\n RotateYTransform &\n RotateZTransform &\n ScaleTransform &\n ScaleXTransform &\n ScaleYTransform &\n TranslateXTransform &\n TranslateYTransform &\n SkewXTransform &\n SkewYTransform\ntype TransitionConfigWithoutRepeats = (\n | ({ type?: 'spring' } & WithSpringConfig)\n | ({ type: 'timing' } & WithTimingConfig)\n | ({ type: 'decay' } & WithDecayConfig)\n) & {\n delay?: number\n}\n\ntype TransitionConfig = TransitionConfigWithoutRepeats & {\n /**\n * Number of times this animation should repeat. To make it infinite, use the `loop` boolean.\n *\n * Default: `0`\n *\n * It's worth noting that this value isn't *exactly* a `repeat`. Instead, it uses Reanimated's `withRepeat` function under the hood, which repeats back to the **previous value**. If you want a repeated animation, I recommend setting it to `true` from the start, and make sure you have a `from` value.\n *\n * As a result, this value cannot be reliably changed on the fly. If you would like animations to repeat based on the `from` value, `repeat` must be a number when the component initializes. You can set it to `0` to stop it, but you won't be able to start it again. You might be better off using the sequence array API if you need to update its repetitiveness on the fly.\n */\n repeat?: number\n /**\n * Setting this to `true` is the same as `repeat: Infinity`\n *\n * Default: `false`\n *\n * Note: this value cannot be set on the fly. If you would like animations to repeat based on the `from` value, it must be `true` when the component initializes. You can set it to `false` to stop it, but you won't be able to start it again. You might be better off using the sequence array API if you need to update its repetitiveness on the fly.\n */\n loop?: boolean\n /**\n * Whether or not the animation repetition should alternate in direction.\n *\n * By default, this is `true`.\n *\n * If `false`, any animations with `loop` or `repeat` will not go back and forth. Instead, they will go from 0 -> 1, and again from 0 -> 1.\n *\n * If `true`, then animations will go 0 -> 1 -> 0.\n *\n * Setting this to `true` is like setting `animationDirection: alternate` in CSS.\n */\n repeatReverse?: boolean\n}\n\nconst isColor = (styleKey: string) => {\n 'worklet'\n return [\n 'backgroundColor',\n 'borderBottomColor',\n 'borderColor',\n 'borderEndColor',\n 'borderLeftColor',\n 'borderRightColor',\n 'borderStartColor',\n 'borderTopColor',\n 'color',\n ].includes(styleKey)\n}\n\nfunction animationConfig<Animate>(\n styleProp: string,\n transition: MotiTransition<Animate> | undefined\n) {\n 'worklet'\n const key = styleProp\n let repeatCount = 0\n let repeatReverse = true\n let animationType: Required<TransitionConfig>['type'] = 'spring'\n\n if (isColor(key) || key === 'opacity') {\n animationType = 'timing'\n }\n\n // say that we're looking at `width`\n // first, check if we have transition.width.type\n if (transition[key as keyof Animate]?.type) {\n animationType = (transition as any)[key]?.type\n } else if (transition?.type) {\n // otherwise, fallback to transition.type\n animationType = transition.type\n }\n\n const loop = transition[key as keyof Animate]?.loop ?? transition?.loop\n\n if (loop != null) {\n repeatCount = loop ? -1 : 0\n }\n\n if (transition[key as keyof Animate]?.repeat != null) {\n repeatCount = transition[key as keyof Animate]?.repeat\n } else if (transition?.repeat != null) {\n repeatCount = transition.repeat\n }\n\n if (transition[key as keyof Animate]?.repeatReverse != null) {\n repeatReverse = transition[key as keyof Animate]?.repeatReverse\n } else if (transition?.repeatReverse != null) {\n repeatReverse = transition.repeatReverse\n }\n\n let config = {}\n // so sad, but fix it later :(\n let animation = (...props: any): any => props\n\n if (animationType === 'timing') {\n const duration =\n (transition[key as keyof Animate] as WithTimingConfig)?.duration ??\n (transition as WithTimingConfig)?.duration\n\n const easing =\n (transition[key as keyof Animate] as WithTimingConfig)?.easing ??\n (transition as WithTimingConfig)?.easing\n\n if (easing) {\n config['easing'] = easing\n }\n if (duration != null) {\n config['duration'] = duration\n }\n animation = withTiming\n } else if (animationType === 'spring') {\n animation = withSpring\n config = {} as WithSpringConfig\n configKeys.forEach((configKey) => {\n 'worklet'\n const styleSpecificConfig = transition?.[key]?.[configKey]\n const transitionConfigForKey = transition?.[configKey]\n if (styleSpecificConfig != null) {\n config[configKey] = styleSpecificConfig\n } else if (transitionConfigForKey != null) {\n config[configKey] = transitionConfigForKey\n }\n })\n } else if (animationType === 'decay') {\n animation = withDecay\n config = {\n velocity: 2,\n deceleration: 2,\n }\n const configKeys: (keyof WithDecayConfig)[] = [\n 'clamp',\n 'velocity',\n 'deceleration',\n 'velocityFactor',\n ]\n configKeys.forEach((configKey) => {\n 'worklet'\n // is this necessary ^ don't think so...?\n const styleSpecificConfig = transition?.[key]?.[configKey]\n const transitionConfigForKey = transition?.[configKey]\n\n if (styleSpecificConfig != null) {\n config[configKey] = styleSpecificConfig\n } else if (transitionConfigForKey != null) {\n config[configKey] = transitionConfigForKey\n }\n })\n }\n\n return {\n animation,\n config,\n repeatReverse,\n repeatCount,\n shouldRepeat: !!repeatCount,\n }\n}\n\nconst configKeys: (keyof WithSpringConfig)[] = [\n 'damping',\n 'mass',\n 'overshootClamping',\n 'restDisplacementThreshold',\n 'restSpeedThreshold',\n 'stiffness',\n 'velocity',\n]\n"],
|
|
5
|
+
"mappings": ";;AAAA;AAEA;AAeA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,MAAM,eAAe,SAAS;AAC9B,MAAM,eAAe,SAAS;AAE9B,aAAa,iBAAiB;AAC9B,aAAa,iBAAiB;AAEvB,0BAA4C,YAAmC;AACpF,SAAO;AAAA,IACL,cAAc;AAAA,IACd;AAAA,IACA,MAAM;AAAA,IACN,MAAM;AAAA,IACN,eAAe,CAAC,OAA0B,YAAiC;AACzE,YAAM,EAAE,UAAU,cAAc,OAAO,SAAS,cAAc,UAAU;AACxE,YAAM,CAAC,WAAW,iBAAiB,YAAY;AAC/C,YAAM,WAAW,WAAW,sBAAsB;AAClD,YAAM,YAAY,eAAe,KAAK;AACtC,YAAM,aAAa,eAAe,KAAK;AACvC,YAAM,eAAe,CAAC,CAAC,QAAQ;AAC/B,YAAM,SAAS,YAAY,MAAM;AAC/B;AACA,eAAO,qCAAU;AAAA,MACnB,GAAG,CAAC,QAAQ,CAAC;AAEb,YAAM,0BAA0B,YAC9B,IAAI,SAAS;AACX,qDAAe,GAAG;AAAA,MACpB,GACA,CAAC,YAAY,CACf;AACA,YAAM,0BAA0B,YAAY,MAAM;AAChD;AAAA,MACF,GAAG,CAAC,aAAa,CAAC;AAElB,gBAAU,MAAM;AACd,kBAAU,QAAQ;AAAA,MACpB,GAAG,CAAC,SAAS,CAAC;AAEd,gBAAU,MAAM;AACd,mBAAW,QAAQ;AAAA,MACrB,GAAG,CAAC,MAAM,KAAK,CAAC;AAEhB,gBACE,4DAAqC;AACnC,YAAI,CAAC,aAAa,CAAC,cAAc;AAC/B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AAA,MACtB;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,CAAC,CAAC;AAAA,EAClB;AACF;AA3GS;AA6GT,MAAM,aAAyC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -22,12 +22,13 @@ function createAnimations(animations) {
|
|
|
22
22
|
animations,
|
|
23
23
|
View: AnimatedView,
|
|
24
24
|
Text: AnimatedText,
|
|
25
|
-
useAnimations: (props,
|
|
26
|
-
const {
|
|
25
|
+
useAnimations: (props, helpers) => {
|
|
26
|
+
const { styleKey, mergedStyles, state, pseudos, onDidAnimate, delay } = helpers;
|
|
27
27
|
const [isPresent, safeToUnmount] = usePresence();
|
|
28
28
|
const presence = useContext(AnimatePresenceContext);
|
|
29
29
|
const isMounted = useSharedValue(false);
|
|
30
|
-
const
|
|
30
|
+
const isHovering = useSharedValue(false);
|
|
31
|
+
const hasExitStyle = !!pseudos.exitStyle;
|
|
31
32
|
const custom = useCallback(() => {
|
|
32
33
|
"worklet";
|
|
33
34
|
return presence == null ? void 0 : presence.custom;
|
|
@@ -41,6 +42,9 @@ function createAnimations(animations) {
|
|
|
41
42
|
useEffect(() => {
|
|
42
43
|
isMounted.value = true;
|
|
43
44
|
}, [isMounted]);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
isHovering.value = true;
|
|
47
|
+
}, [state.hover]);
|
|
44
48
|
useEffect(/* @__PURE__ */ __name(function allowUnMountIfMissingExit() {
|
|
45
49
|
if (!isPresent && !hasExitStyle) {
|
|
46
50
|
reanimatedSafeToUnmount();
|
|
@@ -48,23 +52,23 @@ function createAnimations(animations) {
|
|
|
48
52
|
}, "allowUnMountIfMissingExit"), [hasExitStyle, isPresent, reanimatedSafeToUnmount]);
|
|
49
53
|
const animatedStyle = useAnimatedStyle(() => {
|
|
50
54
|
var _a, _b, _c;
|
|
55
|
+
isHovering.value;
|
|
56
|
+
const style = mergedStyles({
|
|
57
|
+
isExiting: !isPresent
|
|
58
|
+
});
|
|
51
59
|
const final = {
|
|
52
60
|
transform: []
|
|
53
61
|
};
|
|
54
|
-
const isExiting = !isPresent && !!exitStyle;
|
|
62
|
+
const isExiting = !isPresent && !!pseudos.exitStyle;
|
|
55
63
|
const transition = animations[props.animation];
|
|
56
|
-
const mergedStyles = {
|
|
57
|
-
...style,
|
|
58
|
-
...isExiting && exitStyle
|
|
59
|
-
};
|
|
60
64
|
const exitingStyleProps = {};
|
|
61
|
-
if (exitStyle) {
|
|
62
|
-
for (const key of Object.keys(exitStyle)) {
|
|
65
|
+
if (pseudos.exitStyle) {
|
|
66
|
+
for (const key of Object.keys(pseudos.exitStyle)) {
|
|
63
67
|
exitingStyleProps[key] = true;
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
|
-
for (const key in
|
|
67
|
-
const value =
|
|
70
|
+
for (const key in style) {
|
|
71
|
+
const value = style[key];
|
|
68
72
|
const { animation, config, shouldRepeat, repeatCount, repeatReverse } = animationConfig(key, transition);
|
|
69
73
|
const callback = /* @__PURE__ */ __name((completed, recentValue) => {
|
|
70
74
|
if (onDidAnimate) {
|
|
@@ -84,56 +88,61 @@ function createAnimations(animations) {
|
|
|
84
88
|
if (key === "transform") {
|
|
85
89
|
if (!Array.isArray(value)) {
|
|
86
90
|
console.error(`Invalid transform value. Needs to be an array.`);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
for (const transformObject of value) {
|
|
94
|
+
const key2 = Object.keys(transformObject)[0];
|
|
95
|
+
const transformValue = transformObject[key2];
|
|
96
|
+
const transform = {};
|
|
97
|
+
if (((_a = transition == null ? void 0 : transition[key2]) == null ? void 0 : _a.delay) != null) {
|
|
98
|
+
delayMs = (_c = (_b = transition == null ? void 0 : transition[key2]) == null ? void 0 : _b.delay) != null ? _c : null;
|
|
99
|
+
}
|
|
100
|
+
let finalValue2 = animation(transformValue, config, callback);
|
|
101
|
+
if (shouldRepeat) {
|
|
102
|
+
finalValue2 = withRepeat(finalValue2, repeatCount, repeatReverse);
|
|
103
|
+
}
|
|
104
|
+
if (delayMs != null) {
|
|
105
|
+
transform[key2] = withDelay(delayMs, finalValue2);
|
|
106
|
+
} else {
|
|
107
|
+
transform[key2] = finalValue2;
|
|
108
|
+
}
|
|
109
|
+
if (Object.keys(transform).length) {
|
|
110
|
+
final["transform"].push(transform);
|
|
107
111
|
}
|
|
108
112
|
}
|
|
109
|
-
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (typeof value === "object") {
|
|
110
116
|
final[key] = {};
|
|
111
117
|
for (const innerStyleKey of Object.keys(value || {})) {
|
|
112
|
-
let
|
|
118
|
+
let finalValue2 = animation(value, config, callback);
|
|
113
119
|
if (shouldRepeat) {
|
|
114
|
-
|
|
120
|
+
finalValue2 = withRepeat(finalValue2, repeatCount, repeatReverse);
|
|
115
121
|
}
|
|
116
122
|
if (delayMs != null) {
|
|
117
|
-
final[key][innerStyleKey] = withDelay(delayMs,
|
|
123
|
+
final[key][innerStyleKey] = withDelay(delayMs, finalValue2);
|
|
118
124
|
} else {
|
|
119
|
-
final[key][innerStyleKey] =
|
|
125
|
+
final[key][innerStyleKey] = finalValue2;
|
|
120
126
|
}
|
|
121
127
|
}
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
let finalValue = animation(value, config, callback);
|
|
131
|
+
if (shouldRepeat) {
|
|
132
|
+
finalValue = withRepeat(finalValue, repeatCount, repeatReverse);
|
|
133
|
+
}
|
|
134
|
+
if (delayMs != null && typeof delayMs === "number") {
|
|
135
|
+
final[key] = withDelay(delayMs, finalValue);
|
|
122
136
|
} else {
|
|
123
|
-
|
|
124
|
-
if (shouldRepeat) {
|
|
125
|
-
finalValue = withRepeat(finalValue, repeatCount, repeatReverse);
|
|
126
|
-
}
|
|
127
|
-
if (delayMs != null && typeof delayMs === "number") {
|
|
128
|
-
final[key] = withDelay(delayMs, finalValue);
|
|
129
|
-
} else {
|
|
130
|
-
final[key] = finalValue;
|
|
131
|
-
}
|
|
137
|
+
final[key] = finalValue;
|
|
132
138
|
}
|
|
133
139
|
}
|
|
140
|
+
if (process.env.NODE_ENV === "development" && props["debug"]) {
|
|
141
|
+
console.log("animation style", JSON.stringify(final, null, 2));
|
|
142
|
+
}
|
|
134
143
|
return final;
|
|
135
144
|
}, [
|
|
136
|
-
|
|
145
|
+
styleKey,
|
|
137
146
|
custom,
|
|
138
147
|
delay,
|
|
139
148
|
hasExitStyle,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/animations-reanimated",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.207+3fd10ea6",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"typings": "types",
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
"dist"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@tamagui/animate-presence": "^1.0.0-beta.
|
|
16
|
-
"@tamagui/core": "^1.0.0-beta.
|
|
15
|
+
"@tamagui/animate-presence": "^1.0.0-beta.207+3fd10ea6",
|
|
16
|
+
"@tamagui/core": "^1.0.0-beta.207+3fd10ea6",
|
|
17
17
|
"react-native-reanimated": "^2.4.1"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@tamagui/build": "^1.0.0-beta.
|
|
20
|
+
"@tamagui/build": "^1.0.0-beta.207+3fd10ea6"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build": "tamagui-build",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "3fd10ea6d026fac0339fbc1a501ee304f4985b05"
|
|
32
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAnimations.d.ts","sourceRoot":"","sources":["../src/createAnimations.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"createAnimations.d.ts","sourceRoot":"","sources":["../src/createAnimations.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAA0C,MAAM,eAAe,CAAA;AAoCvF,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,UAAU,EAAE,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAoLpF"}
|