@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.
Files changed (38) hide show
  1. package/dist/cjs/createAnimations.cjs +224 -172
  2. package/dist/cjs/createAnimations.native.js +227 -189
  3. package/dist/cjs/createAnimations.native.js.map +1 -1
  4. package/dist/cjs/index.cjs +7 -5
  5. package/dist/cjs/index.native.js +7 -5
  6. package/dist/cjs/index.native.js.map +1 -1
  7. package/dist/cjs/polyfill.cjs +6 -2
  8. package/dist/cjs/polyfill.native.js +6 -2
  9. package/dist/cjs/polyfill.native.js.map +1 -1
  10. package/dist/esm/createAnimations.mjs +194 -144
  11. package/dist/esm/createAnimations.mjs.map +1 -1
  12. package/dist/esm/createAnimations.native.js +197 -161
  13. package/dist/esm/createAnimations.native.js.map +1 -1
  14. package/dist/esm/index.js +1 -2
  15. package/dist/esm/index.js.map +1 -6
  16. package/dist/esm/index.mjs +0 -1
  17. package/dist/esm/index.mjs.map +1 -1
  18. package/dist/esm/index.native.js +0 -1
  19. package/dist/esm/index.native.js.map +1 -1
  20. package/dist/esm/polyfill.mjs +6 -2
  21. package/dist/esm/polyfill.mjs.map +1 -1
  22. package/dist/esm/polyfill.native.js +6 -2
  23. package/dist/esm/polyfill.native.js.map +1 -1
  24. package/package.json +9 -9
  25. package/src/createAnimations.tsx +2 -2
  26. package/types/createAnimations.d.ts.map +3 -3
  27. package/types/index.d.ts.map +2 -2
  28. package/types/polyfill.d.ts.map +2 -2
  29. package/dist/cjs/createAnimations.js +0 -220
  30. package/dist/cjs/createAnimations.js.map +0 -6
  31. package/dist/cjs/index.js +0 -16
  32. package/dist/cjs/index.js.map +0 -6
  33. package/dist/cjs/polyfill.js +0 -3
  34. package/dist/cjs/polyfill.js.map +0 -6
  35. package/dist/esm/createAnimations.js +0 -218
  36. package/dist/esm/createAnimations.js.map +0 -6
  37. package/dist/esm/polyfill.js +0 -3
  38. 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
