@tamagui/animations-css 1.0.1-beta.99 → 1.0.1-rc.0.1
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.js +56 -25
- package/dist/cjs/createAnimations.js.map +2 -2
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/createAnimations.js +55 -27
- package/dist/esm/createAnimations.js.map +2 -2
- package/dist/esm/index.js +0 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/jsx/createAnimations.js +55 -12
- package/dist/jsx/createAnimations.js.map +2 -2
- package/dist/jsx/index.js +0 -0
- package/dist/jsx/index.js.map +1 -1
- package/package.json +4 -4
- package/src/createAnimations.tsx +63 -12
- package/types/createAnimations.d.ts +0 -0
- package/types/index.d.ts +0 -0
- package/types/createAnimations.d.ts.map +0 -1
- package/types/index.d.ts.map +0 -1
|
@@ -1,21 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
6
|
var __export = (target, all) => {
|
|
20
7
|
for (var name in all)
|
|
21
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -34,23 +21,67 @@ __export(createAnimations_exports, {
|
|
|
34
21
|
createAnimations: () => createAnimations
|
|
35
22
|
});
|
|
36
23
|
module.exports = __toCommonJS(createAnimations_exports);
|
|
24
|
+
var import_core = require("@tamagui/core");
|
|
25
|
+
var import_use_presence = require("@tamagui/use-presence");
|
|
26
|
+
var import_react = require("react");
|
|
37
27
|
function createAnimations(animations) {
|
|
38
28
|
return {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
Text: "span",
|
|
29
|
+
View: import_core.Stack,
|
|
30
|
+
Text: import_core.Text,
|
|
42
31
|
animations,
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
usePresence: import_use_presence.usePresence,
|
|
33
|
+
useAnimatedNumber(initial) {
|
|
34
|
+
const val = (0, import_react.useRef)(initial);
|
|
35
|
+
return {
|
|
36
|
+
getInstance() {
|
|
37
|
+
return val;
|
|
38
|
+
},
|
|
39
|
+
getValue() {
|
|
40
|
+
return val.current;
|
|
41
|
+
},
|
|
42
|
+
setValue(next) {
|
|
43
|
+
val.current = next;
|
|
44
|
+
},
|
|
45
|
+
stop() {
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
useAnimatedNumberReaction(val, reaction) {
|
|
50
|
+
},
|
|
51
|
+
useAnimatedNumberStyle(val, getStyle) {
|
|
52
|
+
return getStyle(val.getValue());
|
|
53
|
+
},
|
|
54
|
+
useAnimations: ({ props, presence, style, state, hostRef }) => {
|
|
55
|
+
const isEntering = !!state.unmounted;
|
|
56
|
+
const isExiting = (presence == null ? void 0 : presence[0]) === false;
|
|
57
|
+
const sendExitComplete = presence == null ? void 0 : presence[1];
|
|
58
|
+
const animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation;
|
|
59
|
+
const animation = animations[animationKey];
|
|
45
60
|
if (!animation) {
|
|
46
|
-
|
|
61
|
+
return null;
|
|
47
62
|
}
|
|
48
63
|
const keys = props.animateOnly ? props.animateOnly.join(" ") : "all";
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
64
|
+
(0, import_core.useIsomorphicLayoutEffect)(() => {
|
|
65
|
+
if (!sendExitComplete || !isExiting || !hostRef.current)
|
|
66
|
+
return;
|
|
67
|
+
const node = hostRef.current;
|
|
68
|
+
const onFinishAnimation = () => {
|
|
69
|
+
sendExitComplete == null ? void 0 : sendExitComplete();
|
|
70
|
+
};
|
|
71
|
+
node.addEventListener("transitionend", onFinishAnimation);
|
|
72
|
+
node.addEventListener("transitioncancel", onFinishAnimation);
|
|
73
|
+
return () => {
|
|
74
|
+
node.removeEventListener("transitionend", onFinishAnimation);
|
|
75
|
+
node.addEventListener("transitioncancel", onFinishAnimation);
|
|
76
|
+
};
|
|
77
|
+
}, [sendExitComplete, isExiting]);
|
|
78
|
+
style.transition = `${keys} ${animation}`;
|
|
79
|
+
if (process.env.NODE_ENV === "development" && props["debug"]) {
|
|
80
|
+
console.log("CSS animation", style, { isEntering, isExiting });
|
|
81
|
+
}
|
|
82
|
+
return (0, import_react.useMemo)(() => {
|
|
83
|
+
return { style };
|
|
84
|
+
}, [JSON.stringify(style)]);
|
|
54
85
|
}
|
|
55
86
|
};
|
|
56
87
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/createAnimations.tsx"],
|
|
4
|
-
"sourcesContent": ["import { AnimationDriver } from '@tamagui/core'\n\nexport function createAnimations<A extends Object>(animations: A): AnimationDriver<A> {\n return {\n
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { AnimationDriver, Stack, Text, useIsomorphicLayoutEffect } from '@tamagui/core'\nimport { usePresence } from '@tamagui/use-presence'\nimport { useMemo, useRef } from 'react'\n\nexport function createAnimations<A extends Object>(animations: A): AnimationDriver<A> {\n return {\n View: Stack,\n Text: Text,\n animations,\n usePresence,\n\n useAnimatedNumber(initial) {\n const val = useRef(initial)\n return {\n getInstance() {\n return val\n },\n getValue() {\n return val.current\n },\n setValue(next) {\n val.current = next\n },\n stop() {},\n }\n },\n\n useAnimatedNumberReaction(val, reaction) {\n // TODO use event listeners, would need access to the corresponsing node...\n },\n\n useAnimatedNumberStyle(val, getStyle) {\n return getStyle(val.getValue())\n },\n\n useAnimations: ({ props, presence, style, state, hostRef }) => {\n const isEntering = !!state.unmounted\n const isExiting = presence?.[0] === false\n const sendExitComplete = presence?.[1]\n const animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation\n const animation = animations[animationKey as any]\n if (!animation) {\n return null\n }\n\n const keys = props.animateOnly ? props.animateOnly.join(' ') : 'all'\n\n useIsomorphicLayoutEffect(() => {\n if (!sendExitComplete || !isExiting || !hostRef.current) return\n const node = hostRef.current as HTMLElement\n const onFinishAnimation = () => {\n sendExitComplete?.()\n }\n node.addEventListener('transitionend', onFinishAnimation)\n node.addEventListener('transitioncancel', onFinishAnimation)\n return () => {\n node.removeEventListener('transitionend', onFinishAnimation)\n node.addEventListener('transitioncancel', onFinishAnimation)\n }\n }, [sendExitComplete, isExiting])\n\n // add css transition\n style.transition = `${keys} ${animation}`\n\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n // eslint-disable-next-line no-console\n console.log('CSS animation', style, { isEntering, isExiting })\n }\n\n return useMemo(() => {\n return { style }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [JSON.stringify(style)])\n },\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAwE;AACxE,0BAA4B;AAC5B,mBAAgC;AAEzB,SAAS,iBAAmC,YAAmC;AACpF,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IAEA,kBAAkB,SAAS;AACzB,YAAM,UAAM,qBAAO,OAAO;AAC1B,aAAO;AAAA,QACL,cAAc;AACZ,iBAAO;AAAA,QACT;AAAA,QACA,WAAW;AACT,iBAAO,IAAI;AAAA,QACb;AAAA,QACA,SAAS,MAAM;AACb,cAAI,UAAU;AAAA,QAChB;AAAA,QACA,OAAO;AAAA,QAAC;AAAA,MACV;AAAA,IACF;AAAA,IAEA,0BAA0B,KAAK,UAAU;AAAA,IAEzC;AAAA,IAEA,uBAAuB,KAAK,UAAU;AACpC,aAAO,SAAS,IAAI,SAAS,CAAC;AAAA,IAChC;AAAA,IAEA,eAAe,CAAC,EAAE,OAAO,UAAU,OAAO,OAAO,QAAQ,MAAM;AAC7D,YAAM,aAAa,CAAC,CAAC,MAAM;AAC3B,YAAM,aAAY,qCAAW,QAAO;AACpC,YAAM,mBAAmB,qCAAW;AACpC,YAAM,eAAe,MAAM,QAAQ,MAAM,SAAS,IAAI,MAAM,UAAU,KAAK,MAAM;AACjF,YAAM,YAAY,WAAW;AAC7B,UAAI,CAAC,WAAW;AACd,eAAO;AAAA,MACT;AAEA,YAAM,OAAO,MAAM,cAAc,MAAM,YAAY,KAAK,GAAG,IAAI;AAE/D,iDAA0B,MAAM;AAC9B,YAAI,CAAC,oBAAoB,CAAC,aAAa,CAAC,QAAQ;AAAS;AACzD,cAAM,OAAO,QAAQ;AACrB,cAAM,oBAAoB,MAAM;AAC9B;AAAA,QACF;AACA,aAAK,iBAAiB,iBAAiB,iBAAiB;AACxD,aAAK,iBAAiB,oBAAoB,iBAAiB;AAC3D,eAAO,MAAM;AACX,eAAK,oBAAoB,iBAAiB,iBAAiB;AAC3D,eAAK,iBAAiB,oBAAoB,iBAAiB;AAAA,QAC7D;AAAA,MACF,GAAG,CAAC,kBAAkB,SAAS,CAAC;AAGhC,YAAM,aAAa,GAAG,QAAQ;AAE9B,UAAI,QAAQ,IAAI,aAAa,iBAAiB,MAAM,UAAU;AAE5D,gBAAQ,IAAI,iBAAiB,OAAO,EAAE,YAAY,UAAU,CAAC;AAAA,MAC/D;AAEA,iBAAO,sBAAQ,MAAM;AACnB,eAAO,EAAE,MAAM;AAAA,MAEjB,GAAG,CAAC,KAAK,UAAU,KAAK,CAAC,CAAC;AAAA,IAC5B;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/index.js
CHANGED
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,36 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
1
|
+
import { Stack, Text, useIsomorphicLayoutEffect } from "@tamagui/core";
|
|
2
|
+
import { usePresence } from "@tamagui/use-presence";
|
|
3
|
+
import { useMemo, useRef } from "react";
|
|
17
4
|
function createAnimations(animations) {
|
|
18
5
|
return {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Text: "span",
|
|
6
|
+
View: Stack,
|
|
7
|
+
Text,
|
|
22
8
|
animations,
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
usePresence,
|
|
10
|
+
useAnimatedNumber(initial) {
|
|
11
|
+
const val = useRef(initial);
|
|
12
|
+
return {
|
|
13
|
+
getInstance() {
|
|
14
|
+
return val;
|
|
15
|
+
},
|
|
16
|
+
getValue() {
|
|
17
|
+
return val.current;
|
|
18
|
+
},
|
|
19
|
+
setValue(next) {
|
|
20
|
+
val.current = next;
|
|
21
|
+
},
|
|
22
|
+
stop() {
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
useAnimatedNumberReaction(val, reaction) {
|
|
27
|
+
},
|
|
28
|
+
useAnimatedNumberStyle(val, getStyle) {
|
|
29
|
+
return getStyle(val.getValue());
|
|
30
|
+
},
|
|
31
|
+
useAnimations: ({ props, presence, style, state, hostRef }) => {
|
|
32
|
+
const isEntering = !!state.unmounted;
|
|
33
|
+
const isExiting = (presence == null ? void 0 : presence[0]) === false;
|
|
34
|
+
const sendExitComplete = presence == null ? void 0 : presence[1];
|
|
35
|
+
const animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation;
|
|
36
|
+
const animation = animations[animationKey];
|
|
25
37
|
if (!animation) {
|
|
26
|
-
|
|
38
|
+
return null;
|
|
27
39
|
}
|
|
28
40
|
const keys = props.animateOnly ? props.animateOnly.join(" ") : "all";
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
useIsomorphicLayoutEffect(() => {
|
|
42
|
+
if (!sendExitComplete || !isExiting || !hostRef.current)
|
|
43
|
+
return;
|
|
44
|
+
const node = hostRef.current;
|
|
45
|
+
const onFinishAnimation = () => {
|
|
46
|
+
sendExitComplete == null ? void 0 : sendExitComplete();
|
|
47
|
+
};
|
|
48
|
+
node.addEventListener("transitionend", onFinishAnimation);
|
|
49
|
+
node.addEventListener("transitioncancel", onFinishAnimation);
|
|
50
|
+
return () => {
|
|
51
|
+
node.removeEventListener("transitionend", onFinishAnimation);
|
|
52
|
+
node.addEventListener("transitioncancel", onFinishAnimation);
|
|
53
|
+
};
|
|
54
|
+
}, [sendExitComplete, isExiting]);
|
|
55
|
+
style.transition = `${keys} ${animation}`;
|
|
56
|
+
if (process.env.NODE_ENV === "development" && props["debug"]) {
|
|
57
|
+
console.log("CSS animation", style, { isEntering, isExiting });
|
|
58
|
+
}
|
|
59
|
+
return useMemo(() => {
|
|
60
|
+
return { style };
|
|
61
|
+
}, [JSON.stringify(style)]);
|
|
34
62
|
}
|
|
35
63
|
};
|
|
36
64
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/createAnimations.tsx"],
|
|
4
|
-
"sourcesContent": ["import { AnimationDriver } from '@tamagui/core'\n\nexport function createAnimations<A extends Object>(animations: A): AnimationDriver<A> {\n return {\n
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { AnimationDriver, Stack, Text, useIsomorphicLayoutEffect } from '@tamagui/core'\nimport { usePresence } from '@tamagui/use-presence'\nimport { useMemo, useRef } from 'react'\n\nexport function createAnimations<A extends Object>(animations: A): AnimationDriver<A> {\n return {\n View: Stack,\n Text: Text,\n animations,\n usePresence,\n\n useAnimatedNumber(initial) {\n const val = useRef(initial)\n return {\n getInstance() {\n return val\n },\n getValue() {\n return val.current\n },\n setValue(next) {\n val.current = next\n },\n stop() {},\n }\n },\n\n useAnimatedNumberReaction(val, reaction) {\n // TODO use event listeners, would need access to the corresponsing node...\n },\n\n useAnimatedNumberStyle(val, getStyle) {\n return getStyle(val.getValue())\n },\n\n useAnimations: ({ props, presence, style, state, hostRef }) => {\n const isEntering = !!state.unmounted\n const isExiting = presence?.[0] === false\n const sendExitComplete = presence?.[1]\n const animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation\n const animation = animations[animationKey as any]\n if (!animation) {\n return null\n }\n\n const keys = props.animateOnly ? props.animateOnly.join(' ') : 'all'\n\n useIsomorphicLayoutEffect(() => {\n if (!sendExitComplete || !isExiting || !hostRef.current) return\n const node = hostRef.current as HTMLElement\n const onFinishAnimation = () => {\n sendExitComplete?.()\n }\n node.addEventListener('transitionend', onFinishAnimation)\n node.addEventListener('transitioncancel', onFinishAnimation)\n return () => {\n node.removeEventListener('transitionend', onFinishAnimation)\n node.addEventListener('transitioncancel', onFinishAnimation)\n }\n }, [sendExitComplete, isExiting])\n\n // add css transition\n style.transition = `${keys} ${animation}`\n\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n // eslint-disable-next-line no-console\n console.log('CSS animation', style, { isEntering, isExiting })\n }\n\n return useMemo(() => {\n return { style }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [JSON.stringify(style)])\n },\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAA0B,OAAO,MAAM,iCAAiC;AACxE,SAAS,mBAAmB;AAC5B,SAAS,SAAS,cAAc;AAEzB,SAAS,iBAAmC,YAAmC;AACpF,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IAEA,kBAAkB,SAAS;AACzB,YAAM,MAAM,OAAO,OAAO;AAC1B,aAAO;AAAA,QACL,cAAc;AACZ,iBAAO;AAAA,QACT;AAAA,QACA,WAAW;AACT,iBAAO,IAAI;AAAA,QACb;AAAA,QACA,SAAS,MAAM;AACb,cAAI,UAAU;AAAA,QAChB;AAAA,QACA,OAAO;AAAA,QAAC;AAAA,MACV;AAAA,IACF;AAAA,IAEA,0BAA0B,KAAK,UAAU;AAAA,IAEzC;AAAA,IAEA,uBAAuB,KAAK,UAAU;AACpC,aAAO,SAAS,IAAI,SAAS,CAAC;AAAA,IAChC;AAAA,IAEA,eAAe,CAAC,EAAE,OAAO,UAAU,OAAO,OAAO,QAAQ,MAAM;AAC7D,YAAM,aAAa,CAAC,CAAC,MAAM;AAC3B,YAAM,aAAY,qCAAW,QAAO;AACpC,YAAM,mBAAmB,qCAAW;AACpC,YAAM,eAAe,MAAM,QAAQ,MAAM,SAAS,IAAI,MAAM,UAAU,KAAK,MAAM;AACjF,YAAM,YAAY,WAAW;AAC7B,UAAI,CAAC,WAAW;AACd,eAAO;AAAA,MACT;AAEA,YAAM,OAAO,MAAM,cAAc,MAAM,YAAY,KAAK,GAAG,IAAI;AAE/D,gCAA0B,MAAM;AAC9B,YAAI,CAAC,oBAAoB,CAAC,aAAa,CAAC,QAAQ;AAAS;AACzD,cAAM,OAAO,QAAQ;AACrB,cAAM,oBAAoB,MAAM;AAC9B;AAAA,QACF;AACA,aAAK,iBAAiB,iBAAiB,iBAAiB;AACxD,aAAK,iBAAiB,oBAAoB,iBAAiB;AAC3D,eAAO,MAAM;AACX,eAAK,oBAAoB,iBAAiB,iBAAiB;AAC3D,eAAK,iBAAiB,oBAAoB,iBAAiB;AAAA,QAC7D;AAAA,MACF,GAAG,CAAC,kBAAkB,SAAS,CAAC;AAGhC,YAAM,aAAa,GAAG,QAAQ;AAE9B,UAAI,QAAQ,IAAI,aAAa,iBAAiB,MAAM,UAAU;AAE5D,gBAAQ,IAAI,iBAAiB,OAAO,EAAE,YAAY,UAAU,CAAC;AAAA,MAC/D;AAEA,aAAO,QAAQ,MAAM;AACnB,eAAO,EAAE,MAAM;AAAA,MAEjB,GAAG,CAAC,KAAK,UAAU,KAAK,CAAC,CAAC;AAAA,IAC5B;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/index.js
CHANGED
|
File without changes
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1,21 +1,64 @@
|
|
|
1
|
+
import { Stack, Text, useIsomorphicLayoutEffect } from "@tamagui/core";
|
|
2
|
+
import { usePresence } from "@tamagui/use-presence";
|
|
3
|
+
import { useMemo, useRef } from "react";
|
|
1
4
|
function createAnimations(animations) {
|
|
2
5
|
return {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Text: "span",
|
|
6
|
+
View: Stack,
|
|
7
|
+
Text,
|
|
6
8
|
animations,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
throw new Error(`no animation found: ${props.animation}`);
|
|
11
|
-
}
|
|
12
|
-
const keys = props.animateOnly ? props.animateOnly.join(" ") : "all";
|
|
9
|
+
usePresence,
|
|
10
|
+
useAnimatedNumber(initial) {
|
|
11
|
+
const val = useRef(initial);
|
|
13
12
|
return {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
getInstance() {
|
|
14
|
+
return val;
|
|
15
|
+
},
|
|
16
|
+
getValue() {
|
|
17
|
+
return val.current;
|
|
18
|
+
},
|
|
19
|
+
setValue(next) {
|
|
20
|
+
val.current = next;
|
|
21
|
+
},
|
|
22
|
+
stop() {
|
|
17
23
|
}
|
|
18
24
|
};
|
|
25
|
+
},
|
|
26
|
+
useAnimatedNumberReaction(val, reaction) {
|
|
27
|
+
},
|
|
28
|
+
useAnimatedNumberStyle(val, getStyle) {
|
|
29
|
+
return getStyle(val.getValue());
|
|
30
|
+
},
|
|
31
|
+
useAnimations: ({ props, presence, style, state, hostRef }) => {
|
|
32
|
+
const isEntering = !!state.unmounted;
|
|
33
|
+
const isExiting = presence?.[0] === false;
|
|
34
|
+
const sendExitComplete = presence?.[1];
|
|
35
|
+
const animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation;
|
|
36
|
+
const animation = animations[animationKey];
|
|
37
|
+
if (!animation) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const keys = props.animateOnly ? props.animateOnly.join(" ") : "all";
|
|
41
|
+
useIsomorphicLayoutEffect(() => {
|
|
42
|
+
if (!sendExitComplete || !isExiting || !hostRef.current)
|
|
43
|
+
return;
|
|
44
|
+
const node = hostRef.current;
|
|
45
|
+
const onFinishAnimation = () => {
|
|
46
|
+
sendExitComplete?.();
|
|
47
|
+
};
|
|
48
|
+
node.addEventListener("transitionend", onFinishAnimation);
|
|
49
|
+
node.addEventListener("transitioncancel", onFinishAnimation);
|
|
50
|
+
return () => {
|
|
51
|
+
node.removeEventListener("transitionend", onFinishAnimation);
|
|
52
|
+
node.addEventListener("transitioncancel", onFinishAnimation);
|
|
53
|
+
};
|
|
54
|
+
}, [sendExitComplete, isExiting]);
|
|
55
|
+
style.transition = `${keys} ${animation}`;
|
|
56
|
+
if (process.env.NODE_ENV === "development" && props["debug"]) {
|
|
57
|
+
console.log("CSS animation", style, { isEntering, isExiting });
|
|
58
|
+
}
|
|
59
|
+
return useMemo(() => {
|
|
60
|
+
return { style };
|
|
61
|
+
}, [JSON.stringify(style)]);
|
|
19
62
|
}
|
|
20
63
|
};
|
|
21
64
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/createAnimations.tsx"],
|
|
4
|
-
"sourcesContent": ["import { AnimationDriver } from '@tamagui/core'\n\nexport function createAnimations<A extends Object>(animations: A): AnimationDriver<A> {\n return {\n
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { AnimationDriver, Stack, Text, useIsomorphicLayoutEffect } from '@tamagui/core'\nimport { usePresence } from '@tamagui/use-presence'\nimport { useMemo, useRef } from 'react'\n\nexport function createAnimations<A extends Object>(animations: A): AnimationDriver<A> {\n return {\n View: Stack,\n Text: Text,\n animations,\n usePresence,\n\n useAnimatedNumber(initial) {\n const val = useRef(initial)\n return {\n getInstance() {\n return val\n },\n getValue() {\n return val.current\n },\n setValue(next) {\n val.current = next\n },\n stop() {},\n }\n },\n\n useAnimatedNumberReaction(val, reaction) {\n // TODO use event listeners, would need access to the corresponsing node...\n },\n\n useAnimatedNumberStyle(val, getStyle) {\n return getStyle(val.getValue())\n },\n\n useAnimations: ({ props, presence, style, state, hostRef }) => {\n const isEntering = !!state.unmounted\n const isExiting = presence?.[0] === false\n const sendExitComplete = presence?.[1]\n const animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation\n const animation = animations[animationKey as any]\n if (!animation) {\n return null\n }\n\n const keys = props.animateOnly ? props.animateOnly.join(' ') : 'all'\n\n useIsomorphicLayoutEffect(() => {\n if (!sendExitComplete || !isExiting || !hostRef.current) return\n const node = hostRef.current as HTMLElement\n const onFinishAnimation = () => {\n sendExitComplete?.()\n }\n node.addEventListener('transitionend', onFinishAnimation)\n node.addEventListener('transitioncancel', onFinishAnimation)\n return () => {\n node.removeEventListener('transitionend', onFinishAnimation)\n node.addEventListener('transitioncancel', onFinishAnimation)\n }\n }, [sendExitComplete, isExiting])\n\n // add css transition\n style.transition = `${keys} ${animation}`\n\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n // eslint-disable-next-line no-console\n console.log('CSS animation', style, { isEntering, isExiting })\n }\n\n return useMemo(() => {\n return { style }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [JSON.stringify(style)])\n },\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAA0B,OAAO,MAAM,iCAAiC;AACxE,SAAS,mBAAmB;AAC5B,SAAS,SAAS,cAAc;AAEzB,SAAS,iBAAmC,YAAmC;AACpF,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IAEA,kBAAkB,SAAS;AACzB,YAAM,MAAM,OAAO,OAAO;AAC1B,aAAO;AAAA,QACL,cAAc;AACZ,iBAAO;AAAA,QACT;AAAA,QACA,WAAW;AACT,iBAAO,IAAI;AAAA,QACb;AAAA,QACA,SAAS,MAAM;AACb,cAAI,UAAU;AAAA,QAChB;AAAA,QACA,OAAO;AAAA,QAAC;AAAA,MACV;AAAA,IACF;AAAA,IAEA,0BAA0B,KAAK,UAAU;AAAA,IAEzC;AAAA,IAEA,uBAAuB,KAAK,UAAU;AACpC,aAAO,SAAS,IAAI,SAAS,CAAC;AAAA,IAChC;AAAA,IAEA,eAAe,CAAC,EAAE,OAAO,UAAU,OAAO,OAAO,QAAQ,MAAM;AAC7D,YAAM,aAAa,CAAC,CAAC,MAAM;AAC3B,YAAM,YAAY,WAAW,OAAO;AACpC,YAAM,mBAAmB,WAAW;AACpC,YAAM,eAAe,MAAM,QAAQ,MAAM,SAAS,IAAI,MAAM,UAAU,KAAK,MAAM;AACjF,YAAM,YAAY,WAAW;AAC7B,UAAI,CAAC,WAAW;AACd,eAAO;AAAA,MACT;AAEA,YAAM,OAAO,MAAM,cAAc,MAAM,YAAY,KAAK,GAAG,IAAI;AAE/D,gCAA0B,MAAM;AAC9B,YAAI,CAAC,oBAAoB,CAAC,aAAa,CAAC,QAAQ;AAAS;AACzD,cAAM,OAAO,QAAQ;AACrB,cAAM,oBAAoB,MAAM;AAC9B,6BAAmB;AAAA,QACrB;AACA,aAAK,iBAAiB,iBAAiB,iBAAiB;AACxD,aAAK,iBAAiB,oBAAoB,iBAAiB;AAC3D,eAAO,MAAM;AACX,eAAK,oBAAoB,iBAAiB,iBAAiB;AAC3D,eAAK,iBAAiB,oBAAoB,iBAAiB;AAAA,QAC7D;AAAA,MACF,GAAG,CAAC,kBAAkB,SAAS,CAAC;AAGhC,YAAM,aAAa,GAAG,QAAQ;AAE9B,UAAI,QAAQ,IAAI,aAAa,iBAAiB,MAAM,UAAU;AAE5D,gBAAQ,IAAI,iBAAiB,OAAO,EAAE,YAAY,UAAU,CAAC;AAAA,MAC/D;AAEA,aAAO,QAAQ,MAAM;AACnB,eAAO,EAAE,MAAM;AAAA,MAEjB,GAAG,CAAC,KAAK,UAAU,KAAK,CAAC,CAAC;AAAA,IAC5B;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/jsx/index.js
CHANGED
|
File without changes
|
package/dist/jsx/index.js.map
CHANGED
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/animations-css",
|
|
3
|
-
"version": "1.0.1-
|
|
3
|
+
"version": "1.0.1-rc.0.1",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"types": "./types/index.d.ts",
|
|
8
8
|
"main": "dist/cjs",
|
|
9
9
|
"module": "dist/esm",
|
|
10
|
-
"module:jsx": "dist/jsx",
|
|
11
10
|
"files": [
|
|
12
11
|
"src",
|
|
13
12
|
"types",
|
|
14
13
|
"dist"
|
|
15
14
|
],
|
|
16
15
|
"dependencies": {
|
|
17
|
-
"@tamagui/core": "^1.0.1-
|
|
16
|
+
"@tamagui/core": "^1.0.1-rc.0.1",
|
|
17
|
+
"@tamagui/use-presence": "^1.0.1-rc.0.1"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@tamagui/build": "^1.0.1-
|
|
20
|
+
"@tamagui/build": "^1.0.1-rc.0.1"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build": "tamagui-build",
|
package/src/createAnimations.tsx
CHANGED
|
@@ -1,25 +1,76 @@
|
|
|
1
|
-
import { AnimationDriver } from '@tamagui/core'
|
|
1
|
+
import { AnimationDriver, Stack, Text, useIsomorphicLayoutEffect } from '@tamagui/core'
|
|
2
|
+
import { usePresence } from '@tamagui/use-presence'
|
|
3
|
+
import { useMemo, useRef } from 'react'
|
|
2
4
|
|
|
3
5
|
export function createAnimations<A extends Object>(animations: A): AnimationDriver<A> {
|
|
4
6
|
return {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Text: 'span',
|
|
7
|
+
View: Stack,
|
|
8
|
+
Text: Text,
|
|
8
9
|
animations,
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
usePresence,
|
|
11
|
+
|
|
12
|
+
useAnimatedNumber(initial) {
|
|
13
|
+
const val = useRef(initial)
|
|
14
|
+
return {
|
|
15
|
+
getInstance() {
|
|
16
|
+
return val
|
|
17
|
+
},
|
|
18
|
+
getValue() {
|
|
19
|
+
return val.current
|
|
20
|
+
},
|
|
21
|
+
setValue(next) {
|
|
22
|
+
val.current = next
|
|
23
|
+
},
|
|
24
|
+
stop() {},
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
useAnimatedNumberReaction(val, reaction) {
|
|
29
|
+
// TODO use event listeners, would need access to the corresponsing node...
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
useAnimatedNumberStyle(val, getStyle) {
|
|
33
|
+
return getStyle(val.getValue())
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
useAnimations: ({ props, presence, style, state, hostRef }) => {
|
|
37
|
+
const isEntering = !!state.unmounted
|
|
38
|
+
const isExiting = presence?.[0] === false
|
|
39
|
+
const sendExitComplete = presence?.[1]
|
|
40
|
+
const animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation
|
|
41
|
+
const animation = animations[animationKey as any]
|
|
11
42
|
if (!animation) {
|
|
12
|
-
|
|
43
|
+
return null
|
|
13
44
|
}
|
|
14
45
|
|
|
15
46
|
const keys = props.animateOnly ? props.animateOnly.join(' ') : 'all'
|
|
16
47
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
48
|
+
useIsomorphicLayoutEffect(() => {
|
|
49
|
+
if (!sendExitComplete || !isExiting || !hostRef.current) return
|
|
50
|
+
const node = hostRef.current as HTMLElement
|
|
51
|
+
const onFinishAnimation = () => {
|
|
52
|
+
sendExitComplete?.()
|
|
53
|
+
}
|
|
54
|
+
node.addEventListener('transitionend', onFinishAnimation)
|
|
55
|
+
node.addEventListener('transitioncancel', onFinishAnimation)
|
|
56
|
+
return () => {
|
|
57
|
+
node.removeEventListener('transitionend', onFinishAnimation)
|
|
58
|
+
node.addEventListener('transitioncancel', onFinishAnimation)
|
|
59
|
+
}
|
|
60
|
+
}, [sendExitComplete, isExiting])
|
|
61
|
+
|
|
62
|
+
// add css transition
|
|
63
|
+
style.transition = `${keys} ${animation}`
|
|
64
|
+
|
|
65
|
+
if (process.env.NODE_ENV === 'development' && props['debug']) {
|
|
66
|
+
// eslint-disable-next-line no-console
|
|
67
|
+
console.log('CSS animation', style, { isEntering, isExiting })
|
|
22
68
|
}
|
|
69
|
+
|
|
70
|
+
return useMemo(() => {
|
|
71
|
+
return { style }
|
|
72
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
73
|
+
}, [JSON.stringify(style)])
|
|
23
74
|
},
|
|
24
75
|
}
|
|
25
76
|
}
|
|
File without changes
|
package/types/index.d.ts
CHANGED
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createAnimations.d.ts","sourceRoot":"","sources":["../src/createAnimations.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAE/C,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,UAAU,EAAE,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAsBpF"}
|
package/types/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA"}
|