@tamagui/animations-moti 2.0.0-rc.9 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/createAnimations.cjs +224 -172
- package/dist/cjs/createAnimations.native.js +227 -189
- package/dist/cjs/createAnimations.native.js.map +1 -1
- package/dist/cjs/index.cjs +7 -5
- package/dist/cjs/index.native.js +7 -5
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/polyfill.cjs +6 -2
- package/dist/cjs/polyfill.native.js +6 -2
- package/dist/cjs/polyfill.native.js.map +1 -1
- package/dist/esm/createAnimations.mjs +194 -144
- package/dist/esm/createAnimations.mjs.map +1 -1
- package/dist/esm/createAnimations.native.js +197 -161
- package/dist/esm/createAnimations.native.js.map +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.js.map +1 -6
- package/dist/esm/index.mjs +0 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +0 -1
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/polyfill.mjs +6 -2
- package/dist/esm/polyfill.mjs.map +1 -1
- package/dist/esm/polyfill.native.js +6 -2
- package/dist/esm/polyfill.native.js.map +1 -1
- package/package.json +9 -9
- package/src/createAnimations.tsx +2 -2
- package/types/createAnimations.d.ts.map +3 -3
- package/types/index.d.ts.map +2 -2
- package/types/polyfill.d.ts.map +2 -2
- package/dist/cjs/createAnimations.js +0 -220
- package/dist/cjs/createAnimations.js.map +0 -6
- package/dist/cjs/index.js +0 -16
- package/dist/cjs/index.js.map +0 -6
- package/dist/cjs/polyfill.js +0 -3
- package/dist/cjs/polyfill.js.map +0 -6
- package/dist/esm/createAnimations.js +0 -218
- package/dist/esm/createAnimations.js.map +0 -6
- package/dist/esm/polyfill.js +0 -3
- package/dist/esm/polyfill.js.map +0 -6
|
@@ -2,123 +2,136 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
32
34
|
var createAnimations_exports = {};
|
|
33
35
|
__export(createAnimations_exports, {
|
|
34
36
|
createAnimations: () => createAnimations
|
|
35
37
|
});
|
|
36
38
|
module.exports = __toCommonJS(createAnimations_exports);
|
|
37
|
-
var import_use_presence = require("@tamagui/use-presence")
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const resolveDynamicValue = (value, isDark) =>
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
|
|
39
|
+
var import_use_presence = require("@tamagui/use-presence");
|
|
40
|
+
var import_core = require("@tamagui/core");
|
|
41
|
+
var import_author = require("moti/author");
|
|
42
|
+
var import_react = __toESM(require("react"), 1);
|
|
43
|
+
var import_react_native_reanimated = __toESM(require("react-native-reanimated"), 1);
|
|
44
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
45
|
+
const resolveDynamicValue = (value, isDark) => {
|
|
46
|
+
if (value && typeof value === "object" && "dynamic" in value) {
|
|
47
|
+
const dynamicValue = isDark ? value.dynamic.dark : value.dynamic.light;
|
|
48
|
+
return dynamicValue;
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
};
|
|
52
|
+
const safeESModule = a => {
|
|
53
|
+
const b = a;
|
|
54
|
+
const out = b.__esModule || b[Symbol.toStringTag] === "Module" ? b.default : b;
|
|
55
|
+
return out || a;
|
|
56
|
+
};
|
|
57
|
+
const Animated = safeESModule(import_react_native_reanimated.default);
|
|
49
58
|
function createTamaguiAnimatedComponent(defaultTag = "div") {
|
|
50
|
-
const isText = defaultTag === "span"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
const isText = defaultTag === "span";
|
|
60
|
+
const Component = Animated.createAnimatedComponent((0, import_react.forwardRef)((propsIn, ref) => {
|
|
61
|
+
const {
|
|
62
|
+
forwardedRef,
|
|
63
|
+
animation,
|
|
64
|
+
render = defaultTag,
|
|
65
|
+
...propsRest
|
|
66
|
+
} = propsIn;
|
|
67
|
+
const hostRef = (0, import_react.useRef)(null);
|
|
68
|
+
const composedRefs = (0, import_core.useComposedRefs)(forwardedRef, ref, hostRef);
|
|
69
|
+
const stateRef = (0, import_react.useRef)(null);
|
|
70
|
+
if (!stateRef.current) {
|
|
71
|
+
stateRef.current = {
|
|
62
72
|
get host() {
|
|
63
73
|
return hostRef.current;
|
|
64
74
|
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const [_, state] = (0, import_core.useThemeWithState)({});
|
|
78
|
+
const result = (0, import_core.getSplitStyles)(propsRest, isText ? import_core.Text.staticConfig : import_core.View.staticConfig, state?.theme, state?.name, {
|
|
79
|
+
unmounted: false
|
|
80
|
+
}, {
|
|
81
|
+
isAnimated: false,
|
|
82
|
+
noClass: true
|
|
83
|
+
});
|
|
84
|
+
const props = result?.viewProps || {};
|
|
85
|
+
const Element = render;
|
|
86
|
+
const transformedProps = import_core.hooks.usePropsTransform?.(render, props, stateRef, false);
|
|
87
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Element, {
|
|
88
|
+
...transformedProps,
|
|
89
|
+
ref: composedRefs
|
|
90
|
+
});
|
|
91
|
+
}));
|
|
92
|
+
Component["acceptRenderProp"] = true;
|
|
93
|
+
return Component;
|
|
81
94
|
}
|
|
82
|
-
const AnimatedView = createTamaguiAnimatedComponent("div")
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
95
|
+
const AnimatedView = createTamaguiAnimatedComponent("div");
|
|
96
|
+
const AnimatedText = createTamaguiAnimatedComponent("span");
|
|
97
|
+
const onlyAnimateKeys = {
|
|
98
|
+
transform: true,
|
|
99
|
+
opacity: true,
|
|
100
|
+
height: true,
|
|
101
|
+
width: true,
|
|
102
|
+
backgroundColor: true,
|
|
103
|
+
borderColor: true,
|
|
104
|
+
borderLeftColor: true,
|
|
105
|
+
borderRightColor: true,
|
|
106
|
+
borderTopColor: true,
|
|
107
|
+
borderBottomColor: true,
|
|
108
|
+
borderRadius: true,
|
|
109
|
+
borderTopLeftRadius: true,
|
|
110
|
+
borderTopRightRadius: true,
|
|
111
|
+
borderBottomLeftRadius: true,
|
|
112
|
+
borderBottomRightRadius: true,
|
|
113
|
+
borderLeftWidth: true,
|
|
114
|
+
borderRightWidth: true,
|
|
115
|
+
borderTopWidth: true,
|
|
116
|
+
borderBottomWidth: true,
|
|
117
|
+
color: true,
|
|
118
|
+
left: true,
|
|
119
|
+
right: true,
|
|
120
|
+
top: true,
|
|
121
|
+
bottom: true,
|
|
122
|
+
fontSize: true,
|
|
123
|
+
fontWeight: true,
|
|
124
|
+
lineHeight: true,
|
|
125
|
+
letterSpacing: true
|
|
126
|
+
};
|
|
114
127
|
function createAnimations(animations) {
|
|
115
128
|
return {
|
|
129
|
+
needsCustomComponent: true,
|
|
116
130
|
View: import_core.isWeb ? AnimatedView : Animated.View,
|
|
117
131
|
Text: import_core.isWeb ? AnimatedText : Animated.Text,
|
|
118
132
|
// View: Animated.View,
|
|
119
133
|
// Text: Animated.Text,
|
|
120
|
-
isReactNative:
|
|
121
|
-
supportsCSS: !1,
|
|
134
|
+
isReactNative: true,
|
|
122
135
|
inputStyle: "value",
|
|
123
136
|
outputStyle: "inline",
|
|
124
137
|
animations,
|
|
@@ -142,15 +155,22 @@ function createAnimations(animations) {
|
|
|
142
155
|
}, onFinish) {
|
|
143
156
|
"worklet";
|
|
144
157
|
|
|
145
|
-
|
|
146
|
-
|
|
158
|
+
if (config.type === "direct") {
|
|
159
|
+
sharedValue.value = next;
|
|
160
|
+
onFinish?.();
|
|
161
|
+
} else if (config.type === "spring") {
|
|
162
|
+
sharedValue.value = (0, import_react_native_reanimated.withSpring)(next, config, onFinish ? () => {
|
|
163
|
+
"worklet";
|
|
147
164
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
165
|
+
(0, import_react_native_reanimated.runOnJS)(onFinish)();
|
|
166
|
+
} : void 0);
|
|
167
|
+
} else {
|
|
168
|
+
sharedValue.value = (0, import_react_native_reanimated.withTiming)(next, config, onFinish ? () => {
|
|
169
|
+
"worklet";
|
|
151
170
|
|
|
152
|
-
|
|
153
|
-
|
|
171
|
+
(0, import_react_native_reanimated.runOnJS)(onFinish)();
|
|
172
|
+
} : void 0);
|
|
173
|
+
}
|
|
154
174
|
},
|
|
155
175
|
stop() {
|
|
156
176
|
"worklet";
|
|
@@ -163,8 +183,12 @@ function createAnimations(animations) {
|
|
|
163
183
|
value
|
|
164
184
|
}, onValue) {
|
|
165
185
|
const instance = value.getInstance();
|
|
166
|
-
return (0, import_react_native_reanimated.useAnimatedReaction)(() =>
|
|
167
|
-
|
|
186
|
+
return (0, import_react_native_reanimated.useAnimatedReaction)(() => {
|
|
187
|
+
return instance.value;
|
|
188
|
+
}, (next, prev) => {
|
|
189
|
+
if (prev !== next) {
|
|
190
|
+
(0, import_react_native_reanimated.runOnJS)(onValue)(next);
|
|
191
|
+
}
|
|
168
192
|
},
|
|
169
193
|
// dependency array is very important here
|
|
170
194
|
[onValue, instance]);
|
|
@@ -173,82 +197,110 @@ function createAnimations(animations) {
|
|
|
173
197
|
* `getStyle` must be a worklet
|
|
174
198
|
*/
|
|
175
199
|
useAnimatedNumberStyle(val, getStyle) {
|
|
176
|
-
const instance = val.getInstance()
|
|
177
|
-
|
|
178
|
-
|
|
200
|
+
const instance = val.getInstance();
|
|
201
|
+
const derivedValue = (0, import_react_native_reanimated.useDerivedValue)(() => {
|
|
202
|
+
return instance.value;
|
|
203
|
+
}, [instance, getStyle]);
|
|
204
|
+
return (0, import_react_native_reanimated.useAnimatedStyle)(() => {
|
|
205
|
+
return getStyle(derivedValue.value);
|
|
206
|
+
}, [val, getStyle, derivedValue, instance]);
|
|
179
207
|
},
|
|
180
208
|
useAnimations: animationProps => {
|
|
181
209
|
const {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
value
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
210
|
+
props,
|
|
211
|
+
presence,
|
|
212
|
+
style,
|
|
213
|
+
componentState
|
|
214
|
+
} = animationProps;
|
|
215
|
+
const animationKey = Array.isArray(props.transition) ? props.transition[0] : props.transition;
|
|
216
|
+
const isHydrating = componentState.unmounted === true;
|
|
217
|
+
const disableAnimation = isHydrating || !animationKey;
|
|
218
|
+
const presenceContext = import_react.default.useContext(import_use_presence.PresenceContext);
|
|
219
|
+
const [, themeState] = (0, import_core.useThemeWithState)({});
|
|
220
|
+
const isDark = themeState?.scheme === "dark" || themeState?.name?.startsWith("dark");
|
|
221
|
+
const {
|
|
222
|
+
dontAnimate,
|
|
223
|
+
motiProps
|
|
224
|
+
} = (0, import_react.useMemo)(() => {
|
|
225
|
+
let animate = {};
|
|
226
|
+
let dontAnimate2 = {};
|
|
227
|
+
if (disableAnimation) {
|
|
228
|
+
for (const key in style) {
|
|
229
|
+
const rawValue = style[key];
|
|
230
|
+
const value = resolveDynamicValue(rawValue, isDark);
|
|
231
|
+
if (value === void 0) continue;
|
|
232
|
+
dontAnimate2[key] = value;
|
|
233
|
+
}
|
|
234
|
+
} else {
|
|
235
|
+
const animateOnly = props.animateOnly;
|
|
236
|
+
for (const key in style) {
|
|
237
|
+
const rawValue = style[key];
|
|
238
|
+
const value = resolveDynamicValue(rawValue, isDark);
|
|
239
|
+
if (value === void 0) continue;
|
|
240
|
+
if (!onlyAnimateKeys[key] || value === "auto" || typeof value === "string" && value.startsWith("calc") || animateOnly && !animateOnly.includes(key)) {
|
|
241
|
+
dontAnimate2[key] = value;
|
|
242
|
+
} else {
|
|
243
|
+
animate[key] = value;
|
|
209
244
|
}
|
|
210
245
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
246
|
+
}
|
|
247
|
+
if (componentState.unmounted === "should-enter") {
|
|
248
|
+
for (const key in style) {
|
|
249
|
+
const rawValue = style[key];
|
|
250
|
+
const value = resolveDynamicValue(rawValue, isDark);
|
|
251
|
+
if (value === void 0) continue;
|
|
252
|
+
dontAnimate2[key] = value;
|
|
215
253
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
254
|
+
}
|
|
255
|
+
const styles = animate;
|
|
256
|
+
const isExiting = Boolean(presence?.[1]);
|
|
257
|
+
const usePresenceValue = presence || void 0;
|
|
258
|
+
let transition = isHydrating ? {
|
|
259
|
+
type: "transition",
|
|
260
|
+
duration: 0
|
|
261
|
+
} : animations[animationKey];
|
|
262
|
+
let hasClonedTransition = false;
|
|
263
|
+
if (Array.isArray(props.transition)) {
|
|
264
|
+
const config = props.transition[1];
|
|
265
|
+
if (config && typeof config === "object") {
|
|
266
|
+
for (const key in config) {
|
|
227
267
|
const val = config[key];
|
|
228
|
-
|
|
268
|
+
if (!hasClonedTransition) {
|
|
269
|
+
transition = Object.assign({}, transition);
|
|
270
|
+
hasClonedTransition = true;
|
|
271
|
+
}
|
|
272
|
+
if (typeof val === "string") {
|
|
273
|
+
transition[key] = animations[val];
|
|
274
|
+
} else {
|
|
275
|
+
transition[key] = val;
|
|
276
|
+
}
|
|
229
277
|
}
|
|
230
278
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
279
|
+
}
|
|
280
|
+
return {
|
|
281
|
+
dontAnimate: dontAnimate2,
|
|
282
|
+
motiProps: {
|
|
283
|
+
animate: isExiting || componentState.unmounted === true ? {} : styles,
|
|
284
|
+
transition: componentState.unmounted ? {
|
|
285
|
+
duration: 0
|
|
286
|
+
} : transition,
|
|
287
|
+
usePresenceValue,
|
|
288
|
+
presenceContext,
|
|
289
|
+
exit: isExiting ? styles : void 0
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
}, [presenceContext, presence, animationKey, componentState.unmounted, JSON.stringify(style), presenceContext, isDark]);
|
|
293
|
+
const moti = (0, import_author.useMotify)(motiProps);
|
|
294
|
+
if (process.env.NODE_ENV === "development" && props["debug"] && props["debug"] !== "profile") {
|
|
295
|
+
console.info(`useMotify(`, JSON.stringify(motiProps, null, 2) + ")", {
|
|
296
|
+
"componentState.unmounted": componentState.unmounted,
|
|
297
|
+
animationProps,
|
|
298
|
+
motiProps,
|
|
299
|
+
moti,
|
|
300
|
+
style: [dontAnimate, moti.style]
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
return {
|
|
252
304
|
style: [dontAnimate, moti.style]
|
|
253
305
|
};
|
|
254
306
|
}
|