- __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: !0
11
- });
12
- },
13
- __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
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
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
- value: mod,
27
- enumerable: !0
28
- }) : target, mod)),
29
- __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
- value: !0
31
- }), mod);
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
- import_core = require("@tamagui/core"),
39
- import_author = require("moti/author"),
40
- import_react = __toESM(require("react"), 1),
41
- import_react_native_reanimated = __toESM(require("react-native-reanimated"), 1),
42
- import_jsx_runtime = require("react/jsx-runtime");
43
- const resolveDynamicValue = (value, isDark) => value && typeof value == "object" && "dynamic" in value ? isDark ? value.dynamic.dark : value.dynamic.light : value,
44
- safeESModule = a => {
45
- const b = a;
46
- return (b.__esModule || b[Symbol.toStringTag] === "Module" ? b.default : b) || a;
47
- },
48
- Animated = safeESModule(import_react_native_reanimated.default);
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
- Component = Animated.createAnimatedComponent((0, import_react.forwardRef)((propsIn, ref) => {
52
- const {
53
- forwardedRef,
54
- animation,
55
- render = defaultTag,
56
- ...propsRest
57
- } = propsIn,
58
- hostRef = (0, import_react.useRef)(null),
59
- composedRefs = (0, import_core.useComposedRefs)(forwardedRef, ref, hostRef),
60
- stateRef = (0, import_react.useRef)(null);
61
- stateRef.current || (stateRef.current = {
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
- const [_, state] = (0, import_core.useThemeWithState)({}),
67
- props = (0, import_core.getSplitStyles)(propsRest, isText ? import_core.Text.staticConfig : import_core.View.staticConfig, state?.theme, state?.name, {
68
- unmounted: !1
69
- }, {
70
- isAnimated: !1,
71
- noClass: !0
72
- })?.viewProps || {},
73
- Element = render,
74
- transformedProps = import_core.hooks.usePropsTransform?.(render, props, stateRef, !1);
75
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Element, {
76
- ...transformedProps,
77
- ref: composedRefs
78
- });
79
- }));
80
- return Component.acceptTagProp = !0, Component;
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
- AnimatedText = createTamaguiAnimatedComponent("span"),
84
- onlyAnimateKeys = {
85
- transform: !0,
86
- opacity: !0,
87
- height: !0,
88
- width: !0,
89
- backgroundColor: !0,
90
- borderColor: !0,
91
- borderLeftColor: !0,
92
- borderRightColor: !0,
93
- borderTopColor: !0,
94
- borderBottomColor: !0,
95
- borderRadius: !0,
96
- borderTopLeftRadius: !0,
97
- borderTopRightRadius: !0,
98
- borderBottomLeftRadius: !0,
99
- borderBottomRightRadius: !0,
100
- borderLeftWidth: !0,
101
- borderRightWidth: !0,
102
- borderTopWidth: !0,
103
- borderBottomWidth: !0,
104
- color: !0,
105
- left: !0,
106
- right: !0,
107
- top: !0,
108
- bottom: !0,
109
- fontSize: !0,
110
- fontWeight: !0,
111
- lineHeight: !0,
112
- letterSpacing: !0
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: !0,
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
- config.type === "direct" ? (sharedValue.value = next, onFinish?.()) : config.type === "spring" ? sharedValue.value = (0, import_react_native_reanimated.withSpring)(next, config, onFinish ? () => {
146
- "worklet";
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
- (0, import_react_native_reanimated.runOnJS)(onFinish)();
149
- } : void 0) : sharedValue.value = (0, import_react_native_reanimated.withTiming)(next, config, onFinish ? () => {
150
- "worklet";
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
- (0, import_react_native_reanimated.runOnJS)(onFinish)();
153
- } : void 0);
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)(() => instance.value, (next, prev) => {
167
- prev !== next && (0, import_react_native_reanimated.runOnJS)(onValue)(next);
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
- derivedValue = (0, import_react_native_reanimated.useDerivedValue)(() => instance.value, [instance, getStyle]);
178
- return (0, import_react_native_reanimated.useAnimatedStyle)(() => getStyle(derivedValue.value), [val, getStyle, derivedValue, instance]);
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
- props,
183
- presence,
184
- style,
185
- componentState
186
- } = animationProps,
187
- animationKey = Array.isArray(props.transition) ? props.transition[0] : props.transition,
188
- isHydrating = componentState.unmounted === !0,
189
- disableAnimation = isHydrating || !animationKey,
190
- presenceContext = import_react.default.useContext(import_use_presence.PresenceContext),
191
- [, themeState] = (0, import_core.useThemeWithState)({}),
192
- isDark = themeState?.scheme === "dark" || themeState?.name?.startsWith("dark"),
193
- {
194
- dontAnimate,
195
- motiProps
196
- } = (0, import_react.useMemo)(() => {
197
- let animate = {},
198
- dontAnimate2 = {};
199
- if (disableAnimation) for (const key in style) {
200
- const rawValue = style[key],
201
- value = resolveDynamicValue(rawValue, isDark);
202
- value !== void 0 && (dontAnimate2[key] = value);
203
- } else {
204
- const animateOnly = props.animateOnly;
205
- for (const key in style) {
206
- const rawValue = style[key],
207
- value = resolveDynamicValue(rawValue, isDark);
208
- value !== void 0 && (!onlyAnimateKeys[key] || value === "auto" || typeof value == "string" && value.startsWith("calc") || animateOnly && !animateOnly.includes(key) ? dontAnimate2[key] = value : animate[key] = value);
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
- if (componentState.unmounted === "should-enter") for (const key in style) {
212
- const rawValue = style[key],
213
- value = resolveDynamicValue(rawValue, isDark);
214
- value !== void 0 && (dontAnimate2[key] = value);
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
- const styles = animate,
217
- isExiting = !!presence?.[1],
218
- usePresenceValue = presence || void 0;
219
- let transition = isHydrating ? {
220
- type: "transition",
221
- duration: 0
222
- } : animations[animationKey],
223
- hasClonedTransition = !1;
224
- if (Array.isArray(props.transition)) {
225
- const config = props.transition[1];
226
- if (config && typeof config == "object") for (const key in config) {
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
- hasClonedTransition || (transition = Object.assign({}, transition), hasClonedTransition = !0), typeof val == "string" ? transition[key] = animations[val] : transition[key] = val;
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
- return {
232
- dontAnimate: dontAnimate2,
233
- motiProps: {
234
- animate: isExiting || componentState.unmounted === !0 ? {} : styles,
235
- transition: componentState.unmounted ? {
236
- duration: 0
237
- } : transition,
238
- usePresenceValue,
239
- presenceContext,
240
- exit: isExiting ? styles : void 0
241
- }
242
- };
243
- }, [presenceContext, presence, animationKey, componentState.unmounted, JSON.stringify(style), presenceContext, isDark]),
244
- moti = (0, import_author.useMotify)(motiProps);
245
- return process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile" && console.info("useMotify(", JSON.stringify(motiProps, null, 2) + ")", {
246
- "componentState.unmounted": componentState.unmounted,
247
- animationProps,
248
- motiProps,
249
- moti,
250
- style: [dontAnimate, moti.style]
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
  }