@tamagui/animations-moti 1.57.2 → 1.57.4

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.
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var create_animations_exports = {};
30
+ __export(create_animations_exports, {
31
+ createAnimations: () => createAnimations
32
+ });
33
+ module.exports = __toCommonJS(create_animations_exports);
34
+ var import_use_presence = require("@tamagui/use-presence");
35
+ var import_moti = require("moti");
36
+ var import_react = require("react");
37
+ var import_react_native_reanimated = __toESM(require("react-native-reanimated"));
38
+ function createAnimations(animations) {
39
+ return {
40
+ View: import_react_native_reanimated.default.View,
41
+ Text: import_react_native_reanimated.default.Text,
42
+ isReactNative: true,
43
+ animations,
44
+ usePresence: import_use_presence.usePresence,
45
+ useAnimatedNumber(initial) {
46
+ const val = (0, import_react_native_reanimated.useSharedValue)(initial);
47
+ return (0, import_react.useMemo)(
48
+ () => ({
49
+ getInstance() {
50
+ "worklet";
51
+ return val.value;
52
+ },
53
+ getValue() {
54
+ "worklet";
55
+ return val.value;
56
+ },
57
+ setValue(next) {
58
+ "worklet";
59
+ val.value = next;
60
+ },
61
+ stop() {
62
+ "worklet";
63
+ }
64
+ }),
65
+ [val]
66
+ );
67
+ },
68
+ useAnimatedNumberReaction({ value }, onValue) {
69
+ return (0, import_react_native_reanimated.useAnimatedReaction)(
70
+ () => {
71
+ return value.getValue();
72
+ },
73
+ (next, prev) => {
74
+ if (prev !== next) {
75
+ (0, import_react_native_reanimated.runOnJS)(onValue)(next);
76
+ }
77
+ },
78
+ // dependency array is very important here
79
+ [value, onValue]
80
+ );
81
+ },
82
+ /**
83
+ * `getStyle` must be a worklet
84
+ */
85
+ useAnimatedNumberStyle(val, getStyle) {
86
+ return (0, import_react_native_reanimated.useDerivedValue)(() => {
87
+ return getStyle(val.getValue());
88
+ }, [val, getStyle]);
89
+ },
90
+ useAnimations: ({ props, presence, style, onDidAnimate }) => {
91
+ const animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation;
92
+ let animate = style;
93
+ const nonAnimatedStyle = { ...style };
94
+ const animateOnly = props.animateOnly ?? ["opacity", "transform"];
95
+ animate = {};
96
+ animateOnly.forEach((nonAnimatedKey) => {
97
+ if (!style[nonAnimatedKey])
98
+ return;
99
+ animate[nonAnimatedKey] = style[nonAnimatedKey];
100
+ delete style[nonAnimatedKey];
101
+ });
102
+ const animateStr = JSON.stringify(animate);
103
+ const moti = (0, import_moti.useMotify)({
104
+ // without this, the driver breaks on native
105
+ // stringifying -> parsing fixes that
106
+ animate: (0, import_react.useMemo)(() => JSON.parse(animateStr), [animateStr]),
107
+ transition: animations[animationKey],
108
+ onDidAnimate,
109
+ usePresenceValue: presence,
110
+ presenceContext: (0, import_react.useContext)(import_use_presence.PresenceContext)
111
+ });
112
+ return {
113
+ style: [nonAnimatedStyle, moti.style]
114
+ };
115
+ }
116
+ };
117
+ }
118
+ // Annotate the CommonJS export names for ESM import in node:
119
+ 0 && (module.exports = {
120
+ createAnimations
121
+ });
122
+ //# sourceMappingURL=create-animations.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/create-animations.tsx"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA6C;AAE7C,kBAA0C;AAC1C,mBAAoC;AACpC,qCAKO;AAEA,SAAS,iBACd,YACoB;AACpB,SAAO;AAAA,IACL,MAAM,+BAAAA,QAAS;AAAA,IACf,MAAM,+BAAAA,QAAS;AAAA,IACf,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IAEA,kBAAkB,SAA0C;AAC1D,YAAM,UAAM,+CAAe,OAAO;AAElC,iBAAO;AAAA,QACL,OAAO;AAAA,UACL,cAAc;AACZ;AACA,mBAAO,IAAI;AAAA,UACb;AAAA,UACA,WAAW;AACT;AACA,mBAAO,IAAI;AAAA,UACb;AAAA,UACA,SAAS,MAAM;AACb;AACA,gBAAI,QAAQ;AAAA,UACd;AAAA,UACA,OAAO;AACL;AAAA,UACF;AAAA,QACF;AAAA,QACA,CAAC,GAAG;AAAA,MACN;AAAA,IACF;AAAA,IAEA,0BAA0B,EAAE,MAAM,GAAG,SAAS;AAC5C,iBAAO;AAAA,QACL,MAAM;AACJ,iBAAO,MAAM,SAAS;AAAA,QACxB;AAAA,QACA,CAAC,MAAM,SAAS;AACd,cAAI,SAAS,MAAM;AAGjB,wDAAQ,OAAO,EAAE,IAAI;AAAA,UACvB;AAAA,QACF;AAAA;AAAA,QAEA,CAAC,OAAO,OAAO;AAAA,MACjB;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,uBAAuB,KAAK,UAAU;AACpC,iBAAO,gDAAgB,MAAM;AAC3B,eAAO,SAAS,IAAI,SAAS,CAAC;AAAA,MAEhC,GAAG,CAAC,KAAK,QAAQ,CAAC;AAAA,IACpB;AAAA,IAEA,eAAe,CAAC,EAAE,OAAO,UAAU,OAAO,aAAa,MAAM;AAC3D,YAAM,eAAe,MAAM,QAAQ,MAAM,SAAS,IAC9C,MAAM,UAAU,CAAC,IACjB,MAAM;AAEV,UAAI,UAAU;AACd,YAAM,mBAAuC,EAAE,GAAG,MAAM;AAExD,YAAM,cAAc,MAAM,eAAe,CAAC,WAAW,WAAW;AAEhE,gBAAU,CAAC;AACX,kBAAY,QAAQ,CAAC,mBAAmB;AACtC,YAAI,CAAC,MAAM,cAAc;AAAG;AAC5B,gBAAQ,cAAc,IAAI,MAAM,cAAc;AAC9C,eAAO,MAAM,cAAc;AAAA,MAC7B,CAAC;AAED,YAAM,aAAa,KAAK,UAAU,OAAO;AACzC,YAAM,WAAO,uBAAU;AAAA;AAAA;AAAA,QAGrB,aAAS,sBAAQ,MAAM,KAAK,MAAM,UAAU,GAAG,CAAC,UAAU,CAAC;AAAA,QAC3D,YAAY,WAAW,YAAuC;AAAA,QAC9D;AAAA,QACA,kBAAkB;AAAA,QAClB,qBAAiB,yBAAW,mCAAe;AAAA,MAC7C,CAAC;AAED,aAAO;AAAA,QACL,OAAO,CAAC,kBAAkB,KAAK,KAAK;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AACF;",
5
+ "names": ["Animated"]
6
+ }
@@ -0,0 +1,93 @@
1
+ import { PresenceContext, usePresence } from "@tamagui/use-presence";
2
+ import { useMotify } from "moti";
3
+ import { useContext, useMemo } from "react";
4
+ import Animated, {
5
+ runOnJS,
6
+ useAnimatedReaction,
7
+ useDerivedValue,
8
+ useSharedValue
9
+ } from "react-native-reanimated";
10
+ function createAnimations(animations) {
11
+ return {
12
+ View: Animated.View,
13
+ Text: Animated.Text,
14
+ isReactNative: true,
15
+ animations,
16
+ usePresence,
17
+ useAnimatedNumber(initial) {
18
+ const val = useSharedValue(initial);
19
+ return useMemo(
20
+ () => ({
21
+ getInstance() {
22
+ "worklet";
23
+ return val.value;
24
+ },
25
+ getValue() {
26
+ "worklet";
27
+ return val.value;
28
+ },
29
+ setValue(next) {
30
+ "worklet";
31
+ val.value = next;
32
+ },
33
+ stop() {
34
+ "worklet";
35
+ }
36
+ }),
37
+ [val]
38
+ );
39
+ },
40
+ useAnimatedNumberReaction({ value }, onValue) {
41
+ return useAnimatedReaction(
42
+ () => {
43
+ return value.getValue();
44
+ },
45
+ (next, prev) => {
46
+ if (prev !== next) {
47
+ runOnJS(onValue)(next);
48
+ }
49
+ },
50
+ // dependency array is very important here
51
+ [value, onValue]
52
+ );
53
+ },
54
+ /**
55
+ * `getStyle` must be a worklet
56
+ */
57
+ useAnimatedNumberStyle(val, getStyle) {
58
+ return useDerivedValue(() => {
59
+ return getStyle(val.getValue());
60
+ }, [val, getStyle]);
61
+ },
62
+ useAnimations: ({ props, presence, style, onDidAnimate }) => {
63
+ const animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation;
64
+ let animate = style;
65
+ const nonAnimatedStyle = { ...style };
66
+ const animateOnly = props.animateOnly ?? ["opacity", "transform"];
67
+ animate = {};
68
+ animateOnly.forEach((nonAnimatedKey) => {
69
+ if (!style[nonAnimatedKey])
70
+ return;
71
+ animate[nonAnimatedKey] = style[nonAnimatedKey];
72
+ delete style[nonAnimatedKey];
73
+ });
74
+ const animateStr = JSON.stringify(animate);
75
+ const moti = useMotify({
76
+ // without this, the driver breaks on native
77
+ // stringifying -> parsing fixes that
78
+ animate: useMemo(() => JSON.parse(animateStr), [animateStr]),
79
+ transition: animations[animationKey],
80
+ onDidAnimate,
81
+ usePresenceValue: presence,
82
+ presenceContext: useContext(PresenceContext)
83
+ });
84
+ return {
85
+ style: [nonAnimatedStyle, moti.style]
86
+ };
87
+ }
88
+ };
89
+ }
90
+ export {
91
+ createAnimations
92
+ };
93
+ //# sourceMappingURL=create-animations.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/create-animations.tsx"],
4
+ "mappings": "AAAA,SAAS,iBAAiB,mBAAmB;AAE7C,SAAyB,iBAAiB;AAC1C,SAAS,YAAY,eAAe;AACpC,OAAO;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,SAAS,iBACd,YACoB;AACpB,SAAO;AAAA,IACL,MAAM,SAAS;AAAA,IACf,MAAM,SAAS;AAAA,IACf,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IAEA,kBAAkB,SAA0C;AAC1D,YAAM,MAAM,eAAe,OAAO;AAElC,aAAO;AAAA,QACL,OAAO;AAAA,UACL,cAAc;AACZ;AACA,mBAAO,IAAI;AAAA,UACb;AAAA,UACA,WAAW;AACT;AACA,mBAAO,IAAI;AAAA,UACb;AAAA,UACA,SAAS,MAAM;AACb;AACA,gBAAI,QAAQ;AAAA,UACd;AAAA,UACA,OAAO;AACL;AAAA,UACF;AAAA,QACF;AAAA,QACA,CAAC,GAAG;AAAA,MACN;AAAA,IACF;AAAA,IAEA,0BAA0B,EAAE,MAAM,GAAG,SAAS;AAC5C,aAAO;AAAA,QACL,MAAM;AACJ,iBAAO,MAAM,SAAS;AAAA,QACxB;AAAA,QACA,CAAC,MAAM,SAAS;AACd,cAAI,SAAS,MAAM;AAGjB,oBAAQ,OAAO,EAAE,IAAI;AAAA,UACvB;AAAA,QACF;AAAA;AAAA,QAEA,CAAC,OAAO,OAAO;AAAA,MACjB;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,uBAAuB,KAAK,UAAU;AACpC,aAAO,gBAAgB,MAAM;AAC3B,eAAO,SAAS,IAAI,SAAS,CAAC;AAAA,MAEhC,GAAG,CAAC,KAAK,QAAQ,CAAC;AAAA,IACpB;AAAA,IAEA,eAAe,CAAC,EAAE,OAAO,UAAU,OAAO,aAAa,MAAM;AAC3D,YAAM,eAAe,MAAM,QAAQ,MAAM,SAAS,IAC9C,MAAM,UAAU,CAAC,IACjB,MAAM;AAEV,UAAI,UAAU;AACd,YAAM,mBAAuC,EAAE,GAAG,MAAM;AAExD,YAAM,cAAc,MAAM,eAAe,CAAC,WAAW,WAAW;AAEhE,gBAAU,CAAC;AACX,kBAAY,QAAQ,CAAC,mBAAmB;AACtC,YAAI,CAAC,MAAM,cAAc;AAAG;AAC5B,gBAAQ,cAAc,IAAI,MAAM,cAAc;AAC9C,eAAO,MAAM,cAAc;AAAA,MAC7B,CAAC;AAED,YAAM,aAAa,KAAK,UAAU,OAAO;AACzC,YAAM,OAAO,UAAU;AAAA;AAAA;AAAA,QAGrB,SAAS,QAAQ,MAAM,KAAK,MAAM,UAAU,GAAG,CAAC,UAAU,CAAC;AAAA,QAC3D,YAAY,WAAW,YAAuC;AAAA,QAC9D;AAAA,QACA,kBAAkB;AAAA,QAClB,iBAAiB,WAAW,eAAe;AAAA,MAC7C,CAAC;AAED,aAAO;AAAA,QACL,OAAO,CAAC,kBAAkB,KAAK,KAAK;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AACF;",
5
+ "names": []
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/animations-moti",
3
- "version": "1.57.2",
3
+ "version": "1.57.4",
4
4
  "source": "src/index.ts",
5
5
  "license": "MIT",
6
6
  "types": "./types/index.d.ts",
@@ -12,12 +12,12 @@
12
12
  "dist"
13
13
  ],
14
14
  "dependencies": {
15
- "@tamagui/use-presence": "1.57.2",
16
- "@tamagui/web": "1.57.2",
15
+ "@tamagui/use-presence": "1.57.4",
16
+ "@tamagui/web": "1.57.4",
17
17
  "moti": "^0.25.3"
18
18
  },
19
19
  "devDependencies": {
20
- "@tamagui/build": "1.57.2",
20
+ "@tamagui/build": "1.57.4",
21
21
  "react-native-reanimated": "^3.3.0"
22
22
  },
23
23
  "scripts": {