@tamagui/animations-motion 1.129.5 → 1.129.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/createAnimations.cjs +32 -24
- package/dist/cjs/createAnimations.js +50 -22
- package/dist/cjs/createAnimations.js.map +2 -2
- package/dist/cjs/createAnimations.native.js +46 -21
- package/dist/cjs/createAnimations.native.js.map +2 -2
- package/dist/esm/createAnimations.js +51 -22
- package/dist/esm/createAnimations.js.map +2 -2
- package/dist/esm/createAnimations.mjs +33 -25
- package/dist/esm/createAnimations.mjs.map +1 -1
- package/dist/esm/createAnimations.native.js +38 -28
- package/dist/esm/createAnimations.native.js.map +1 -1
- package/package.json +4 -4
- package/src/createAnimations.tsx +84 -25
- package/types/createAnimations.d.ts.map +2 -2
|
@@ -69,36 +69,43 @@ function createAnimations(animationsProp) {
|
|
|
69
69
|
disableAnimation = componentState.unmounted === !0 || !animationKey,
|
|
70
70
|
presenceContext = import_react2.default.useContext(import_use_presence.PresenceContext),
|
|
71
71
|
[scope, animate] = (0, import_react.useAnimate)(),
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (!
|
|
82
|
-
|
|
72
|
+
lastAnimationStyle = (0, import_react2.useRef)(null),
|
|
73
|
+
controls = (0, import_react2.useRef)(null),
|
|
74
|
+
styleKey = JSON.stringify(style),
|
|
75
|
+
{
|
|
76
|
+
dontAnimate,
|
|
77
|
+
doAnimate,
|
|
78
|
+
animationOptions
|
|
79
|
+
} = (0, import_react2.useMemo)(() => getMotionAnimatedProps(props, style, disableAnimation), [presenceContext, animationKey, styleKey]),
|
|
80
|
+
runAnimation = (animationStyle, animationOptions2) => {
|
|
81
|
+
if (!animationStyle || !(stateRef.current.host instanceof HTMLElement)) return;
|
|
82
|
+
if ((0, import_core.fixStyles)(animationStyle), (0, import_core.styleToCSS)(animationStyle), !lastAnimationStyle.current) {
|
|
83
|
+
lastAnimationStyle.current = animationStyle, controls.current = animate(scope.current, animationStyle, {
|
|
83
84
|
duration: 0,
|
|
84
85
|
type: "tween"
|
|
85
|
-
});
|
|
86
|
+
}), controls.current.complete();
|
|
86
87
|
return;
|
|
87
88
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
const diff = {};
|
|
90
|
+
for (const key in animationStyle) animationStyle[key] !== lastAnimationStyle.current[key] && (diff[key] = animationStyle[key]);
|
|
91
|
+
controls.current = animate(scope.current, diff, animationOptions2), lastAnimationStyle.current = animationStyle;
|
|
92
|
+
};
|
|
91
93
|
return useStyleEmitter?.(nextStyle => {
|
|
92
94
|
const {
|
|
93
95
|
doAnimate: doAnimate2,
|
|
94
96
|
animationOptions: animationOptions2
|
|
95
97
|
} = getMotionAnimatedProps(props, nextStyle, disableAnimation);
|
|
96
|
-
|
|
98
|
+
runAnimation(doAnimate2, animationOptions2);
|
|
97
99
|
}), (0, import_react2.useEffect)(() => () => {
|
|
98
|
-
|
|
100
|
+
lastAnimationStyle.current = null;
|
|
99
101
|
}, []), (0, import_react2.useLayoutEffect)(() => {
|
|
100
102
|
doAnimate && runAnimation(doAnimate, animationOptions);
|
|
101
|
-
}, [doAnimate,
|
|
103
|
+
}, [JSON.stringify(doAnimate), lastAnimationStyle]), process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile" && console.info("[animations-motion](", JSON.stringify(doAnimate, null, 2) + ")", {
|
|
104
|
+
doAnimate,
|
|
105
|
+
dontAnimate,
|
|
106
|
+
animationOptions,
|
|
107
|
+
props
|
|
108
|
+
}), {
|
|
102
109
|
style: dontAnimate,
|
|
103
110
|
ref: scope,
|
|
104
111
|
tag: "div"
|
|
@@ -153,12 +160,12 @@ function createAnimations(animationsProp) {
|
|
|
153
160
|
doAnimate: null
|
|
154
161
|
};
|
|
155
162
|
const animationOptions = animationPropToAnimationConfig(props.animation);
|
|
156
|
-
let dontAnimate = {}
|
|
157
|
-
|
|
158
|
-
|
|
163
|
+
let dontAnimate = {},
|
|
164
|
+
doAnimate = null;
|
|
165
|
+
const animateOnly = props.animateOnly;
|
|
159
166
|
for (const key in style) {
|
|
160
167
|
const value = style[key];
|
|
161
|
-
animateOnly && !animateOnly.includes(key) ? dontAnimate[key] = value : doAnimate[key] = value;
|
|
168
|
+
disableAnimationProps.has(key) || animateOnly && !animateOnly.includes(key) ? dontAnimate[key] = value : (doAnimate ||= {}, doAnimate[key] = value);
|
|
162
169
|
}
|
|
163
170
|
return {
|
|
164
171
|
dontAnimate,
|
|
@@ -175,7 +182,8 @@ function createAnimations(animationsProp) {
|
|
|
175
182
|
} : {};
|
|
176
183
|
}
|
|
177
184
|
}
|
|
178
|
-
const
|
|
185
|
+
const disableAnimationProps = /* @__PURE__ */new Set(["alignContent", "alignItems", "backdropFilter", "boxSizing", "contain", "display", "flexBasis", "flexDirection", "flexShrink", "justifyContent", "maxHeight", "maxWidth", "minHeight", "minWidth", "overflow", "pointerEvents", "position", "textWrap"]),
|
|
186
|
+
MotionView = createMotionView("div"),
|
|
179
187
|
MotionText = createMotionView("span");
|
|
180
188
|
function createMotionView(defaultTag) {
|
|
181
189
|
const isText = defaultTag === "span",
|
|
@@ -208,7 +216,7 @@ function createMotionView(defaultTag) {
|
|
|
208
216
|
// noMergeStyle: true,
|
|
209
217
|
resolveValues: "auto"
|
|
210
218
|
});
|
|
211
|
-
return out.viewProps.style && (0, import_core.styleToCSS)(out.viewProps.style), out.viewProps;
|
|
219
|
+
return out.viewProps.style && ((0, import_core.fixStyles)(out.viewProps.style), (0, import_core.styleToCSS)(out.viewProps.style)), out.viewProps;
|
|
212
220
|
}
|
|
213
221
|
const props = getProps({
|
|
214
222
|
...propsRest,
|
|
@@ -46,33 +46,42 @@ function createAnimations(animationsProp) {
|
|
|
46
46
|
usePresence: import_use_presence.usePresence,
|
|
47
47
|
ResetPresence: import_use_presence.ResetPresence,
|
|
48
48
|
useAnimations: (animationProps) => {
|
|
49
|
-
const { props, style, componentState, stateRef, useStyleEmitter } = animationProps, animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation, disableAnimation = componentState.unmounted === !0 || !animationKey, presenceContext = import_react2.default.useContext(import_use_presence.PresenceContext), [scope, animate] = (0, import_react.useAnimate)(),
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
49
|
+
const { props, style, componentState, stateRef, useStyleEmitter } = animationProps, animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation, disableAnimation = componentState.unmounted === !0 || !animationKey, presenceContext = import_react2.default.useContext(import_use_presence.PresenceContext), [scope, animate] = (0, import_react.useAnimate)(), lastAnimationStyle = (0, import_react2.useRef)(null), controls = (0, import_react2.useRef)(null), styleKey = JSON.stringify(style), { dontAnimate, doAnimate, animationOptions } = (0, import_react2.useMemo)(() => getMotionAnimatedProps(
|
|
50
|
+
props,
|
|
51
|
+
style,
|
|
52
|
+
disableAnimation
|
|
53
|
+
), [presenceContext, animationKey, styleKey]), runAnimation = (animationStyle, animationOptions2) => {
|
|
54
|
+
if (!animationStyle || !(stateRef.current.host instanceof HTMLElement))
|
|
55
|
+
return;
|
|
56
|
+
if ((0, import_core.fixStyles)(animationStyle), (0, import_core.styleToCSS)(animationStyle), !lastAnimationStyle.current) {
|
|
57
|
+
lastAnimationStyle.current = animationStyle, controls.current = animate(scope.current, animationStyle, {
|
|
58
|
+
duration: 0,
|
|
59
|
+
type: "tween"
|
|
60
|
+
}), controls.current.complete();
|
|
61
|
+
return;
|
|
62
62
|
}
|
|
63
|
-
|
|
63
|
+
const diff = {};
|
|
64
|
+
for (const key in animationStyle)
|
|
65
|
+
animationStyle[key] !== lastAnimationStyle.current[key] && (diff[key] = animationStyle[key]);
|
|
66
|
+
controls.current = animate(scope.current, diff, animationOptions2), lastAnimationStyle.current = animationStyle;
|
|
67
|
+
};
|
|
64
68
|
return useStyleEmitter?.((nextStyle) => {
|
|
65
69
|
const { doAnimate: doAnimate2, animationOptions: animationOptions2 } = getMotionAnimatedProps(
|
|
66
70
|
props,
|
|
67
71
|
nextStyle,
|
|
68
72
|
disableAnimation
|
|
69
73
|
);
|
|
70
|
-
|
|
74
|
+
runAnimation(doAnimate2, animationOptions2);
|
|
71
75
|
}), (0, import_react2.useEffect)(() => () => {
|
|
72
|
-
|
|
76
|
+
lastAnimationStyle.current = null;
|
|
73
77
|
}, []), (0, import_react2.useLayoutEffect)(() => {
|
|
74
78
|
doAnimate && runAnimation(doAnimate, animationOptions);
|
|
75
|
-
}, [doAnimate,
|
|
79
|
+
}, [JSON.stringify(doAnimate), lastAnimationStyle]), process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile" && console.info("[animations-motion](", JSON.stringify(doAnimate, null, 2) + ")", {
|
|
80
|
+
doAnimate,
|
|
81
|
+
dontAnimate,
|
|
82
|
+
animationOptions,
|
|
83
|
+
props
|
|
84
|
+
}), {
|
|
76
85
|
style: dontAnimate,
|
|
77
86
|
ref: scope,
|
|
78
87
|
tag: "div"
|
|
@@ -128,11 +137,11 @@ function createAnimations(animationsProp) {
|
|
|
128
137
|
doAnimate: null
|
|
129
138
|
};
|
|
130
139
|
const animationOptions = animationPropToAnimationConfig(props.animation);
|
|
131
|
-
let dontAnimate = {};
|
|
132
|
-
const
|
|
140
|
+
let dontAnimate = {}, doAnimate = null;
|
|
141
|
+
const animateOnly = props.animateOnly;
|
|
133
142
|
for (const key in style) {
|
|
134
143
|
const value = style[key];
|
|
135
|
-
animateOnly && !animateOnly.includes(key) ? dontAnimate[key] = value : doAnimate[key] = value;
|
|
144
|
+
disableAnimationProps.has(key) || animateOnly && !animateOnly.includes(key) ? dontAnimate[key] = value : (doAnimate ||= {}, doAnimate[key] = value);
|
|
136
145
|
}
|
|
137
146
|
return {
|
|
138
147
|
dontAnimate,
|
|
@@ -150,7 +159,26 @@ function createAnimations(animationsProp) {
|
|
|
150
159
|
} : {};
|
|
151
160
|
}
|
|
152
161
|
}
|
|
153
|
-
const
|
|
162
|
+
const disableAnimationProps = /* @__PURE__ */ new Set([
|
|
163
|
+
"alignContent",
|
|
164
|
+
"alignItems",
|
|
165
|
+
"backdropFilter",
|
|
166
|
+
"boxSizing",
|
|
167
|
+
"contain",
|
|
168
|
+
"display",
|
|
169
|
+
"flexBasis",
|
|
170
|
+
"flexDirection",
|
|
171
|
+
"flexShrink",
|
|
172
|
+
"justifyContent",
|
|
173
|
+
"maxHeight",
|
|
174
|
+
"maxWidth",
|
|
175
|
+
"minHeight",
|
|
176
|
+
"minWidth",
|
|
177
|
+
"overflow",
|
|
178
|
+
"pointerEvents",
|
|
179
|
+
"position",
|
|
180
|
+
"textWrap"
|
|
181
|
+
]), MotionView = createMotionView("div"), MotionText = createMotionView("span");
|
|
154
182
|
function createMotionView(defaultTag) {
|
|
155
183
|
const isText = defaultTag === "span", Component = (0, import_react2.forwardRef)((propsIn, ref) => {
|
|
156
184
|
const { forwardedRef, animation, tag = defaultTag, style, ...propsRest } = propsIn, [scope, animate] = (0, import_react.useAnimate)(), hostRef = (0, import_react2.useRef)(null), composedRefs = (0, import_core.useComposedRefs)(forwardedRef, ref, hostRef, scope), stateRef = (0, import_react2.useRef)(null);
|
|
@@ -179,7 +207,7 @@ function createMotionView(defaultTag) {
|
|
|
179
207
|
resolveValues: "auto"
|
|
180
208
|
}
|
|
181
209
|
);
|
|
182
|
-
return out.viewProps.style && (0, import_core.styleToCSS)(out.viewProps.style), out.viewProps;
|
|
210
|
+
return out.viewProps.style && ((0, import_core.fixStyles)(out.viewProps.style), (0, import_core.styleToCSS)(out.viewProps.style)), out.viewProps;
|
|
183
211
|
}
|
|
184
212
|
const props = getProps({ ...propsRest, style: nonAnimatedStyles }), Element = tag || "div", transformedProps = import_core.hooks.usePropsTransform?.(tag, props, stateRef, !1);
|
|
185
213
|
return (0, import_react2.useE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AU,CAAC,EAAE;AAEhD,cAAI,YAAY,gBAAgB,aAAa;AAC3C,kBAAM,wBACJ,iBAAiB,SAAS,WACtB;AAAA,cACE,MAAM;AAAA,cACN,WAAW,iBAAiB,YAAY,KAAK;AAAA,YAC/C,IACA,iBAAiB,SAAS,WACxB,EAAE,MAAM,SAAS,UAAU,EAAE,IAC7B;AAAA,cACE,MAAM;AAAA,cACN,GAAI;AAAA,YACN;AAER,oBAAQ,MAAM,UAAiB,qBAAqB;AAAA,UACtD;AAAA,QACF,CAAC;AAAA,IACH,GAAG,CAAC,aAAa,CAAC,GAEX,4CAAC,WAAS,GAAG,kBAAkB,KAAK,cAAc;AAAA,EAC3D,CAAC;AAED,mBAAU,gBAAmB,IAEtB;AACT;",
|
|
5
|
+
"names": ["import_react", "React", "animationOptions", "doAnimate", "props"]
|
|
6
6
|
}
|
|
@@ -46,40 +46,46 @@ function createAnimations(animationsProp) {
|
|
|
46
46
|
usePresence: import_use_presence.usePresence,
|
|
47
47
|
ResetPresence: import_use_presence.ResetPresence,
|
|
48
48
|
useAnimations: function(animationProps) {
|
|
49
|
-
var { props, style, componentState, stateRef, useStyleEmitter } = animationProps, animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation, isHydrating = componentState.unmounted === !0, disableAnimation = isHydrating || !animationKey, presenceContext = import_react2.default.useContext(import_use_presence.PresenceContext), [scope, animate] = (0, import_react.useAnimate)(),
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return getMotionAnimatedProps(props, style, disableAnimation);
|
|
49
|
+
var { props, style, componentState, stateRef, useStyleEmitter } = animationProps, animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation, isHydrating = componentState.unmounted === !0, disableAnimation = isHydrating || !animationKey, presenceContext = import_react2.default.useContext(import_use_presence.PresenceContext), [scope, animate] = (0, import_react.useAnimate)(), lastAnimationStyle = (0, import_react2.useRef)(null), controls = (0, import_react2.useRef)(null), styleKey = JSON.stringify(style), { dontAnimate, doAnimate, animationOptions } = (0, import_react2.useMemo)(function() {
|
|
50
|
+
var motionAnimationState = getMotionAnimatedProps(props, style, disableAnimation);
|
|
51
|
+
return motionAnimationState;
|
|
53
52
|
}, [
|
|
54
53
|
presenceContext,
|
|
55
54
|
animationKey,
|
|
56
|
-
|
|
57
|
-
])
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
firstRenderStyle.current = animationStyle, animate(stateRef.current.host, animationStyle, {
|
|
55
|
+
styleKey
|
|
56
|
+
]), runAnimation = function(animationStyle, animationOptions2) {
|
|
57
|
+
if (animationStyle && stateRef.current.host instanceof HTMLElement) {
|
|
58
|
+
if ((0, import_core.fixStyles)(animationStyle), (0, import_core.styleToCSS)(animationStyle), !lastAnimationStyle.current) {
|
|
59
|
+
lastAnimationStyle.current = animationStyle, controls.current = animate(scope.current, animationStyle, {
|
|
62
60
|
duration: 0,
|
|
63
61
|
type: "tween"
|
|
64
|
-
});
|
|
62
|
+
}), controls.current.complete();
|
|
65
63
|
return;
|
|
66
64
|
}
|
|
67
|
-
|
|
65
|
+
var diff = {};
|
|
66
|
+
for (var key2 in animationStyle)
|
|
67
|
+
animationStyle[key2] !== lastAnimationStyle.current[key2] && (diff[key2] = animationStyle[key2]);
|
|
68
|
+
controls.current = animate(scope.current, diff, animationOptions2), lastAnimationStyle.current = animationStyle;
|
|
68
69
|
}
|
|
69
|
-
}
|
|
70
|
+
};
|
|
70
71
|
return useStyleEmitter == null || useStyleEmitter(function(nextStyle) {
|
|
71
72
|
var { doAnimate: doAnimate2, animationOptions: animationOptions2 } = getMotionAnimatedProps(props, nextStyle, disableAnimation);
|
|
72
|
-
|
|
73
|
+
runAnimation(doAnimate2, animationOptions2);
|
|
73
74
|
}), (0, import_react2.useEffect)(function() {
|
|
74
75
|
return function() {
|
|
75
|
-
|
|
76
|
+
lastAnimationStyle.current = null;
|
|
76
77
|
};
|
|
77
78
|
}, []), (0, import_react2.useLayoutEffect)(function() {
|
|
78
79
|
doAnimate && runAnimation(doAnimate, animationOptions);
|
|
79
80
|
}, [
|
|
81
|
+
JSON.stringify(doAnimate),
|
|
82
|
+
lastAnimationStyle
|
|
83
|
+
]), process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile" && console.info("[animations-motion](", JSON.stringify(doAnimate, null, 2) + ")", {
|
|
80
84
|
doAnimate,
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
dontAnimate,
|
|
86
|
+
animationOptions,
|
|
87
|
+
props
|
|
88
|
+
}), {
|
|
83
89
|
style: dontAnimate,
|
|
84
90
|
ref: scope,
|
|
85
91
|
tag: "div"
|
|
@@ -143,10 +149,10 @@ function createAnimations(animationsProp) {
|
|
|
143
149
|
dontAnimate: style,
|
|
144
150
|
doAnimate: null
|
|
145
151
|
};
|
|
146
|
-
var animationOptions = animationPropToAnimationConfig(props.animation), dontAnimate = {}, doAnimate =
|
|
152
|
+
var animationOptions = animationPropToAnimationConfig(props.animation), dontAnimate = {}, doAnimate = null, animateOnly = props.animateOnly;
|
|
147
153
|
for (var key2 in style) {
|
|
148
154
|
var value = style[key2];
|
|
149
|
-
animateOnly && !animateOnly.includes(key2) ? dontAnimate[key2] = value : doAnimate[key2] = value;
|
|
155
|
+
disableAnimationProps.has(key2) || animateOnly && !animateOnly.includes(key2) ? dontAnimate[key2] = value : (doAnimate || (doAnimate = {}), doAnimate[key2] = value);
|
|
150
156
|
}
|
|
151
157
|
return {
|
|
152
158
|
dontAnimate,
|
|
@@ -169,7 +175,26 @@ function createAnimations(animationsProp) {
|
|
|
169
175
|
} : {};
|
|
170
176
|
}
|
|
171
177
|
}
|
|
172
|
-
var
|
|
178
|
+
var disableAnimationProps = /* @__PURE__ */ new Set([
|
|
179
|
+
"alignContent",
|
|
180
|
+
"alignItems",
|
|
181
|
+
"backdropFilter",
|
|
182
|
+
"boxSizing",
|
|
183
|
+
"contain",
|
|
184
|
+
"display",
|
|
185
|
+
"flexBasis",
|
|
186
|
+
"flexDirection",
|
|
187
|
+
"flexShrink",
|
|
188
|
+
"justifyContent",
|
|
189
|
+
"maxHeight",
|
|
190
|
+
"maxWidth",
|
|
191
|
+
"minHeight",
|
|
192
|
+
"minWidth",
|
|
193
|
+
"overflow",
|
|
194
|
+
"pointerEvents",
|
|
195
|
+
"position",
|
|
196
|
+
"textWrap"
|
|
197
|
+
]), MotionView = createMotionView("div"), MotionText = createMotionView("span");
|
|
173
198
|
function createMotionView(defaultTag) {
|
|
174
199
|
var isText = defaultTag === "span", Component = /* @__PURE__ */ (0, import_react2.forwardRef)(function(propsIn, ref) {
|
|
175
200
|
var _hooks_usePropsTransform, { forwardedRef, animation, tag = defaultTag, style, ...propsRest } = propsIn, [scope, animate] = (0, import_react.useAnimate)(), hostRef = (0, import_react2.useRef)(null), composedRefs = (0, import_core.useComposedRefs)(forwardedRef, ref, hostRef, scope), stateRef = (0, import_react2.useRef)(null);
|
|
@@ -199,7 +224,7 @@ function createMotionView(defaultTag) {
|
|
|
199
224
|
// noMergeStyle: true,
|
|
200
225
|
resolveValues: "auto"
|
|
201
226
|
});
|
|
202
|
-
return out.viewProps.style && (0, import_core.styleToCSS)(out.viewProps.style), out.viewProps;
|
|
227
|
+
return out.viewProps.style && ((0, import_core.fixStyles)(out.viewProps.style), (0, import_core.styleToCSS)(out.viewProps.style)), out.viewProps;
|
|
203
228
|
}
|
|
204
229
|
var props = getProps({
|
|
205
230
|
...propsRest,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/createAnimations.tsx"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;uDAAA,
|
|
5
|
-
"names": ["import_react", "MotionValueStrategy", "WeakMap", "createAnimations", "animationsProp", "animations", "key", "type", "View", "MotionView", "Text", "MotionText", "isReactNative", "supportsCSSVars", "needsWebStyles", "avoidReRenders", "usePresence", "ResetPresence", "useAnimations", "animationProps", "props", "style", "componentState", "stateRef", "useStyleEmitter", "animationKey", "Array", "isArray", "animation", "isHydrating", "unmounted", "disableAnimation", "presenceContext", "React", "useContext", "PresenceContext", "scope", "animate", "useAnimate", "
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;uDAAA,cAaO,0BACP,sBAA4D,kCAC5D,eAQO,yBACPA,gBAA+E,2BAYzEC,sBAAsB,oBAAIC,QAAAA;AAEzB,SAASC,iBACdC,gBAAiB;AAKjB,MAAMC,aAAgB,CAAC;AACvB,WAAWC,OAAOF;AAChBC,eAAWC,GAAAA,IAAO;MAChBC,MAAM;MACN,GAAGH,eAAeE,GAAAA;IACpB;AAGF,SAAO;;IAELE,MAAMC;IACNC,MAAMC;IACNC,eAAe;IACfC,iBAAiB;IACjBC,gBAAgB;IAChBC,gBAAgB;IAChBV;IACAW;IACAC;IAEAC,eAAe,SAACC,gBAAAA;AACd,UAAM,EAAEC,OAAOC,OAAOC,gBAAgBC,UAAUC,gBAAe,IAAKL,gBAE9DM,eAAeC,MAAMC,QAAQP,MAAMQ,SAAS,IAC9CR,MAAMQ,UAAU,CAAA,IAChBR,MAAMQ,WAEJC,cAAcP,eAAeQ,cAAc,IAC3CC,mBAAmBF,eAAe,CAACJ,cACnCO,kBAAkBC,cAAAA,QAAMC,WAAWC,mCAAAA,GAEnC,CAACC,OAAOC,OAAAA,QAAWC,yBAAAA,GACnBC,yBAAqBC,sBAAsB,IAAA,GAC3CC,eAAWD,sBAAiD,IAAA,GAC5DE,WAAWC,KAAKC,UAAUvB,KAAAA,GAE1B,EAAEwB,aAAaC,WAAWC,iBAAgB,QAAKC,uBAAQ,WAAA;AAC3D,YAAMC,uBAAuBC,uBAC3B9B,OACAC,OACAU,gBAAAA;AAEF,eAAOkB;MACT,GAAG;QAACjB;QAAiBP;QAAciB;OAAS,GAItCS,eAAe,SACnBC,gBACAL,mBAAAA;AAEA,YAAKK,kBACC7B,SAAS8B,QAAQC,gBAAgBC,aAQvC;kBAHAC,uBAAUJ,cAAAA,OACVK,wBAAWL,cAAAA,GAEP,C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D,KAAKlD,OAAOG,UAAU,EAAA;AAEzEuC,wCAAU,WAAA;AACR,UAAKoE;AAEL,eAAOA,cAAczD,YAAYW,GAAG,UAAU,SAACC,OAAAA;AAC7C,cAAMxB,YAAYqE,cAAcjC,SAASZ,KAAAA,GACnC+D,kBAAkBnJ,oBAAoB4E,IAAIqD,cAAczD,WAAW,GACnE4E,OAAO1B,QAAQtE,SAEfiG,WAAWf,SAAS;YAAElH,OAAOwC;UAAU,CAAA,EAAGxC;AAEhD,cAAIiI,YAAYD,gBAAgB9F,aAAa;AAC3C,gBAAMgG,yBACJH,mBAAAA,OAAAA,SAAAA,gBAAiB7I,UAAS,WACtB;cACEA,MAAM;cACNmD,YAAW0F,mBAAAA,OAAAA,SAAAA,gBAAiB1F,aAAY,KAAK;YAC/C,KACA0F,mBAAAA,OAAAA,SAAAA,gBAAiB7I,UAAS,WACxB;cAAEA,MAAM;cAASmD,UAAU;YAAE,IAC7B;cACEnD,MAAM;cACN,GAAI6I;YACN;AAER/G,oBAAQgH,MAAMC,UAAiBC,qBAAAA;UACjC;QACF,CAAA;IACF,GAAG;MAACrB;KAAc,GAEX,uCAAAsB,KAACP,SAAAA;MAAS,GAAGC;MAAkB7E,KAAKuD;;EAC7C,CAAA;AAEAP,mBAAU,gBAAmB,IAEtBA;AACT;",
|
|
5
|
+
"names": ["import_react", "MotionValueStrategy", "WeakMap", "createAnimations", "animationsProp", "animations", "key", "type", "View", "MotionView", "Text", "MotionText", "isReactNative", "supportsCSSVars", "needsWebStyles", "avoidReRenders", "usePresence", "ResetPresence", "useAnimations", "animationProps", "props", "style", "componentState", "stateRef", "useStyleEmitter", "animationKey", "Array", "isArray", "animation", "isHydrating", "unmounted", "disableAnimation", "presenceContext", "React", "useContext", "PresenceContext", "scope", "animate", "useAnimate", "lastAnimationStyle", "useRef", "controls", "styleKey", "JSON", "stringify", "dontAnimate", "doAnimate", "animationOptions", "useMemo", "motionAnimationState", "getMotionAnimatedProps", "runAnimation", "animationStyle", "current", "host", "HTMLElement", "fixStyles", "styleToCSS", "duration", "complete", "diff", "nextStyle", "useEffect", "useLayoutEffect", "process", "env", "NODE_ENV", "console", "info", "ref", "tag", "useAnimatedNumber", "initial", "motionValue", "useMotionValue", "getInstance", "getValue", "get", "setValue", "next", "config", "onFinish", "set", "unsubscribe", "on", "value", "Math", "abs", "stop", "useAnimatedNumberReaction", "onValue", "instance", "useMotionValueEvent", "useAnimatedNumberStyle", "val", "getStyleProp", "getStyleRef", "getStyle", "cur", "disable", "animationPropToAnimationConfig", "animateOnly", "disableAnimationProps", "has", "includes", "animationProp", "defaultAnimationKey", "specificAnimations", "default", "Object", "fromEntries", "keys", "flatMap", "Set", "createMotionView", "defaultTag", "isText", "Component", "forwardRef", "propsIn", "hooks", "forwardedRef", "propsRest", "hostRef", "composedRefs", "useComposedRefs", "_", "state", "useThemeWithState", "styles", "animatedStyle", "nonAnimatedStyles", "find", "x", "filter", "getProps", "out", "getSplitStyles", "staticConfig", "theme", "name", "isAnimated", "noClass", "resolveValues", "viewProps", "Element", "transformedProps", "usePropsTransform", "animationConfig", "node", "webStyle", "motionAnimationConfig", "_jsx"]
|
|
6
6
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
fixStyles,
|
|
2
3
|
getSplitStyles,
|
|
3
4
|
hooks,
|
|
4
5
|
styleToCSS,
|
|
@@ -35,33 +36,42 @@ function createAnimations(animationsProp) {
|
|
|
35
36
|
usePresence,
|
|
36
37
|
ResetPresence,
|
|
37
38
|
useAnimations: (animationProps) => {
|
|
38
|
-
const { props, style, componentState, stateRef, useStyleEmitter } = animationProps, animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation, disableAnimation = componentState.unmounted === !0 || !animationKey, presenceContext = React.useContext(PresenceContext), [scope, animate] = useAnimate(),
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
39
|
+
const { props, style, componentState, stateRef, useStyleEmitter } = animationProps, animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation, disableAnimation = componentState.unmounted === !0 || !animationKey, presenceContext = React.useContext(PresenceContext), [scope, animate] = useAnimate(), lastAnimationStyle = useRef(null), controls = useRef(null), styleKey = JSON.stringify(style), { dontAnimate, doAnimate, animationOptions } = useMemo(() => getMotionAnimatedProps(
|
|
40
|
+
props,
|
|
41
|
+
style,
|
|
42
|
+
disableAnimation
|
|
43
|
+
), [presenceContext, animationKey, styleKey]), runAnimation = (animationStyle, animationOptions2) => {
|
|
44
|
+
if (!animationStyle || !(stateRef.current.host instanceof HTMLElement))
|
|
45
|
+
return;
|
|
46
|
+
if (fixStyles(animationStyle), styleToCSS(animationStyle), !lastAnimationStyle.current) {
|
|
47
|
+
lastAnimationStyle.current = animationStyle, controls.current = animate(scope.current, animationStyle, {
|
|
48
|
+
duration: 0,
|
|
49
|
+
type: "tween"
|
|
50
|
+
}), controls.current.complete();
|
|
51
|
+
return;
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
+
const diff = {};
|
|
54
|
+
for (const key in animationStyle)
|
|
55
|
+
animationStyle[key] !== lastAnimationStyle.current[key] && (diff[key] = animationStyle[key]);
|
|
56
|
+
controls.current = animate(scope.current, diff, animationOptions2), lastAnimationStyle.current = animationStyle;
|
|
57
|
+
};
|
|
53
58
|
return useStyleEmitter?.((nextStyle) => {
|
|
54
59
|
const { doAnimate: doAnimate2, animationOptions: animationOptions2 } = getMotionAnimatedProps(
|
|
55
60
|
props,
|
|
56
61
|
nextStyle,
|
|
57
62
|
disableAnimation
|
|
58
63
|
);
|
|
59
|
-
|
|
64
|
+
runAnimation(doAnimate2, animationOptions2);
|
|
60
65
|
}), useEffect(() => () => {
|
|
61
|
-
|
|
66
|
+
lastAnimationStyle.current = null;
|
|
62
67
|
}, []), useLayoutEffect(() => {
|
|
63
68
|
doAnimate && runAnimation(doAnimate, animationOptions);
|
|
64
|
-
}, [doAnimate,
|
|
69
|
+
}, [JSON.stringify(doAnimate), lastAnimationStyle]), process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile" && console.info("[animations-motion](", JSON.stringify(doAnimate, null, 2) + ")", {
|
|
70
|
+
doAnimate,
|
|
71
|
+
dontAnimate,
|
|
72
|
+
animationOptions,
|
|
73
|
+
props
|
|
74
|
+
}), {
|
|
65
75
|
style: dontAnimate,
|
|
66
76
|
ref: scope,
|
|
67
77
|
tag: "div"
|
|
@@ -117,11 +127,11 @@ function createAnimations(animationsProp) {
|
|
|
117
127
|
doAnimate: null
|
|
118
128
|
};
|
|
119
129
|
const animationOptions = animationPropToAnimationConfig(props.animation);
|
|
120
|
-
let dontAnimate = {};
|
|
121
|
-
const
|
|
130
|
+
let dontAnimate = {}, doAnimate = null;
|
|
131
|
+
const animateOnly = props.animateOnly;
|
|
122
132
|
for (const key in style) {
|
|
123
133
|
const value = style[key];
|
|
124
|
-
animateOnly && !animateOnly.includes(key) ? dontAnimate[key] = value : doAnimate[key] = value;
|
|
134
|
+
disableAnimationProps.has(key) || animateOnly && !animateOnly.includes(key) ? dontAnimate[key] = value : (doAnimate ||= {}, doAnimate[key] = value);
|
|
125
135
|
}
|
|
126
136
|
return {
|
|
127
137
|
dontAnimate,
|
|
@@ -139,7 +149,26 @@ function createAnimations(animationsProp) {
|
|
|
139
149
|
} : {};
|
|
140
150
|
}
|
|
141
151
|
}
|
|
142
|
-
const
|
|
152
|
+
const disableAnimationProps = /* @__PURE__ */ new Set([
|
|
153
|
+
"alignContent",
|
|
154
|
+
"alignItems",
|
|
155
|
+
"backdropFilter",
|
|
156
|
+
"boxSizing",
|
|
157
|
+
"contain",
|
|
158
|
+
"display",
|
|
159
|
+
"flexBasis",
|
|
160
|
+
"flexDirection",
|
|
161
|
+
"flexShrink",
|
|
162
|
+
"justifyContent",
|
|
163
|
+
"maxHeight",
|
|
164
|
+
"maxWidth",
|
|
165
|
+
"minHeight",
|
|
166
|
+
"minWidth",
|
|
167
|
+
"overflow",
|
|
168
|
+
"pointerEvents",
|
|
169
|
+
"position",
|
|
170
|
+
"textWrap"
|
|
171
|
+
]), MotionView = createMotionView("div"), MotionText = createMotionView("span");
|
|
143
172
|
function createMotionView(defaultTag) {
|
|
144
173
|
const isText = defaultTag === "span", Component = forwardRef((propsIn, ref) => {
|
|
145
174
|
const { forwardedRef, animation, tag = defaultTag, style, ...propsRest } = propsIn, [scope, animate] = useAnimate(), hostRef = useRef(null), composedRefs = useComposedRefs(forwardedRef, ref, hostRef, scope), stateRef = useRef(null);
|
|
@@ -168,7 +197,7 @@ function createMotionView(defaultTag) {
|
|
|
168
197
|
resolveValues: "auto"
|
|
169
198
|
}
|
|
170
199
|
);
|
|
171
|
-
return out.viewProps.style && styleToCSS(out.viewProps.style), out.viewProps;
|
|
200
|
+
return out.viewProps.style && (fixStyles(out.viewProps.style), styleToCSS(out.viewProps.style)), out.viewProps;
|
|
172
201
|
}
|
|
173
202
|
const props = getProps({ ...propsRest, style: nonAnimatedStyles }), Element = tag || "div", transformedProps = hooks.usePropsTransform?.(tag, props, stateRef, !1);
|
|
174
203
|
return useEffect(() => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/createAnimations.tsx"],
|
|
4
|
-
"mappings": "AAAA;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB,eAAe,mBAAmB;AAC5D;AAAA,
|
|
5
|
-
"names": ["
|
|
4
|
+
"mappings": "AAAA;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB,eAAe,mBAAmB;AAC5D;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,OAE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C,aAAa,CAAC,GAEX,oBAAC,WAAS,GAAG,kBAAkB,KAAK,cAAc;AAAA,EAC3D,CAAC;AAED,mBAAU,gBAAmB,IAEtB;AACT;",
|
|
5
|
+
"names": ["animationOptions", "doAnimate", "props"]
|
|
6
6
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getSplitStyles, hooks, styleToCSS, Text, useComposedRefs, useThemeWithState, View } from "@tamagui/core";
|
|
1
|
+
import { fixStyles, getSplitStyles, hooks, styleToCSS, Text, useComposedRefs, useThemeWithState, View } from "@tamagui/core";
|
|
2
2
|
import { PresenceContext, ResetPresence, usePresence } from "@tamagui/use-presence";
|
|
3
3
|
import { useAnimate, useMotionValue, useMotionValueEvent } from "motion/react";
|
|
4
4
|
import React, { forwardRef, useEffect, useLayoutEffect, useMemo, useRef } from "react";
|
|
@@ -33,36 +33,43 @@ function createAnimations(animationsProp) {
|
|
|
33
33
|
disableAnimation = componentState.unmounted === !0 || !animationKey,
|
|
34
34
|
presenceContext = React.useContext(PresenceContext),
|
|
35
35
|
[scope, animate] = useAnimate(),
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (!
|
|
46
|
-
|
|
36
|
+
lastAnimationStyle = useRef(null),
|
|
37
|
+
controls = useRef(null),
|
|
38
|
+
styleKey = JSON.stringify(style),
|
|
39
|
+
{
|
|
40
|
+
dontAnimate,
|
|
41
|
+
doAnimate,
|
|
42
|
+
animationOptions
|
|
43
|
+
} = useMemo(() => getMotionAnimatedProps(props, style, disableAnimation), [presenceContext, animationKey, styleKey]),
|
|
44
|
+
runAnimation = (animationStyle, animationOptions2) => {
|
|
45
|
+
if (!animationStyle || !(stateRef.current.host instanceof HTMLElement)) return;
|
|
46
|
+
if (fixStyles(animationStyle), styleToCSS(animationStyle), !lastAnimationStyle.current) {
|
|
47
|
+
lastAnimationStyle.current = animationStyle, controls.current = animate(scope.current, animationStyle, {
|
|
47
48
|
duration: 0,
|
|
48
49
|
type: "tween"
|
|
49
|
-
});
|
|
50
|
+
}), controls.current.complete();
|
|
50
51
|
return;
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
const diff = {};
|
|
54
|
+
for (const key in animationStyle) animationStyle[key] !== lastAnimationStyle.current[key] && (diff[key] = animationStyle[key]);
|
|
55
|
+
controls.current = animate(scope.current, diff, animationOptions2), lastAnimationStyle.current = animationStyle;
|
|
56
|
+
};
|
|
55
57
|
return useStyleEmitter?.(nextStyle => {
|
|
56
58
|
const {
|
|
57
59
|
doAnimate: doAnimate2,
|
|
58
60
|
animationOptions: animationOptions2
|
|
59
61
|
} = getMotionAnimatedProps(props, nextStyle, disableAnimation);
|
|
60
|
-
|
|
62
|
+
runAnimation(doAnimate2, animationOptions2);
|
|
61
63
|
}), useEffect(() => () => {
|
|
62
|
-
|
|
64
|
+
lastAnimationStyle.current = null;
|
|
63
65
|
}, []), useLayoutEffect(() => {
|
|
64
66
|
doAnimate && runAnimation(doAnimate, animationOptions);
|
|
65
|
-
}, [doAnimate,
|
|
67
|
+
}, [JSON.stringify(doAnimate), lastAnimationStyle]), process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile" && console.info("[animations-motion](", JSON.stringify(doAnimate, null, 2) + ")", {
|
|
68
|
+
doAnimate,
|
|
69
|
+
dontAnimate,
|
|
70
|
+
animationOptions,
|
|
71
|
+
props
|
|
72
|
+
}), {
|
|
66
73
|
style: dontAnimate,
|
|
67
74
|
ref: scope,
|
|
68
75
|
tag: "div"
|
|
@@ -117,12 +124,12 @@ function createAnimations(animationsProp) {
|
|
|
117
124
|
doAnimate: null
|
|
118
125
|
};
|
|
119
126
|
const animationOptions = animationPropToAnimationConfig(props.animation);
|
|
120
|
-
let dontAnimate = {}
|
|
121
|
-
|
|
122
|
-
|
|
127
|
+
let dontAnimate = {},
|
|
128
|
+
doAnimate = null;
|
|
129
|
+
const animateOnly = props.animateOnly;
|
|
123
130
|
for (const key in style) {
|
|
124
131
|
const value = style[key];
|
|
125
|
-
animateOnly && !animateOnly.includes(key) ? dontAnimate[key] = value : doAnimate[key] = value;
|
|
132
|
+
disableAnimationProps.has(key) || animateOnly && !animateOnly.includes(key) ? dontAnimate[key] = value : (doAnimate ||= {}, doAnimate[key] = value);
|
|
126
133
|
}
|
|
127
134
|
return {
|
|
128
135
|
dontAnimate,
|
|
@@ -139,7 +146,8 @@ function createAnimations(animationsProp) {
|
|
|
139
146
|
} : {};
|
|
140
147
|
}
|
|
141
148
|
}
|
|
142
|
-
const
|
|
149
|
+
const disableAnimationProps = /* @__PURE__ */new Set(["alignContent", "alignItems", "backdropFilter", "boxSizing", "contain", "display", "flexBasis", "flexDirection", "flexShrink", "justifyContent", "maxHeight", "maxWidth", "minHeight", "minWidth", "overflow", "pointerEvents", "position", "textWrap"]),
|
|
150
|
+
MotionView = createMotionView("div"),
|
|
143
151
|
MotionText = createMotionView("span");
|
|
144
152
|
function createMotionView(defaultTag) {
|
|
145
153
|
const isText = defaultTag === "span",
|
|
@@ -172,7 +180,7 @@ function createMotionView(defaultTag) {
|
|
|
172
180
|
// noMergeStyle: true,
|
|
173
181
|
resolveValues: "auto"
|
|
174
182
|
});
|
|
175
|
-
return out.viewProps.style && styleToCSS(out.viewProps.style), out.viewProps;
|
|
183
|
+
return out.viewProps.style && (fixStyles(out.viewProps.style), styleToCSS(out.viewProps.style)), out.viewProps;
|
|
176
184
|
}
|
|
177
185
|
const props = getProps({
|
|
178
186
|
...propsRest,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getSplitStyles","hooks","styleToCSS","Text","useComposedRefs","useThemeWithState","View","PresenceContext","ResetPresence","usePresence","useAnimate","useMotionValue","useMotionValueEvent","React","forwardRef","useEffect","useLayoutEffect","useMemo","useRef","jsx","MotionValueStrategy","WeakMap","createAnimations","animationsProp","animations","key","type","MotionView","MotionText","isReactNative","supportsCSSVars","needsWebStyles","avoidReRenders","useAnimations","animationProps","props","style","componentState","stateRef","useStyleEmitter","animationKey","Array","isArray","animation","disableAnimation","unmounted","presenceContext","useContext","scope","animate","
|
|
1
|
+
{"version":3,"names":["fixStyles","getSplitStyles","hooks","styleToCSS","Text","useComposedRefs","useThemeWithState","View","PresenceContext","ResetPresence","usePresence","useAnimate","useMotionValue","useMotionValueEvent","React","forwardRef","useEffect","useLayoutEffect","useMemo","useRef","jsx","MotionValueStrategy","WeakMap","createAnimations","animationsProp","animations","key","type","MotionView","MotionText","isReactNative","supportsCSSVars","needsWebStyles","avoidReRenders","useAnimations","animationProps","props","style","componentState","stateRef","useStyleEmitter","animationKey","Array","isArray","animation","disableAnimation","unmounted","presenceContext","useContext","scope","animate","lastAnimationStyle","controls","styleKey","JSON","stringify","dontAnimate","doAnimate","animationOptions","getMotionAnimatedProps","runAnimation","animationStyle","animationOptions2","current","host","HTMLElement","duration","complete","diff","nextStyle","doAnimate2","process","env","NODE_ENV","debug","console","info","ref","tag","useAnimatedNumber","initial","motionValue","getInstance","getValue","get","setValue","next","config","onFinish","set","unsubscribe","on","value","Math","abs","stop","useAnimatedNumberReaction","onValue","instance","useAnimatedNumberStyle","val","getStyleProp","getStyleRef","getStyle","cur","disable","animationPropToAnimationConfig","animateOnly","disableAnimationProps","has","includes","animationProp","defaultAnimationKey","specificAnimations","default","Object","fromEntries","keys","flatMap","Set","createMotionView","defaultTag","isText","Component","propsIn","forwardedRef","propsRest","hostRef","composedRefs","_","state","styles","animatedStyle","nonAnimatedStyles","find","x","filter","getProps","props2","out","staticConfig","theme","name","isAnimated","noClass","resolveValues","viewProps","Element","transformedProps","usePropsTransform","animationConfig","node","webStyle","motionAnimationConfig","acceptTagProp"],"sources":["../../src/createAnimations.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAIEA,SAAA,EACAC,cAAA,EACAC,KAAA,EACAC,UAAA,EACAC,IAAA,EAEAC,eAAA,EACAC,iBAAA,EACAC,IAAA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3D,CAAC;EAED,OAAAL,SAAA,CAAU+B,aAAA,GAAmB,IAEtB/B,SAAA;AACT","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { getSplitStyles, hooks, styleToCSS, Text, useComposedRefs, useThemeWithState, View } from "@tamagui/core";
|
|
2
|
+
import { fixStyles, getSplitStyles, hooks, styleToCSS, Text, useComposedRefs, useThemeWithState, View } from "@tamagui/core";
|
|
3
3
|
import { PresenceContext, ResetPresence, usePresence } from "@tamagui/use-presence";
|
|
4
4
|
import { useAnimate, useMotionValue, useMotionValueEvent } from "motion/react";
|
|
5
5
|
import React, { forwardRef, useEffect, useLayoutEffect, useMemo, useRef } from "react";
|
|
@@ -34,40 +34,49 @@ function createAnimations(animationsProp) {
|
|
|
34
34
|
disableAnimation = isHydrating || !animationKey,
|
|
35
35
|
presenceContext = React.useContext(PresenceContext),
|
|
36
36
|
[scope, animate] = useAnimate(),
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
37
|
+
lastAnimationStyle = useRef(null),
|
|
38
|
+
controls = useRef(null),
|
|
39
|
+
styleKey = JSON.stringify(style),
|
|
40
|
+
{
|
|
41
|
+
dontAnimate,
|
|
42
|
+
doAnimate,
|
|
43
|
+
animationOptions
|
|
44
|
+
} = useMemo(function () {
|
|
45
|
+
var motionAnimationState = getMotionAnimatedProps(props, style, disableAnimation);
|
|
46
|
+
return motionAnimationState;
|
|
47
|
+
}, [presenceContext, animationKey, styleKey]),
|
|
48
|
+
runAnimation = function (animationStyle, animationOptions2) {
|
|
49
|
+
if (animationStyle && stateRef.current.host instanceof HTMLElement) {
|
|
50
|
+
if (fixStyles(animationStyle), styleToCSS(animationStyle), !lastAnimationStyle.current) {
|
|
51
|
+
lastAnimationStyle.current = animationStyle, controls.current = animate(scope.current, animationStyle, {
|
|
52
|
+
duration: 0,
|
|
53
|
+
type: "tween"
|
|
54
|
+
}), controls.current.complete();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
var diff = {};
|
|
58
|
+
for (var key2 in animationStyle) animationStyle[key2] !== lastAnimationStyle.current[key2] && (diff[key2] = animationStyle[key2]);
|
|
59
|
+
controls.current = animate(scope.current, diff, animationOptions2), lastAnimationStyle.current = animationStyle;
|
|
54
60
|
}
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
}
|
|
61
|
+
};
|
|
58
62
|
return useStyleEmitter?.(function (nextStyle) {
|
|
59
63
|
var {
|
|
60
64
|
doAnimate: doAnimate2,
|
|
61
65
|
animationOptions: animationOptions2
|
|
62
66
|
} = getMotionAnimatedProps(props, nextStyle, disableAnimation);
|
|
63
|
-
|
|
67
|
+
runAnimation(doAnimate2, animationOptions2);
|
|
64
68
|
}), useEffect(function () {
|
|
65
69
|
return function () {
|
|
66
|
-
|
|
70
|
+
lastAnimationStyle.current = null;
|
|
67
71
|
};
|
|
68
72
|
}, []), useLayoutEffect(function () {
|
|
69
73
|
doAnimate && runAnimation(doAnimate, animationOptions);
|
|
70
|
-
}, [doAnimate,
|
|
74
|
+
}, [JSON.stringify(doAnimate), lastAnimationStyle]), process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile" && console.info("[animations-motion](", JSON.stringify(doAnimate, null, 2) + ")", {
|
|
75
|
+
doAnimate,
|
|
76
|
+
dontAnimate,
|
|
77
|
+
animationOptions,
|
|
78
|
+
props
|
|
79
|
+
}), {
|
|
71
80
|
style: dontAnimate,
|
|
72
81
|
ref: scope,
|
|
73
82
|
tag: "div"
|
|
@@ -132,11 +141,11 @@ function createAnimations(animationsProp) {
|
|
|
132
141
|
};
|
|
133
142
|
var animationOptions = animationPropToAnimationConfig(props.animation),
|
|
134
143
|
dontAnimate = {},
|
|
135
|
-
doAnimate =
|
|
144
|
+
doAnimate = null,
|
|
136
145
|
animateOnly = props.animateOnly;
|
|
137
146
|
for (var key2 in style) {
|
|
138
147
|
var value = style[key2];
|
|
139
|
-
animateOnly && !animateOnly.includes(key2) ? dontAnimate[key2] = value : doAnimate[key2] = value;
|
|
148
|
+
disableAnimationProps.has(key2) || animateOnly && !animateOnly.includes(key2) ? dontAnimate[key2] = value : (doAnimate || (doAnimate = {}), doAnimate[key2] = value);
|
|
140
149
|
}
|
|
141
150
|
return {
|
|
142
151
|
dontAnimate,
|
|
@@ -155,7 +164,8 @@ function createAnimations(animationsProp) {
|
|
|
155
164
|
} : {};
|
|
156
165
|
}
|
|
157
166
|
}
|
|
158
|
-
var
|
|
167
|
+
var disableAnimationProps = /* @__PURE__ */new Set(["alignContent", "alignItems", "backdropFilter", "boxSizing", "contain", "display", "flexBasis", "flexDirection", "flexShrink", "justifyContent", "maxHeight", "maxWidth", "minHeight", "minWidth", "overflow", "pointerEvents", "position", "textWrap"]),
|
|
168
|
+
MotionView = createMotionView("div"),
|
|
159
169
|
MotionText = createMotionView("span");
|
|
160
170
|
function createMotionView(defaultTag) {
|
|
161
171
|
var isText = defaultTag === "span",
|
|
@@ -195,7 +205,7 @@ function createMotionView(defaultTag) {
|
|
|
195
205
|
// noMergeStyle: true,
|
|
196
206
|
resolveValues: "auto"
|
|
197
207
|
});
|
|
198
|
-
return out.viewProps.style && styleToCSS(out.viewProps.style), out.viewProps;
|
|
208
|
+
return out.viewProps.style && (fixStyles(out.viewProps.style), styleToCSS(out.viewProps.style)), out.viewProps;
|
|
199
209
|
}
|
|
200
210
|
var props = getProps({
|
|
201
211
|
...propsRest,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["jsx","_jsx","getSplitStyles","hooks","styleToCSS","Text","useComposedRefs","useThemeWithState","View","PresenceContext","ResetPresence","usePresence","useAnimate","useMotionValue","useMotionValueEvent","React","forwardRef","useEffect","useLayoutEffect","useMemo","useRef","MotionValueStrategy","WeakMap","createAnimations","animationsProp","animations","key","type","MotionView","MotionText","isReactNative","supportsCSSVars","needsWebStyles","avoidReRenders","useAnimations","animationProps","props","style","componentState","stateRef","useStyleEmitter","animationKey","Array","isArray","animation","isHydrating","unmounted","disableAnimation","presenceContext","useContext","scope","animate","
|
|
1
|
+
{"version":3,"names":["jsx","_jsx","fixStyles","getSplitStyles","hooks","styleToCSS","Text","useComposedRefs","useThemeWithState","View","PresenceContext","ResetPresence","usePresence","useAnimate","useMotionValue","useMotionValueEvent","React","forwardRef","useEffect","useLayoutEffect","useMemo","useRef","MotionValueStrategy","WeakMap","createAnimations","animationsProp","animations","key","type","MotionView","MotionText","isReactNative","supportsCSSVars","needsWebStyles","avoidReRenders","useAnimations","animationProps","props","style","componentState","stateRef","useStyleEmitter","animationKey","Array","isArray","animation","isHydrating","unmounted","disableAnimation","presenceContext","useContext","scope","animate","lastAnimationStyle","controls","styleKey","JSON","stringify","dontAnimate","doAnimate","animationOptions","motionAnimationState","getMotionAnimatedProps","runAnimation","animationStyle","animationOptions2","current","host","HTMLElement","duration","complete","diff","key2","nextStyle","doAnimate2","process","env","NODE_ENV","debug","console","info","ref","tag","useAnimatedNumber","initial","motionValue","getInstance","getValue","get","setValue","next","config","arguments","length","onFinish","set","unsubscribe","on","value","Math","abs","stop","useAnimatedNumberReaction","param","onValue","instance","useAnimatedNumberStyle","val","getStyleProp","getStyleRef","getStyle","cur","disable","animationPropToAnimationConfig","animateOnly","disableAnimationProps","has","includes","animationProp","defaultAnimationKey","specificAnimations","default","Object","fromEntries","keys","flatMap","Set","createMotionView","defaultTag","isText","Component","propsIn","_hooks_usePropsTransform","forwardedRef","propsRest","hostRef","composedRefs","_","state","styles","animatedStyle","nonAnimatedStyles","find","x","filter","getProps","props2","out","staticConfig","theme","name","isAnimated","noClass","resolveValues","viewProps","Element","transformedProps","usePropsTransform","call","animationConfig","node","webStyle","motionAnimationConfig"],"sources":["../../src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AAA,CAAAyJ,iBAAA,cAAAzB,wBAAA,uBAAAA,wBAAA,CAAA0B,IAAA,CAAA1J,KAAA,EAAA8E,GAAA,EAAA7C,KAAA,EAAAG,QAAA;MAAA,OAAAtB,SACN,aAAW;QAAkC,IAAA0H,aAE/C,EAEE,OACEA,aAAM,CAAAvD,WAAA,CAAAY,EAAA,qBAAAC,KAAA;UAAA,IACNzB,SAAI,GAAAmE,aAAA,CAAA9B,QAAA,CAAAZ,KAAA;YAAA6D,eAAA,GAAAzI,mBAAA,CAAAkE,GAAA,CAAAoD,aAAA,CAAAvD,WAAA;YAAA2E,IAAA,GAAAzB,OAAA,CAAArE,OAAA;YAAA+F,QAAA,GAAAhB,QAAA;cACN3G,KAAA,EAAAmC;YAER,GAAAnC,KAAA;UACF,IAAA2H,QAAA,IAAAD,IAAA,YAAA5F,WAAA;YACD,IAAA8F,qBAAA,GAAAH,eAAA,EAAAnI,IAAA;cACCA,IAAA,SAEG;cACRyC,QAAA,GAAA0F,eAAA,EAAA1F,QAAA;YAED,IAAA0F,eAAU,EAAAnI,IAAmB,KAEtB;cACTA,IAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/animations-motion",
|
|
3
|
-
"version": "1.129.
|
|
3
|
+
"version": "1.129.6",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@tamagui/core": "1.129.
|
|
33
|
-
"@tamagui/use-presence": "1.129.
|
|
32
|
+
"@tamagui/core": "1.129.6",
|
|
33
|
+
"@tamagui/use-presence": "1.129.6",
|
|
34
34
|
"motion": "^12.19.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@tamagui/build": "1.129.
|
|
37
|
+
"@tamagui/build": "1.129.6",
|
|
38
38
|
"react": "*"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
package/src/createAnimations.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
type AnimatedNumberStrategy,
|
|
3
3
|
type AnimationDriver,
|
|
4
4
|
type AnimationProp,
|
|
5
|
+
fixStyles,
|
|
5
6
|
getSplitStyles,
|
|
6
7
|
hooks,
|
|
7
8
|
styleToCSS,
|
|
@@ -14,6 +15,7 @@ import {
|
|
|
14
15
|
import { PresenceContext, ResetPresence, usePresence } from '@tamagui/use-presence'
|
|
15
16
|
import {
|
|
16
17
|
type AnimationOptions,
|
|
18
|
+
type AnimationPlaybackControlsWithThen,
|
|
17
19
|
type MotionValue,
|
|
18
20
|
useAnimate,
|
|
19
21
|
useMotionValue,
|
|
@@ -72,34 +74,55 @@ export function createAnimations<A extends Record<string, AnimationConfig>>(
|
|
|
72
74
|
const presenceContext = React.useContext(PresenceContext)
|
|
73
75
|
|
|
74
76
|
const [scope, animate] = useAnimate()
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
styleToCSS(props.style) // ideally this would just come from tamagui
|
|
79
|
-
}
|
|
77
|
+
const lastAnimationStyle = useRef<Object | null>(null)
|
|
78
|
+
const controls = useRef<AnimationPlaybackControlsWithThen | null>(null)
|
|
79
|
+
const styleKey = JSON.stringify(style)
|
|
80
80
|
|
|
81
81
|
const { dontAnimate, doAnimate, animationOptions } = useMemo(() => {
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
const motionAnimationState = getMotionAnimatedProps(
|
|
83
|
+
props as any,
|
|
84
|
+
style,
|
|
85
|
+
disableAnimation
|
|
86
|
+
)
|
|
87
|
+
return motionAnimationState
|
|
88
|
+
}, [presenceContext, animationKey, styleKey])
|
|
84
89
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
// const id = useId()
|
|
91
|
+
|
|
92
|
+
const runAnimation = (
|
|
93
|
+
animationStyle: Record<string, unknown> | null,
|
|
94
|
+
animationOptions: AnimationOptions | undefined
|
|
95
|
+
) => {
|
|
96
|
+
if (!animationStyle) return
|
|
89
97
|
if (!(stateRef.current.host instanceof HTMLElement)) {
|
|
90
98
|
return
|
|
91
99
|
}
|
|
92
100
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
101
|
+
// ideally this would just come from tamagui
|
|
102
|
+
fixStyles(animationStyle)
|
|
103
|
+
styleToCSS(animationStyle)
|
|
104
|
+
|
|
105
|
+
if (!lastAnimationStyle.current) {
|
|
106
|
+
// console.log('first', id, animationStyle)
|
|
107
|
+
lastAnimationStyle.current = animationStyle
|
|
108
|
+
controls.current = animate(scope.current, animationStyle, {
|
|
96
109
|
duration: 0,
|
|
97
110
|
type: 'tween',
|
|
98
111
|
})
|
|
112
|
+
controls.current.complete()
|
|
99
113
|
return
|
|
100
114
|
}
|
|
101
115
|
|
|
102
|
-
|
|
116
|
+
const diff = {}
|
|
117
|
+
for (const key in animationStyle) {
|
|
118
|
+
if (animationStyle[key] !== lastAnimationStyle.current[key]) {
|
|
119
|
+
diff[key] = animationStyle[key]
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// console.log('animate', id, diff)
|
|
124
|
+
controls.current = animate(scope.current, diff, animationOptions)
|
|
125
|
+
lastAnimationStyle.current = animationStyle
|
|
103
126
|
}
|
|
104
127
|
|
|
105
128
|
useStyleEmitter?.((nextStyle) => {
|
|
@@ -108,27 +131,38 @@ export function createAnimations<A extends Record<string, AnimationConfig>>(
|
|
|
108
131
|
nextStyle,
|
|
109
132
|
disableAnimation
|
|
110
133
|
)
|
|
111
|
-
|
|
112
|
-
runAnimation(doAnimate, animationOptions)
|
|
113
|
-
// Object.assign(dontAnimate, doAnimate)
|
|
114
|
-
}
|
|
134
|
+
runAnimation(doAnimate, animationOptions)
|
|
115
135
|
})
|
|
116
136
|
|
|
117
137
|
// strict mode correctness fix, idk why i thought it would clear a useRef
|
|
118
138
|
// before running strict? if you remove this you'll see the next
|
|
119
|
-
// useLayoutEffect re-run and animate due to
|
|
139
|
+
// useLayoutEffect re-run and animate due to lastAnimationStyle.current
|
|
120
140
|
// being set when in theory it should be clear
|
|
121
141
|
useEffect(() => {
|
|
122
142
|
return () => {
|
|
123
|
-
|
|
143
|
+
lastAnimationStyle.current = null
|
|
124
144
|
}
|
|
125
145
|
}, [])
|
|
126
146
|
|
|
127
147
|
useLayoutEffect(() => {
|
|
128
148
|
if (!doAnimate) return
|
|
129
|
-
// debugger
|
|
130
149
|
runAnimation(doAnimate, animationOptions)
|
|
131
|
-
}, [doAnimate,
|
|
150
|
+
}, [JSON.stringify(doAnimate), lastAnimationStyle])
|
|
151
|
+
|
|
152
|
+
if (
|
|
153
|
+
process.env.NODE_ENV === 'development' &&
|
|
154
|
+
props['debug'] &&
|
|
155
|
+
props['debug'] !== 'profile'
|
|
156
|
+
) {
|
|
157
|
+
console.info(`[animations-motion](`, JSON.stringify(doAnimate, null, 2) + ')', {
|
|
158
|
+
doAnimate,
|
|
159
|
+
dontAnimate,
|
|
160
|
+
animationOptions,
|
|
161
|
+
props,
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// console.log('render', id, scope)
|
|
132
166
|
|
|
133
167
|
return {
|
|
134
168
|
style: dontAnimate,
|
|
@@ -218,14 +252,15 @@ export function createAnimations<A extends Record<string, AnimationConfig>>(
|
|
|
218
252
|
const animationOptions = animationPropToAnimationConfig(props.animation)
|
|
219
253
|
|
|
220
254
|
let dontAnimate = {}
|
|
221
|
-
|
|
255
|
+
let doAnimate: Record<string, unknown> | null = null
|
|
222
256
|
|
|
223
257
|
const animateOnly = props.animateOnly as string[] | undefined
|
|
224
258
|
for (const key in style) {
|
|
225
259
|
const value = style[key]
|
|
226
|
-
if (animateOnly && !animateOnly.includes(key)) {
|
|
260
|
+
if (disableAnimationProps.has(key) || (animateOnly && !animateOnly.includes(key))) {
|
|
227
261
|
dontAnimate[key] = value
|
|
228
262
|
} else {
|
|
263
|
+
doAnimate ||= {}
|
|
229
264
|
doAnimate[key] = value
|
|
230
265
|
}
|
|
231
266
|
}
|
|
@@ -272,6 +307,28 @@ export function createAnimations<A extends Record<string, AnimationConfig>>(
|
|
|
272
307
|
}
|
|
273
308
|
}
|
|
274
309
|
|
|
310
|
+
// sort of temporary
|
|
311
|
+
const disableAnimationProps = new Set<string>([
|
|
312
|
+
'alignContent',
|
|
313
|
+
'alignItems',
|
|
314
|
+
'backdropFilter',
|
|
315
|
+
'boxSizing',
|
|
316
|
+
'contain',
|
|
317
|
+
'display',
|
|
318
|
+
'flexBasis',
|
|
319
|
+
'flexDirection',
|
|
320
|
+
'flexShrink',
|
|
321
|
+
'justifyContent',
|
|
322
|
+
'maxHeight',
|
|
323
|
+
'maxWidth',
|
|
324
|
+
'minHeight',
|
|
325
|
+
'minWidth',
|
|
326
|
+
'overflow',
|
|
327
|
+
'pointerEvents',
|
|
328
|
+
'position',
|
|
329
|
+
'textWrap',
|
|
330
|
+
])
|
|
331
|
+
|
|
275
332
|
const MotionView = createMotionView('div')
|
|
276
333
|
const MotionText = createMotionView('span')
|
|
277
334
|
|
|
@@ -329,8 +386,10 @@ function createMotionView(defaultTag: string) {
|
|
|
329
386
|
|
|
330
387
|
// we can definitely get rid of this here
|
|
331
388
|
if (out.viewProps.style) {
|
|
389
|
+
fixStyles(out.viewProps.style)
|
|
332
390
|
styleToCSS(out.viewProps.style)
|
|
333
391
|
}
|
|
392
|
+
|
|
334
393
|
return out.viewProps
|
|
335
394
|
}
|
|
336
395
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"mappings": "AAAA,cAEO,
|
|
2
|
+
"mappings": "AAAA,cAEO,uBAWA,eAAe;AAEtB,cAOO,uBACA,cAAc;KAMhB,kBAAkB;AASvB,OAAO,iBAAS,iBAAiB,UAAU,eAAe,kBACxDA,gBAAgB,IACf,gBAAgB",
|
|
3
3
|
"names": [
|
|
4
4
|
"animationsProp: A"
|
|
5
5
|
],
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"src/createAnimations.tsx"
|
|
8
8
|
],
|
|
9
9
|
"sourcesContent": [
|
|
10
|
-
"import {\n type AnimatedNumberStrategy,\n type AnimationDriver,\n type AnimationProp,\n getSplitStyles,\n hooks,\n styleToCSS,\n Text,\n type UniversalAnimatedNumber,\n useComposedRefs,\n useThemeWithState,\n View,\n} from '@tamagui/core'\nimport { PresenceContext, ResetPresence, usePresence } from '@tamagui/use-presence'\nimport {\n type AnimationOptions,\n type MotionValue,\n useAnimate,\n useMotionValue,\n useMotionValueEvent,\n type ValueTransition,\n} from 'motion/react'\nimport React, { forwardRef, useEffect, useLayoutEffect, useMemo, useRef } from 'react'\n\n// TODO: useAnimatedNumber style could avoid re-rendering\n\ntype MotionAnimatedNumber = MotionValue<number>\ntype AnimationConfig = ValueTransition\n\ntype MotionAnimatedNumberStyle = {\n getStyle: (cur: number) => Record<string, unknown>\n motionValue: MotionValue<number>\n}\n\nconst MotionValueStrategy = new WeakMap<MotionValue, AnimatedNumberStrategy>()\n\nexport function createAnimations<A extends Record<string, AnimationConfig>>(\n animationsProp: A\n): AnimationDriver<A> {\n // normalize, it doesn't assume type: 'spring' even if damping etc there so we do that\n // which also matches the moti driver\n // @ts-expect-error avoid doing a spread for no reason, sub-constraint type issue\n const animations: A = {}\n for (const key in animationsProp) {\n animations[key] = {\n type: 'spring',\n ...animationsProp[key],\n }\n }\n\n return {\n // this is only used by Sheet basically for now to pass result of useAnimatedStyle to\n View: MotionView,\n Text: MotionText,\n isReactNative: false,\n supportsCSSVars: true,\n needsWebStyles: true,\n avoidReRenders: true,\n animations,\n usePresence,\n ResetPresence,\n\n useAnimations: (animationProps) => {\n const { props, style, componentState, stateRef, useStyleEmitter } = animationProps\n\n const animationKey = Array.isArray(props.animation)\n ? props.animation[0]\n : props.animation\n\n const isHydrating = componentState.unmounted === true\n const disableAnimation = isHydrating || !animationKey\n const presenceContext = React.useContext(PresenceContext)\n\n const [scope, animate] = useAnimate()\n const firstRenderStyle = useRef<Object | null>(null)\n\n if (props.style) {\n styleToCSS(props.style) // ideally this would just come from tamagui\n }\n\n const { dontAnimate, doAnimate, animationOptions } = useMemo(() => {\n return getMotionAnimatedProps(props as any, style, disableAnimation)\n }, [presenceContext, animationKey, JSON.stringify(style)])\n\n function runAnimation(\n animationStyle: Record<string, unknown>,\n options: AnimationOptions\n ) {\n if (!(stateRef.current.host instanceof HTMLElement)) {\n return\n }\n\n if (!firstRenderStyle.current) {\n firstRenderStyle.current = animationStyle\n animate(stateRef.current.host, animationStyle, {\n duration: 0,\n type: 'tween',\n })\n return\n }\n\n animate(stateRef.current.host, animationStyle, animationOptions)\n }\n\n useStyleEmitter?.((nextStyle) => {\n const { doAnimate, animationOptions } = getMotionAnimatedProps(\n props as any,\n nextStyle,\n disableAnimation\n )\n if (doAnimate) {\n runAnimation(doAnimate, animationOptions)\n // Object.assign(dontAnimate, doAnimate)\n }\n })\n\n // strict mode correctness fix, idk why i thought it would clear a useRef\n // before running strict? if you remove this you'll see the next\n // useLayoutEffect re-run and animate due to firstRenderStyle.current\n // being set when in theory it should be clear\n useEffect(() => {\n return () => {\n firstRenderStyle.current = null\n }\n }, [])\n\n useLayoutEffect(() => {\n if (!doAnimate) return\n // debugger\n runAnimation(doAnimate, animationOptions)\n }, [doAnimate, firstRenderStyle])\n\n return {\n style: dontAnimate,\n ref: scope,\n tag: 'div',\n }\n },\n\n useAnimatedNumber(initial): UniversalAnimatedNumber<MotionAnimatedNumber> {\n const motionValue = useMotionValue(initial)\n\n return React.useMemo(\n () => ({\n getInstance() {\n return motionValue\n },\n getValue() {\n return motionValue.get()\n },\n setValue(next, config = { type: 'spring' }, onFinish) {\n if (config.type === 'direct') {\n MotionValueStrategy.set(motionValue, {\n type: 'direct',\n })\n motionValue.set(next)\n onFinish?.()\n } else {\n MotionValueStrategy.set(motionValue, config)\n\n if (onFinish) {\n const unsubscribe = motionValue.on('change', (value) => {\n if (Math.abs(value - next) < 0.01) {\n unsubscribe()\n onFinish()\n }\n })\n }\n\n motionValue.set(next)\n // Motion doesn't have a direct onFinish callback, so we simulate it\n }\n },\n stop() {\n motionValue.stop()\n },\n }),\n [motionValue]\n )\n },\n\n useAnimatedNumberReaction({ value }, onValue) {\n const instance = value.getInstance() as MotionValue<number>\n useMotionValueEvent(instance, 'change', onValue)\n },\n\n useAnimatedNumberStyle(val, getStyleProp) {\n const motionValue = val.getInstance() as MotionValue<number>\n const getStyleRef = useRef<typeof getStyleProp>(getStyleProp)\n\n // we need to change useAnimatedNumberStyle to have dep args to be concurrent safe\n getStyleRef.current = getStyleProp\n\n // never changes\n return useMemo(() => {\n return {\n getStyle: (cur) => {\n return getStyleRef.current(cur)\n },\n motionValue,\n } satisfies MotionAnimatedNumberStyle\n }, [])\n },\n }\n\n function getMotionAnimatedProps(\n props: { animation: AnimationProp | null; animateOnly?: string[] },\n style: Record<string, unknown>,\n disable = false\n ) {\n if (disable) {\n return {\n dontAnimate: style,\n doAnimate: null,\n }\n }\n\n const animationOptions = animationPropToAnimationConfig(props.animation)\n\n let dontAnimate = {}\n const doAnimate = {}\n\n const animateOnly = props.animateOnly as string[] | undefined\n for (const key in style) {\n const value = style[key]\n if (animateOnly && !animateOnly.includes(key)) {\n dontAnimate[key] = value\n } else {\n doAnimate[key] = value\n }\n }\n\n return {\n dontAnimate,\n doAnimate,\n animationOptions,\n }\n }\n\n function animationPropToAnimationConfig(\n animationProp: AnimationProp | null\n ): AnimationOptions {\n let defaultAnimationKey = ''\n let specificAnimations = {}\n\n if (typeof animationProp === 'string') {\n defaultAnimationKey = animationProp\n } else if (Array.isArray(animationProp)) {\n if (typeof animationProp[0] === 'string') {\n defaultAnimationKey = animationProp[0]\n specificAnimations = animationProp[1]\n } else {\n specificAnimations = animationProp\n }\n }\n\n if (!defaultAnimationKey) {\n return {}\n }\n\n return {\n default: animations[defaultAnimationKey],\n ...Object.fromEntries(\n Object.keys(specificAnimations).flatMap((key) => {\n if (animations[key]) {\n return [[key, animations[key]]]\n }\n return []\n })\n ),\n }\n }\n}\n\nconst MotionView = createMotionView('div')\nconst MotionText = createMotionView('span')\n\nfunction createMotionView(defaultTag: string) {\n // return forwardRef((props: any, ref) => {\n // console.log('rendering?', props)\n // const Element = motion[props.tag || defaultTag]\n // return <Element ref={ref} {...props} />\n // })\n const isText = defaultTag === 'span'\n\n const Component = forwardRef((propsIn: any, ref) => {\n const { forwardedRef, animation, tag = defaultTag, style, ...propsRest } = propsIn\n const [scope, animate] = useAnimate()\n const hostRef = useRef<HTMLElement>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref, hostRef, scope)\n\n const stateRef = useRef<any>(null)\n if (!stateRef.current) {\n stateRef.current = {\n get host() {\n return hostRef.current\n },\n }\n }\n\n const [_, state] = useThemeWithState({})\n\n const styles = Array.isArray(style) ? style : [style]\n\n // we can assume just one animatedStyle max for now\n const [animatedStyle, nonAnimatedStyles] = (() => {\n return [\n styles.find((x) => x.getStyle) as MotionAnimatedNumberStyle | undefined,\n styles.filter((x) => !x.getStyle),\n ] as const\n })()\n\n function getProps(props: any) {\n const out = getSplitStyles(\n props,\n isText ? Text.staticConfig : View.staticConfig,\n state?.theme!,\n state?.name!,\n {\n unmounted: false,\n },\n {\n isAnimated: false,\n noClass: true,\n // noMergeStyle: true,\n resolveValues: 'auto',\n }\n )\n\n // we can definitely get rid of this here\n if (out.viewProps.style) {\n styleToCSS(out.viewProps.style)\n }\n return out.viewProps\n }\n\n const props = getProps({ ...propsRest, style: nonAnimatedStyles })\n const Element = tag || 'div'\n const transformedProps = hooks.usePropsTransform?.(tag, props, stateRef, false)\n\n useEffect(() => {\n if (!animatedStyle) return\n\n return animatedStyle.motionValue.on('change', (value) => {\n const nextStyle = animatedStyle.getStyle(value)\n const animationConfig = MotionValueStrategy.get(animatedStyle.motionValue)\n const node = hostRef.current\n\n const webStyle = getProps({ style: nextStyle }).style\n\n if (webStyle && node instanceof HTMLElement) {\n const motionAnimationConfig =\n animationConfig?.type === 'timing'\n ? {\n type: 'tween',\n duration: (animationConfig?.duration || 0) / 1000,\n }\n : animationConfig?.type === 'direct'\n ? { type: 'tween', duration: 0 }\n : {\n type: 'spring',\n ...(animationConfig as any),\n }\n\n animate(node, webStyle as any, motionAnimationConfig)\n }\n })\n }, [animatedStyle])\n\n return <Element {...transformedProps} ref={composedRefs} />\n })\n\n Component['acceptTagProp'] = true\n\n return Component\n}\n"
|
|
10
|
+
"import {\n type AnimatedNumberStrategy,\n type AnimationDriver,\n type AnimationProp,\n fixStyles,\n getSplitStyles,\n hooks,\n styleToCSS,\n Text,\n type UniversalAnimatedNumber,\n useComposedRefs,\n useThemeWithState,\n View,\n} from '@tamagui/core'\nimport { PresenceContext, ResetPresence, usePresence } from '@tamagui/use-presence'\nimport {\n type AnimationOptions,\n type AnimationPlaybackControlsWithThen,\n type MotionValue,\n useAnimate,\n useMotionValue,\n useMotionValueEvent,\n type ValueTransition,\n} from 'motion/react'\nimport React, { forwardRef, useEffect, useLayoutEffect, useMemo, useRef } from 'react'\n\n// TODO: useAnimatedNumber style could avoid re-rendering\n\ntype MotionAnimatedNumber = MotionValue<number>\ntype AnimationConfig = ValueTransition\n\ntype MotionAnimatedNumberStyle = {\n getStyle: (cur: number) => Record<string, unknown>\n motionValue: MotionValue<number>\n}\n\nconst MotionValueStrategy = new WeakMap<MotionValue, AnimatedNumberStrategy>()\n\nexport function createAnimations<A extends Record<string, AnimationConfig>>(\n animationsProp: A\n): AnimationDriver<A> {\n // normalize, it doesn't assume type: 'spring' even if damping etc there so we do that\n // which also matches the moti driver\n // @ts-expect-error avoid doing a spread for no reason, sub-constraint type issue\n const animations: A = {}\n for (const key in animationsProp) {\n animations[key] = {\n type: 'spring',\n ...animationsProp[key],\n }\n }\n\n return {\n // this is only used by Sheet basically for now to pass result of useAnimatedStyle to\n View: MotionView,\n Text: MotionText,\n isReactNative: false,\n supportsCSSVars: true,\n needsWebStyles: true,\n avoidReRenders: true,\n animations,\n usePresence,\n ResetPresence,\n\n useAnimations: (animationProps) => {\n const { props, style, componentState, stateRef, useStyleEmitter } = animationProps\n\n const animationKey = Array.isArray(props.animation)\n ? props.animation[0]\n : props.animation\n\n const isHydrating = componentState.unmounted === true\n const disableAnimation = isHydrating || !animationKey\n const presenceContext = React.useContext(PresenceContext)\n\n const [scope, animate] = useAnimate()\n const lastAnimationStyle = useRef<Object | null>(null)\n const controls = useRef<AnimationPlaybackControlsWithThen | null>(null)\n const styleKey = JSON.stringify(style)\n\n const { dontAnimate, doAnimate, animationOptions } = useMemo(() => {\n const motionAnimationState = getMotionAnimatedProps(\n props as any,\n style,\n disableAnimation\n )\n return motionAnimationState\n }, [presenceContext, animationKey, styleKey])\n\n // const id = useId()\n\n const runAnimation = (\n animationStyle: Record<string, unknown> | null,\n animationOptions: AnimationOptions | undefined\n ) => {\n if (!animationStyle) return\n if (!(stateRef.current.host instanceof HTMLElement)) {\n return\n }\n\n // ideally this would just come from tamagui\n fixStyles(animationStyle)\n styleToCSS(animationStyle)\n\n if (!lastAnimationStyle.current) {\n // console.log('first', id, animationStyle)\n lastAnimationStyle.current = animationStyle\n controls.current = animate(scope.current, animationStyle, {\n duration: 0,\n type: 'tween',\n })\n controls.current.complete()\n return\n }\n\n const diff = {}\n for (const key in animationStyle) {\n if (animationStyle[key] !== lastAnimationStyle.current[key]) {\n diff[key] = animationStyle[key]\n }\n }\n\n // console.log('animate', id, diff)\n controls.current = animate(scope.current, diff, animationOptions)\n lastAnimationStyle.current = animationStyle\n }\n\n useStyleEmitter?.((nextStyle) => {\n const { doAnimate, animationOptions } = getMotionAnimatedProps(\n props as any,\n nextStyle,\n disableAnimation\n )\n runAnimation(doAnimate, animationOptions)\n })\n\n // strict mode correctness fix, idk why i thought it would clear a useRef\n // before running strict? if you remove this you'll see the next\n // useLayoutEffect re-run and animate due to lastAnimationStyle.current\n // being set when in theory it should be clear\n useEffect(() => {\n return () => {\n lastAnimationStyle.current = null\n }\n }, [])\n\n useLayoutEffect(() => {\n if (!doAnimate) return\n runAnimation(doAnimate, animationOptions)\n }, [JSON.stringify(doAnimate), lastAnimationStyle])\n\n if (\n process.env.NODE_ENV === 'development' &&\n props['debug'] &&\n props['debug'] !== 'profile'\n ) {\n console.info(`[animations-motion](`, JSON.stringify(doAnimate, null, 2) + ')', {\n doAnimate,\n dontAnimate,\n animationOptions,\n props,\n })\n }\n\n // console.log('render', id, scope)\n\n return {\n style: dontAnimate,\n ref: scope,\n tag: 'div',\n }\n },\n\n useAnimatedNumber(initial): UniversalAnimatedNumber<MotionAnimatedNumber> {\n const motionValue = useMotionValue(initial)\n\n return React.useMemo(\n () => ({\n getInstance() {\n return motionValue\n },\n getValue() {\n return motionValue.get()\n },\n setValue(next, config = { type: 'spring' }, onFinish) {\n if (config.type === 'direct') {\n MotionValueStrategy.set(motionValue, {\n type: 'direct',\n })\n motionValue.set(next)\n onFinish?.()\n } else {\n MotionValueStrategy.set(motionValue, config)\n\n if (onFinish) {\n const unsubscribe = motionValue.on('change', (value) => {\n if (Math.abs(value - next) < 0.01) {\n unsubscribe()\n onFinish()\n }\n })\n }\n\n motionValue.set(next)\n // Motion doesn't have a direct onFinish callback, so we simulate it\n }\n },\n stop() {\n motionValue.stop()\n },\n }),\n [motionValue]\n )\n },\n\n useAnimatedNumberReaction({ value }, onValue) {\n const instance = value.getInstance() as MotionValue<number>\n useMotionValueEvent(instance, 'change', onValue)\n },\n\n useAnimatedNumberStyle(val, getStyleProp) {\n const motionValue = val.getInstance() as MotionValue<number>\n const getStyleRef = useRef<typeof getStyleProp>(getStyleProp)\n\n // we need to change useAnimatedNumberStyle to have dep args to be concurrent safe\n getStyleRef.current = getStyleProp\n\n // never changes\n return useMemo(() => {\n return {\n getStyle: (cur) => {\n return getStyleRef.current(cur)\n },\n motionValue,\n } satisfies MotionAnimatedNumberStyle\n }, [])\n },\n }\n\n function getMotionAnimatedProps(\n props: { animation: AnimationProp | null; animateOnly?: string[] },\n style: Record<string, unknown>,\n disable = false\n ) {\n if (disable) {\n return {\n dontAnimate: style,\n doAnimate: null,\n }\n }\n\n const animationOptions = animationPropToAnimationConfig(props.animation)\n\n let dontAnimate = {}\n let doAnimate: Record<string, unknown> | null = null\n\n const animateOnly = props.animateOnly as string[] | undefined\n for (const key in style) {\n const value = style[key]\n if (disableAnimationProps.has(key) || (animateOnly && !animateOnly.includes(key))) {\n dontAnimate[key] = value\n } else {\n doAnimate ||= {}\n doAnimate[key] = value\n }\n }\n\n return {\n dontAnimate,\n doAnimate,\n animationOptions,\n }\n }\n\n function animationPropToAnimationConfig(\n animationProp: AnimationProp | null\n ): AnimationOptions {\n let defaultAnimationKey = ''\n let specificAnimations = {}\n\n if (typeof animationProp === 'string') {\n defaultAnimationKey = animationProp\n } else if (Array.isArray(animationProp)) {\n if (typeof animationProp[0] === 'string') {\n defaultAnimationKey = animationProp[0]\n specificAnimations = animationProp[1]\n } else {\n specificAnimations = animationProp\n }\n }\n\n if (!defaultAnimationKey) {\n return {}\n }\n\n return {\n default: animations[defaultAnimationKey],\n ...Object.fromEntries(\n Object.keys(specificAnimations).flatMap((key) => {\n if (animations[key]) {\n return [[key, animations[key]]]\n }\n return []\n })\n ),\n }\n }\n}\n\n// sort of temporary\nconst disableAnimationProps = new Set<string>([\n 'alignContent',\n 'alignItems',\n 'backdropFilter',\n 'boxSizing',\n 'contain',\n 'display',\n 'flexBasis',\n 'flexDirection',\n 'flexShrink',\n 'justifyContent',\n 'maxHeight',\n 'maxWidth',\n 'minHeight',\n 'minWidth',\n 'overflow',\n 'pointerEvents',\n 'position',\n 'textWrap',\n])\n\nconst MotionView = createMotionView('div')\nconst MotionText = createMotionView('span')\n\nfunction createMotionView(defaultTag: string) {\n // return forwardRef((props: any, ref) => {\n // console.log('rendering?', props)\n // const Element = motion[props.tag || defaultTag]\n // return <Element ref={ref} {...props} />\n // })\n const isText = defaultTag === 'span'\n\n const Component = forwardRef((propsIn: any, ref) => {\n const { forwardedRef, animation, tag = defaultTag, style, ...propsRest } = propsIn\n const [scope, animate] = useAnimate()\n const hostRef = useRef<HTMLElement>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref, hostRef, scope)\n\n const stateRef = useRef<any>(null)\n if (!stateRef.current) {\n stateRef.current = {\n get host() {\n return hostRef.current\n },\n }\n }\n\n const [_, state] = useThemeWithState({})\n\n const styles = Array.isArray(style) ? style : [style]\n\n // we can assume just one animatedStyle max for now\n const [animatedStyle, nonAnimatedStyles] = (() => {\n return [\n styles.find((x) => x.getStyle) as MotionAnimatedNumberStyle | undefined,\n styles.filter((x) => !x.getStyle),\n ] as const\n })()\n\n function getProps(props: any) {\n const out = getSplitStyles(\n props,\n isText ? Text.staticConfig : View.staticConfig,\n state?.theme!,\n state?.name!,\n {\n unmounted: false,\n },\n {\n isAnimated: false,\n noClass: true,\n // noMergeStyle: true,\n resolveValues: 'auto',\n }\n )\n\n // we can definitely get rid of this here\n if (out.viewProps.style) {\n fixStyles(out.viewProps.style)\n styleToCSS(out.viewProps.style)\n }\n\n return out.viewProps\n }\n\n const props = getProps({ ...propsRest, style: nonAnimatedStyles })\n const Element = tag || 'div'\n const transformedProps = hooks.usePropsTransform?.(tag, props, stateRef, false)\n\n useEffect(() => {\n if (!animatedStyle) return\n\n return animatedStyle.motionValue.on('change', (value) => {\n const nextStyle = animatedStyle.getStyle(value)\n const animationConfig = MotionValueStrategy.get(animatedStyle.motionValue)\n const node = hostRef.current\n\n const webStyle = getProps({ style: nextStyle }).style\n\n if (webStyle && node instanceof HTMLElement) {\n const motionAnimationConfig =\n animationConfig?.type === 'timing'\n ? {\n type: 'tween',\n duration: (animationConfig?.duration || 0) / 1000,\n }\n : animationConfig?.type === 'direct'\n ? { type: 'tween', duration: 0 }\n : {\n type: 'spring',\n ...(animationConfig as any),\n }\n\n animate(node, webStyle as any, motionAnimationConfig)\n }\n })\n }, [animatedStyle])\n\n return <Element {...transformedProps} ref={composedRefs} />\n })\n\n Component['acceptTagProp'] = true\n\n return Component\n}\n"
|
|
11
11
|
],
|
|
12
12
|
"version": 3
|
|
13
13
|
}
|