@tamagui/animations-css 1.0.1-beta.20 → 1.0.1-beta.201

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.
@@ -1,22 +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
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
20
6
  var __export = (target, all) => {
21
7
  for (var name in all)
22
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -35,27 +21,78 @@ __export(createAnimations_exports, {
35
21
  createAnimations: () => createAnimations
36
22
  });
37
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");
38
27
  function createAnimations(animations) {
39
28
  return {
40
- avoidClasses: false,
41
- View: "div",
42
- Text: "span",
29
+ View: import_core.Stack,
30
+ Text: import_core.Text,
43
31
  animations,
44
- useAnimations: (props, { getStyle }) => {
45
- const animation = animations[props.animation];
32
+ useAnimatedNumber(initial) {
33
+ const val = (0, import_react.useRef)(initial);
34
+ return {
35
+ getInstance() {
36
+ return val;
37
+ },
38
+ getValue() {
39
+ return val.current;
40
+ },
41
+ setValue(next) {
42
+ val.current = next;
43
+ },
44
+ stop() {
45
+ }
46
+ };
47
+ },
48
+ useAnimatedNumberReaction(val, reaction) {
49
+ },
50
+ useAnimatedNumberStyle(val, getStyle) {
51
+ return getStyle(val.getValue());
52
+ },
53
+ useAnimations: (props, { getStyle, state, hostRef }) => {
54
+ const [isPresent, sendExitComplete] = (0, import_use_presence.usePresence)();
55
+ const presence = (0, import_react.useContext)(import_use_presence.PresenceContext);
56
+ const isExiting = isPresent === false;
57
+ const isEntering = !state.mounted;
58
+ const animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation;
59
+ const animation = animations[animationKey];
46
60
  if (!animation) {
47
- throw new Error(`no animation found: ${props.animation}`);
61
+ return null;
48
62
  }
49
63
  const keys = props.animateOnly ? props.animateOnly.join(" ") : "all";
50
- return {
51
- style: __spreadValues({
52
- transition: `${keys} ${animation}`
53
- }, getStyle())
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
+ const style = {
79
+ transition: `${keys} ${animation}`,
80
+ ...getStyle({
81
+ isEntering,
82
+ isExiting,
83
+ exitVariant: presence == null ? void 0 : presence.exitVariant,
84
+ enterVariant: presence == null ? void 0 : presence.enterVariant
85
+ })
54
86
  };
87
+ if (process.env.NODE_ENV === "development" && props["debug"]) {
88
+ console.log("CSS animation", style, { isEntering, isExiting });
89
+ }
90
+ return (0, import_react.useMemo)(() => {
91
+ return { style };
92
+ }, [JSON.stringify(style)]);
55
93
  }
56
94
  };
57
95
  }
58
- __name(createAnimations, "createAnimations");
59
96
  // Annotate the CommonJS export names for ESM import in node:
60
97
  0 && (module.exports = {
61
98
  createAnimations
@@ -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 avoidClasses: false,\n View: 'div',\n Text: 'span',\n animations,\n useAnimations: (props, { getStyle }) => {\n const animation = animations[props.animation]\n if (!animation) {\n throw new Error(`no animation found: ${props.animation}`)\n }\n\n const keys = props.animateOnly ? props.animateOnly.join(' ') : 'all'\n\n return {\n style: {\n transition: `${keys} ${animation}`,\n ...getStyle(),\n },\n }\n },\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,0BAA4C,YAAmC;AACpF,SAAO;AAAA,IACL,cAAc;AAAA,IACd,MAAM;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA,eAAe,CAAC,OAAO,EAAE,eAAe;AACtC,YAAM,YAAY,WAAW,MAAM;AACnC,UAAI,CAAC,WAAW;AACd,cAAM,IAAI,MAAM,uBAAuB,MAAM,WAAW;AAAA,MAC1D;AAEA,YAAM,OAAO,MAAM,cAAc,MAAM,YAAY,KAAK,GAAG,IAAI;AAE/D,aAAO;AAAA,QACL,OAAO;AAAA,UACL,YAAY,GAAG,QAAQ;AAAA,WACpB,SAAS;AAAA,MAEhB;AAAA,IACF;AAAA,EACF;AACF;AAtBgB;",
4
+ "sourcesContent": ["import { AnimationDriver, Stack, Text, useIsomorphicLayoutEffect } from '@tamagui/core'\nimport { PresenceContext, usePresence } from '@tamagui/use-presence'\nimport { useContext, 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\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, { getStyle, state, hostRef }) => {\n const [isPresent, sendExitComplete] = usePresence()\n const presence = useContext(PresenceContext)\n const isExiting = isPresent === false\n const isEntering = !state.mounted\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 const style = {\n transition: `${keys} ${animation}`,\n ...getStyle({\n isEntering,\n isExiting,\n exitVariant: presence?.exitVariant,\n enterVariant: presence?.enterVariant,\n }),\n }\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,0BAA6C;AAC7C,mBAA4C;AAErC,SAAS,iBAAmC,YAAmC;AACpF,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IAEA,kBAAkB,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,UACA;AAAA,UACA,aAAa,qCAAU;AAAA,UACvB,cAAc,qCAAU;AAAA,QAC1B,CAAC;AAAA,MACH;AAEA,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
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.tsx"],
4
4
  "sourcesContent": ["export * from './createAnimations'\n"],
5
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,+BAAd;",
5
+ "mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,+BAAd;",
6
6
  "names": []
7
7
  }
@@ -1,27 +1,75 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
1
+ import { Stack, Text, useIsomorphicLayoutEffect } from "@tamagui/core";
2
+ import { PresenceContext, usePresence } from "@tamagui/use-presence";
3
+ import { useContext, useMemo, useRef } from "react";
3
4
  function createAnimations(animations) {
4
5
  return {
5
- avoidClasses: false,
6
- View: "div",
7
- Text: "span",
6
+ View: Stack,
7
+ Text,
8
8
  animations,
9
- useAnimations: (props, { getStyle }) => {
10
- const animation = animations[props.animation];
9
+ useAnimatedNumber(initial) {
10
+ const val = useRef(initial);
11
+ return {
12
+ getInstance() {
13
+ return val;
14
+ },
15
+ getValue() {
16
+ return val.current;
17
+ },
18
+ setValue(next) {
19
+ val.current = next;
20
+ },
21
+ stop() {
22
+ }
23
+ };
24
+ },
25
+ useAnimatedNumberReaction(val, reaction) {
26
+ },
27
+ useAnimatedNumberStyle(val, getStyle) {
28
+ return getStyle(val.getValue());
29
+ },
30
+ useAnimations: (props, { getStyle, state, hostRef }) => {
31
+ const [isPresent, sendExitComplete] = usePresence();
32
+ const presence = useContext(PresenceContext);
33
+ const isExiting = isPresent === false;
34
+ const isEntering = !state.mounted;
35
+ const animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation;
36
+ const animation = animations[animationKey];
11
37
  if (!animation) {
12
- throw new Error(`no animation found: ${props.animation}`);
38
+ return null;
13
39
  }
14
40
  const keys = props.animateOnly ? props.animateOnly.join(" ") : "all";
15
- return {
16
- style: {
17
- transition: `${keys} ${animation}`,
18
- ...getStyle()
19
- }
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
+ const style = {
56
+ transition: `${keys} ${animation}`,
57
+ ...getStyle({
58
+ isEntering,
59
+ isExiting,
60
+ exitVariant: presence == null ? void 0 : presence.exitVariant,
61
+ enterVariant: presence == null ? void 0 : presence.enterVariant
62
+ })
20
63
  };
64
+ if (process.env.NODE_ENV === "development" && props["debug"]) {
65
+ console.log("CSS animation", style, { isEntering, isExiting });
66
+ }
67
+ return useMemo(() => {
68
+ return { style };
69
+ }, [JSON.stringify(style)]);
21
70
  }
22
71
  };
23
72
  }
24
- __name(createAnimations, "createAnimations");
25
73
  export {
26
74
  createAnimations
27
75
  };
@@ -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 avoidClasses: false,\n View: 'div',\n Text: 'span',\n animations,\n useAnimations: (props, { getStyle }) => {\n const animation = animations[props.animation]\n if (!animation) {\n throw new Error(`no animation found: ${props.animation}`)\n }\n\n const keys = props.animateOnly ? props.animateOnly.join(' ') : 'all'\n\n return {\n style: {\n transition: `${keys} ${animation}`,\n ...getStyle(),\n },\n }\n },\n }\n}\n"],
5
- "mappings": ";;AAEO,0BAA4C,YAAmC;AACpF,SAAO;AAAA,IACL,cAAc;AAAA,IACd,MAAM;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA,eAAe,CAAC,OAAO,EAAE,eAAe;AACtC,YAAM,YAAY,WAAW,MAAM;AACnC,UAAI,CAAC,WAAW;AACd,cAAM,IAAI,MAAM,uBAAuB,MAAM,WAAW;AAAA,MAC1D;AAEA,YAAM,OAAO,MAAM,cAAc,MAAM,YAAY,KAAK,GAAG,IAAI;AAE/D,aAAO;AAAA,QACL,OAAO;AAAA,UACL,YAAY,GAAG,QAAQ;AAAA,aACpB,SAAS;AAAA,QACd;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAtBgB;",
4
+ "sourcesContent": ["import { AnimationDriver, Stack, Text, useIsomorphicLayoutEffect } from '@tamagui/core'\nimport { PresenceContext, usePresence } from '@tamagui/use-presence'\nimport { useContext, 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\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, { getStyle, state, hostRef }) => {\n const [isPresent, sendExitComplete] = usePresence()\n const presence = useContext(PresenceContext)\n const isExiting = isPresent === false\n const isEntering = !state.mounted\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 const style = {\n transition: `${keys} ${animation}`,\n ...getStyle({\n isEntering,\n isExiting,\n exitVariant: presence?.exitVariant,\n enterVariant: presence?.enterVariant,\n }),\n }\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,iBAAiB,mBAAmB;AAC7C,SAAS,YAAY,SAAS,cAAc;AAErC,SAAS,iBAAmC,YAAmC;AACpF,SAAO;AAAA,IACL,MAAM;AAAA,IACN;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,UA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E,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
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.tsx"],
4
4
  "sourcesContent": ["export * from './createAnimations'\n"],
5
- "mappings": "AAAA;",
5
+ "mappings": "AAAA,cAAc;",
6
6
  "names": []
7
7
  }
@@ -1,27 +1,76 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
1
+ import { Stack, Text, useIsomorphicLayoutEffect } from "@tamagui/core";
2
+ import { PresenceContext, usePresence } from "@tamagui/use-presence";
3
+ import { useContext, useMemo, useRef } from "react";
3
4
  function createAnimations(animations) {
4
5
  return {
5
- avoidClasses: false,
6
- View: "div",
7
- Text: "span",
6
+ View: Stack,
7
+ Text,
8
8
  animations,
9
- useAnimations: (props, { getStyle }) => {
10
- const animation = animations[props.animation];
9
+ useAnimatedNumber(initial) {
10
+ const val = useRef(initial);
11
+ return {
12
+ getInstance() {
13
+ return val;
14
+ },
15
+ getValue() {
16
+ return val.current;
17
+ },
18
+ setValue(next) {
19
+ val.current = next;
20
+ },
21
+ stop() {
22
+ }
23
+ };
24
+ },
25
+ useAnimatedNumberReaction(val, reaction) {
26
+ },
27
+ useAnimatedNumberStyle(val, getStyle) {
28
+ return getStyle(val.getValue());
29
+ },
30
+ useAnimations: (props, { getStyle, state, hostRef }) => {
31
+ const [isPresent, sendExitComplete] = usePresence();
32
+ const presence = useContext(PresenceContext);
33
+ const isExiting = isPresent === false;
34
+ const isEntering = !state.mounted;
35
+ const animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation;
36
+ const animation = animations[animationKey];
11
37
  if (!animation) {
12
- throw new Error(`no animation found: ${props.animation}`);
38
+ return null;
13
39
  }
14
40
  const keys = props.animateOnly ? props.animateOnly.join(" ") : "all";
15
- return {
16
- style: {
17
- transition: `${keys} ${animation}`,
18
- ...getStyle()
19
- }
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
+ const style = {
56
+ transition: `${keys} ${animation}`,
57
+ ...getStyle({
58
+ isEntering,
59
+ isExiting,
60
+ exitVariant: presence?.exitVariant,
61
+ enterVariant: presence?.enterVariant
62
+ })
20
63
  };
64
+ if (process.env.NODE_ENV === "development" && props["debug"]) {
65
+ console.log("CSS animation", style, { isEntering, isExiting });
66
+ }
67
+ return useMemo(() => {
68
+ return { style };
69
+ }, [JSON.stringify(style)]);
21
70
  }
22
71
  };
23
72
  }
24
- __name(createAnimations, "createAnimations");
25
73
  export {
26
74
  createAnimations
27
75
  };
76
+ //# sourceMappingURL=createAnimations.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/createAnimations.tsx"],
4
+ "sourcesContent": ["import { AnimationDriver, Stack, Text, useIsomorphicLayoutEffect } from '@tamagui/core'\nimport { PresenceContext, usePresence } from '@tamagui/use-presence'\nimport { useContext, 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\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, { getStyle, state, hostRef }) => {\n const [isPresent, sendExitComplete] = usePresence()\n const presence = useContext(PresenceContext)\n const isExiting = isPresent === false\n const isEntering = !state.mounted\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 const style = {\n transition: `${keys} ${animation}`,\n ...getStyle({\n isEntering,\n isExiting,\n exitVariant: presence?.exitVariant,\n enterVariant: presence?.enterVariant,\n }),\n }\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,iBAAiB,mBAAmB;AAC7C,SAAS,YAAY,SAAS,cAAc;AAErC,SAAS,iBAAmC,YAAmC;AACpF,SAAO;AAAA,IACL,MAAM;AAAA,IACN;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;A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,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
+ "names": []
7
+ }
package/dist/jsx/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export * from "./createAnimations";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.tsx"],
4
+ "sourcesContent": ["export * from './createAnimations'\n"],
5
+ "mappings": "AAAA,cAAc;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,21 +1,24 @@
1
1
  {
2
2
  "name": "@tamagui/animations-css",
3
- "version": "1.0.1-beta.20",
3
+ "version": "1.0.1-beta.201",
4
4
  "source": "src/index.ts",
5
+ "sideEffects": false,
5
6
  "license": "MIT",
6
- "typings": "types",
7
+ "types": "./types/index.d.ts",
7
8
  "main": "dist/cjs",
8
9
  "module": "dist/esm",
9
10
  "module:jsx": "dist/jsx",
10
11
  "files": [
12
+ "src",
11
13
  "types",
12
14
  "dist"
13
15
  ],
14
16
  "dependencies": {
15
- "@tamagui/core": "^1.0.1-beta.20"
17
+ "@tamagui/core": "^1.0.1-beta.201",
18
+ "@tamagui/use-presence": "^1.0.1-beta.201"
16
19
  },
17
20
  "devDependencies": {
18
- "@tamagui/build": "^1.0.1-beta.20"
21
+ "@tamagui/build": "^1.0.1-beta.201"
19
22
  },
20
23
  "scripts": {
21
24
  "build": "tamagui-build",
@@ -0,0 +1,83 @@
1
+ import { AnimationDriver, Stack, Text, useIsomorphicLayoutEffect } from '@tamagui/core'
2
+ import { PresenceContext, usePresence } from '@tamagui/use-presence'
3
+ import { useContext, useMemo, useRef } from 'react'
4
+
5
+ export function createAnimations<A extends Object>(animations: A): AnimationDriver<A> {
6
+ return {
7
+ View: Stack,
8
+ Text: Text,
9
+ animations,
10
+
11
+ useAnimatedNumber(initial) {
12
+ const val = useRef(initial)
13
+ return {
14
+ getInstance() {
15
+ return val
16
+ },
17
+ getValue() {
18
+ return val.current
19
+ },
20
+ setValue(next) {
21
+ val.current = next
22
+ },
23
+ stop() {},
24
+ }
25
+ },
26
+
27
+ useAnimatedNumberReaction(val, reaction) {
28
+ // TODO use event listeners, would need access to the corresponsing node...
29
+ },
30
+
31
+ useAnimatedNumberStyle(val, getStyle) {
32
+ return getStyle(val.getValue())
33
+ },
34
+
35
+ useAnimations: (props, { getStyle, state, hostRef }) => {
36
+ const [isPresent, sendExitComplete] = usePresence()
37
+ const presence = useContext(PresenceContext)
38
+ const isExiting = isPresent === false
39
+ const isEntering = !state.mounted
40
+ const animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation
41
+ const animation = animations[animationKey as any]
42
+ if (!animation) {
43
+ return null
44
+ }
45
+
46
+ const keys = props.animateOnly ? props.animateOnly.join(' ') : 'all'
47
+
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
+ const style = {
63
+ transition: `${keys} ${animation}`,
64
+ ...getStyle({
65
+ isEntering,
66
+ isExiting,
67
+ exitVariant: presence?.exitVariant,
68
+ enterVariant: presence?.enterVariant,
69
+ }),
70
+ }
71
+
72
+ if (process.env.NODE_ENV === 'development' && props['debug']) {
73
+ // eslint-disable-next-line no-console
74
+ console.log('CSS animation', style, { isEntering, isExiting })
75
+ }
76
+
77
+ return useMemo(() => {
78
+ return { style }
79
+ // eslint-disable-next-line react-hooks/exhaustive-deps
80
+ }, [JSON.stringify(style)])
81
+ },
82
+ }
83
+ }
package/src/index.tsx ADDED
@@ -0,0 +1 @@
1
+ export * from './createAnimations'
@@ -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"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA"}