@tamagui/animations-moti 1.15.34
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/create-animations.js +122 -0
- package/dist/cjs/create-animations.js.map +6 -0
- package/dist/cjs/index.js +24 -0
- package/dist/cjs/index.js.map +6 -0
- package/dist/cjs/polyfill.js +5 -0
- package/dist/cjs/polyfill.js.map +6 -0
- package/dist/esm/create-animations.js +93 -0
- package/dist/esm/create-animations.js.map +6 -0
- package/dist/esm/create-animations.mjs +93 -0
- package/dist/esm/create-animations.mjs.map +6 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +6 -0
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/index.mjs.map +6 -0
- package/dist/esm/polyfill.js +4 -0
- package/dist/esm/polyfill.js.map +6 -0
- package/dist/esm/polyfill.mjs +4 -0
- package/dist/esm/polyfill.mjs.map +6 -0
- package/package.json +37 -0
- package/src/create-animations.tsx +107 -0
- package/src/index.tsx +3 -0
- package/src/polyfill.ts +4 -0
- package/types/create-animations.d.ts +4 -0
- package/types/create-animations.d.ts.map +1 -0
- package/types/index.d.ts +3 -0
- package/types/index.d.ts.map +1 -0
- package/types/polyfill.d.ts +1 -0
- package/types/polyfill.d.ts.map +1 -0
|
@@ -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,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,QACL,OAAO,CAAC,kBAAkB,KAAK,KAAK;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AACF;",
|
|
5
|
+
"names": ["Animated"]
|
|
6
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var src_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(src_exports);
|
|
18
|
+
var import_polyfill = require("./polyfill");
|
|
19
|
+
__reExport(src_exports, require("./create-animations"), module.exports);
|
|
20
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
+
0 && (module.exports = {
|
|
22
|
+
...require("./create-animations")
|
|
23
|
+
});
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -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;A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AAM,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
|
+
}
|
|
@@ -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.mjs.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
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tamagui/animations-moti",
|
|
3
|
+
"version": "1.15.34",
|
|
4
|
+
"source": "src/index.ts",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"types": "./types/index.d.ts",
|
|
7
|
+
"main": "dist/cjs",
|
|
8
|
+
"module": "dist/esm",
|
|
9
|
+
"files": [
|
|
10
|
+
"src",
|
|
11
|
+
"types",
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@tamagui/use-presence": "1.15.34",
|
|
16
|
+
"@tamagui/web": "1.15.34"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@tamagui/build": "1.15.34",
|
|
20
|
+
"moti": "^0.25.1",
|
|
21
|
+
"react-native-reanimated": "^2.14.4"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tamagui-build",
|
|
25
|
+
"watch": "tamagui-build --watch",
|
|
26
|
+
"clean": "tamagui-build clean",
|
|
27
|
+
"clean:build": "tamagui-build clean:build"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
|
|
33
|
+
"sideEffects": [
|
|
34
|
+
"./index.tsx",
|
|
35
|
+
"./polyfill.ts"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { PresenceContext, usePresence } from '@tamagui/use-presence'
|
|
2
|
+
import { AnimationDriver, UniversalAnimatedNumber } from '@tamagui/web'
|
|
3
|
+
import { MotiTransition, useMotify } from 'moti'
|
|
4
|
+
import { useContext, useMemo } from 'react'
|
|
5
|
+
import Animated, {
|
|
6
|
+
runOnJS,
|
|
7
|
+
useAnimatedReaction,
|
|
8
|
+
useDerivedValue,
|
|
9
|
+
useSharedValue,
|
|
10
|
+
} from 'react-native-reanimated'
|
|
11
|
+
|
|
12
|
+
export function createAnimations<A extends Record<string, MotiTransition>>(
|
|
13
|
+
animations: A
|
|
14
|
+
): AnimationDriver<A> {
|
|
15
|
+
return {
|
|
16
|
+
View: Animated.View,
|
|
17
|
+
Text: Animated.Text,
|
|
18
|
+
isReactNative: true,
|
|
19
|
+
animations,
|
|
20
|
+
usePresence,
|
|
21
|
+
|
|
22
|
+
useAnimatedNumber(initial): UniversalAnimatedNumber<number> {
|
|
23
|
+
const val = useSharedValue(initial)
|
|
24
|
+
|
|
25
|
+
return useMemo(
|
|
26
|
+
() => ({
|
|
27
|
+
getInstance() {
|
|
28
|
+
'worklet'
|
|
29
|
+
return val.value
|
|
30
|
+
},
|
|
31
|
+
getValue() {
|
|
32
|
+
'worklet'
|
|
33
|
+
return val.value
|
|
34
|
+
},
|
|
35
|
+
setValue(next) {
|
|
36
|
+
'worklet'
|
|
37
|
+
val.value = next
|
|
38
|
+
},
|
|
39
|
+
stop() {
|
|
40
|
+
'worklet'
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
[val]
|
|
44
|
+
)
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
useAnimatedNumberReaction({ value }, onValue) {
|
|
48
|
+
return useAnimatedReaction(
|
|
49
|
+
() => {
|
|
50
|
+
return value.getValue()
|
|
51
|
+
},
|
|
52
|
+
(next, prev) => {
|
|
53
|
+
if (prev !== next) {
|
|
54
|
+
// @nate what is the point of this hook? is this necessary?
|
|
55
|
+
// without runOnJS, onValue would need to be a worklet
|
|
56
|
+
runOnJS(onValue)(next)
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
// dependency array is very important here
|
|
60
|
+
[value, onValue]
|
|
61
|
+
)
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* `getStyle` must be a worklet
|
|
66
|
+
*/
|
|
67
|
+
useAnimatedNumberStyle(val, getStyle) {
|
|
68
|
+
return useDerivedValue(() => {
|
|
69
|
+
return getStyle(val.getValue())
|
|
70
|
+
// dependency array is very important here
|
|
71
|
+
}, [val, getStyle])
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
useAnimations: ({ props, presence, style, onDidAnimate }) => {
|
|
75
|
+
const animationKey = Array.isArray(props.animation)
|
|
76
|
+
? props.animation[0]
|
|
77
|
+
: props.animation
|
|
78
|
+
|
|
79
|
+
let animate = style
|
|
80
|
+
const nonAnimatedStyle: object | undefined = { ...style }
|
|
81
|
+
|
|
82
|
+
const animateOnly = props.animateOnly ?? ['opacity', 'transform']
|
|
83
|
+
|
|
84
|
+
animate = {}
|
|
85
|
+
animateOnly.forEach((nonAnimatedKey) => {
|
|
86
|
+
if (!style[nonAnimatedKey]) return
|
|
87
|
+
animate[nonAnimatedKey] = style[nonAnimatedKey]
|
|
88
|
+
delete style[nonAnimatedKey]
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
const animateStr = JSON.stringify(animate)
|
|
92
|
+
const moti = useMotify({
|
|
93
|
+
// without this, the driver breaks on native
|
|
94
|
+
// stringifying -> parsing fixes that
|
|
95
|
+
animate: useMemo(() => JSON.parse(animateStr), [animateStr]),
|
|
96
|
+
transition: animations[animationKey as keyof typeof animations],
|
|
97
|
+
onDidAnimate,
|
|
98
|
+
usePresenceValue: presence as any,
|
|
99
|
+
presenceContext: useContext(PresenceContext),
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
style: [nonAnimatedStyle, moti.style],
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
}
|
|
107
|
+
}
|
package/src/index.tsx
ADDED
package/src/polyfill.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-animations.d.ts","sourceRoot":"","sources":["../src/create-animations.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAA2B,MAAM,cAAc,CAAA;AACvE,OAAO,EAAE,cAAc,EAAa,MAAM,MAAM,CAAA;AAShD,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,EACvE,UAAU,EAAE,CAAC,GACZ,eAAe,CAAC,CAAC,CAAC,CA6FpB"}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,YAAY,CAAA;AAEnB,cAAc,qBAAqB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=polyfill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../src/polyfill.ts"],"names":[],"mappings":""}
|