@tamagui/animations-css 1.0.1-beta.19 → 1.0.1-beta.191

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,79 @@ __export(createAnimations_exports, {
35
21
  createAnimations: () => createAnimations
36
22
  });
37
23
  module.exports = __toCommonJS(createAnimations_exports);
24
+ var import_animate_presence = require("@tamagui/animate-presence");
25
+ var import_core = require("@tamagui/core");
26
+ var import_react = require("react");
38
27
  function createAnimations(animations) {
39
28
  return {
40
29
  avoidClasses: false,
41
- View: "div",
42
- Text: "span",
30
+ View: import_core.Stack,
31
+ Text: import_core.Text,
43
32
  animations,
44
- useAnimations: (props, { getStyle }) => {
45
- const animation = animations[props.animation];
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, { getStyle, state, hostRef }) => {
55
+ const [isPresent, sendExitComplete] = (0, import_animate_presence.usePresence)();
56
+ const presence = (0, import_react.useContext)(import_animate_presence.PresenceContext);
57
+ const isExiting = isPresent === false;
58
+ const isEntering = !state.mounted;
59
+ const animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation;
60
+ const animation = animations[animationKey];
46
61
  if (!animation) {
47
- throw new Error(`no animation found: ${props.animation}`);
62
+ return null;
48
63
  }
49
64
  const keys = props.animateOnly ? props.animateOnly.join(" ") : "all";
50
- return {
51
- style: __spreadValues({
52
- transition: `${keys} ${animation}`
53
- }, getStyle())
65
+ (0, import_core.useIsomorphicLayoutEffect)(() => {
66
+ if (!sendExitComplete || !isExiting || !hostRef.current)
67
+ return;
68
+ const node = hostRef.current;
69
+ const onFinishAnimation = () => {
70
+ sendExitComplete == null ? void 0 : sendExitComplete();
71
+ };
72
+ node.addEventListener("transitionend", onFinishAnimation);
73
+ node.addEventListener("transitioncancel", onFinishAnimation);
74
+ return () => {
75
+ node.removeEventListener("transitionend", onFinishAnimation);
76
+ node.addEventListener("transitioncancel", onFinishAnimation);
77
+ };
78
+ }, [sendExitComplete, isExiting]);
79
+ const style = {
80
+ transition: `${keys} ${animation}`,
81
+ ...getStyle({
82
+ isEntering,
83
+ isExiting,
84
+ exitVariant: presence == null ? void 0 : presence.exitVariant,
85
+ enterVariant: presence == null ? void 0 : presence.enterVariant
86
+ })
54
87
  };
88
+ if (process.env.NODE_ENV === "development" && props["debug"]) {
89
+ console.log("CSS animation", style, { isEntering, isExiting });
90
+ }
91
+ return (0, import_react.useMemo)(() => {
92
+ return { style };
93
+ }, [JSON.stringify(style)]);
55
94
  }
56
95
  };
57
96
  }
58
- __name(createAnimations, "createAnimations");
59
97
  // Annotate the CommonJS export names for ESM import in node:
60
98
  0 && (module.exports = {
61
99
  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 { PresenceContext, usePresence } from '@tamagui/animate-presence'\nimport { AnimationDriver, Stack, Text, useIsomorphicLayoutEffect } from '@tamagui/core'\nimport { useContext, useEffect, useLayoutEffect, useMemo, useRef } from 'react'\n\nexport function createAnimations<A extends Object>(animations: A): AnimationDriver<A> {\n return {\n avoidClasses: false,\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 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,8BAA6C;AAC7C,kBAAwE;AACxE,mBAAwE;AAEjE,SAAS,iBAAmC,YAAmC;AACpF,SAAO;AAAA,IACL,cAAc;AAAA,IACd,MAAM;AAAA,IACN,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AA,QACvB,GAAG,SAAS;AAAA,UACV;AAAA,UACA;AAAA,UACA,aAAa,qCAAU;AAAA,UACvB,cAAc,qCAAU;AAAA,QAC1B,CAAC;AAAA,MACH;AAEA,UAAI,QAAQ,IAAI,aAAa,iBAAiB,MAAM,UAAU;AAC5D,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,76 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
1
+ import { PresenceContext, usePresence } from "@tamagui/animate-presence";
2
+ import { Stack, Text, useIsomorphicLayoutEffect } from "@tamagui/core";
3
+ import { useContext, useMemo, useRef } from "react";
3
4
  function createAnimations(animations) {
4
5
  return {
5
6
  avoidClasses: false,
6
- View: "div",
7
- Text: "span",
7
+ View: Stack,
8
+ Text,
8
9
  animations,
9
- useAnimations: (props, { getStyle }) => {
10
- const animation = animations[props.animation];
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, { getStyle, state, hostRef }) => {
32
+ const [isPresent, sendExitComplete] = usePresence();
33
+ const presence = useContext(PresenceContext);
34
+ const isExiting = isPresent === false;
35
+ const isEntering = !state.mounted;
36
+ const animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation;
37
+ const animation = animations[animationKey];
11
38
  if (!animation) {
12
- throw new Error(`no animation found: ${props.animation}`);
39
+ return null;
13
40
  }
14
41
  const keys = props.animateOnly ? props.animateOnly.join(" ") : "all";
15
- return {
16
- style: {
17
- transition: `${keys} ${animation}`,
18
- ...getStyle()
19
- }
42
+ useIsomorphicLayoutEffect(() => {
43
+ if (!sendExitComplete || !isExiting || !hostRef.current)
44
+ return;
45
+ const node = hostRef.current;
46
+ const onFinishAnimation = () => {
47
+ sendExitComplete == null ? void 0 : sendExitComplete();
48
+ };
49
+ node.addEventListener("transitionend", onFinishAnimation);
50
+ node.addEventListener("transitioncancel", onFinishAnimation);
51
+ return () => {
52
+ node.removeEventListener("transitionend", onFinishAnimation);
53
+ node.addEventListener("transitioncancel", onFinishAnimation);
54
+ };
55
+ }, [sendExitComplete, isExiting]);
56
+ const style = {
57
+ transition: `${keys} ${animation}`,
58
+ ...getStyle({
59
+ isEntering,
60
+ isExiting,
61
+ exitVariant: presence == null ? void 0 : presence.exitVariant,
62
+ enterVariant: presence == null ? void 0 : presence.enterVariant
63
+ })
20
64
  };
65
+ if (process.env.NODE_ENV === "development" && props["debug"]) {
66
+ console.log("CSS animation", style, { isEntering, isExiting });
67
+ }
68
+ return useMemo(() => {
69
+ return { style };
70
+ }, [JSON.stringify(style)]);
21
71
  }
22
72
  };
23
73
  }
24
- __name(createAnimations, "createAnimations");
25
74
  export {
26
75
  createAnimations
27
76
  };
@@ -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 { PresenceContext, usePresence } from '@tamagui/animate-presence'\nimport { AnimationDriver, Stack, Text, useIsomorphicLayoutEffect } from '@tamagui/core'\nimport { useContext, useEffect, useLayoutEffect, useMemo, useRef } from 'react'\n\nexport function createAnimations<A extends Object>(animations: A): AnimationDriver<A> {\n return {\n avoidClasses: false,\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 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,SAAS,iBAAiB,mBAAmB;AAC7C,SAA0B,OAAO,MAAM,iCAAiC;AACxE,SAAS,YAAwC,SAAS,cAAc;AAEjE,SAAS,iBAAmC,YAAmC;AACpF,SAAO;AAAA,IACL,cAAc;AAAA,IACd,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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IAAI,aAAa,iBAAiB,MAAM,UAAU;AAC5D,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
@@ -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,77 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
1
+ import { PresenceContext, usePresence } from "@tamagui/animate-presence";
2
+ import { Stack, Text, useIsomorphicLayoutEffect } from "@tamagui/core";
3
+ import { useContext, useMemo, useRef } from "react";
3
4
  function createAnimations(animations) {
4
5
  return {
5
6
  avoidClasses: false,
6
- View: "div",
7
- Text: "span",
7
+ View: Stack,
8
+ Text,
8
9
  animations,
9
- useAnimations: (props, { getStyle }) => {
10
- const animation = animations[props.animation];
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, { getStyle, state, hostRef }) => {
32
+ const [isPresent, sendExitComplete] = usePresence();
33
+ const presence = useContext(PresenceContext);
34
+ const isExiting = isPresent === false;
35
+ const isEntering = !state.mounted;
36
+ const animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation;
37
+ const animation = animations[animationKey];
11
38
  if (!animation) {
12
- throw new Error(`no animation found: ${props.animation}`);
39
+ return null;
13
40
  }
14
41
  const keys = props.animateOnly ? props.animateOnly.join(" ") : "all";
15
- return {
16
- style: {
17
- transition: `${keys} ${animation}`,
18
- ...getStyle()
19
- }
42
+ useIsomorphicLayoutEffect(() => {
43
+ if (!sendExitComplete || !isExiting || !hostRef.current)
44
+ return;
45
+ const node = hostRef.current;
46
+ const onFinishAnimation = () => {
47
+ sendExitComplete?.();
48
+ };
49
+ node.addEventListener("transitionend", onFinishAnimation);
50
+ node.addEventListener("transitioncancel", onFinishAnimation);
51
+ return () => {
52
+ node.removeEventListener("transitionend", onFinishAnimation);
53
+ node.addEventListener("transitioncancel", onFinishAnimation);
54
+ };
55
+ }, [sendExitComplete, isExiting]);
56
+ const style = {
57
+ transition: `${keys} ${animation}`,
58
+ ...getStyle({
59
+ isEntering,
60
+ isExiting,
61
+ exitVariant: presence?.exitVariant,
62
+ enterVariant: presence?.enterVariant
63
+ })
20
64
  };
65
+ if (process.env.NODE_ENV === "development" && props["debug"]) {
66
+ console.log("CSS animation", style, { isEntering, isExiting });
67
+ }
68
+ return useMemo(() => {
69
+ return { style };
70
+ }, [JSON.stringify(style)]);
21
71
  }
22
72
  };
23
73
  }
24
- __name(createAnimations, "createAnimations");
25
74
  export {
26
75
  createAnimations
27
76
  };
77
+ //# sourceMappingURL=createAnimations.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/createAnimations.tsx"],
4
+ "sourcesContent": ["import { PresenceContext, usePresence } from '@tamagui/animate-presence'\nimport { AnimationDriver, Stack, Text, useIsomorphicLayoutEffect } from '@tamagui/core'\nimport { useContext, useEffect, useLayoutEffect, useMemo, useRef } from 'react'\n\nexport function createAnimations<A extends Object>(animations: A): AnimationDriver<A> {\n return {\n avoidClasses: false,\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 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,SAAS,iBAAiB,mBAAmB;AAC7C,SAA0B,OAAO,MAAM,iCAAiC;AACxE,SAAS,YAAwC,SAAS,cAAc;AAEjE,SAAS,iBAAmC,YAAmC;AACpF,SAAO;AAAA,IACL,cAAc;AAAA,IACd,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IAEA,kBAAkB,SAAS;AACzB,YAAM,M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A,aAAa,UAAU;AAAA,UACvB,cAAc,UAAU;AAAA,QAC1B,CAAC;AAAA,MACH;AAEA,UAAI,QAAQ,IAAI,aAAa,iBAAiB,MAAM,UAAU;AAC5D,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.19",
3
+ "version": "1.0.1-beta.191",
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.19"
17
+ "@tamagui/animate-presence": "^1.0.1-beta.191",
18
+ "@tamagui/core": "^1.0.1-beta.191"
16
19
  },
17
20
  "devDependencies": {
18
- "@tamagui/build": "^1.0.1-beta.19"
21
+ "@tamagui/build": "^1.0.1-beta.191"
19
22
  },
20
23
  "scripts": {
21
24
  "build": "tamagui-build",
@@ -0,0 +1,83 @@
1
+ import { PresenceContext, usePresence } from '@tamagui/animate-presence'
2
+ import { AnimationDriver, Stack, Text, useIsomorphicLayoutEffect } from '@tamagui/core'
3
+ import { useContext, useEffect, useLayoutEffect, useMemo, useRef } from 'react'
4
+
5
+ export function createAnimations<A extends Object>(animations: A): AnimationDriver<A> {
6
+ return {
7
+ avoidClasses: false,
8
+ View: Stack,
9
+ Text: Text,
10
+ animations,
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, { getStyle, state, hostRef }) => {
37
+ const [isPresent, sendExitComplete] = usePresence()
38
+ const presence = useContext(PresenceContext)
39
+ const isExiting = isPresent === false
40
+ const isEntering = !state.mounted
41
+ const animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation
42
+ const animation = animations[animationKey as any]
43
+ if (!animation) {
44
+ return null
45
+ }
46
+
47
+ const keys = props.animateOnly ? props.animateOnly.join(' ') : 'all'
48
+
49
+ useIsomorphicLayoutEffect(() => {
50
+ if (!sendExitComplete || !isExiting || !hostRef.current) return
51
+ const node = hostRef.current as HTMLElement
52
+ const onFinishAnimation = () => {
53
+ sendExitComplete?.()
54
+ }
55
+ node.addEventListener('transitionend', onFinishAnimation)
56
+ node.addEventListener('transitioncancel', onFinishAnimation)
57
+ return () => {
58
+ node.removeEventListener('transitionend', onFinishAnimation)
59
+ node.addEventListener('transitioncancel', onFinishAnimation)
60
+ }
61
+ }, [sendExitComplete, isExiting])
62
+
63
+ const style = {
64
+ transition: `${keys} ${animation}`,
65
+ ...getStyle({
66
+ isEntering,
67
+ isExiting,
68
+ exitVariant: presence?.exitVariant,
69
+ enterVariant: presence?.enterVariant,
70
+ }),
71
+ }
72
+
73
+ if (process.env.NODE_ENV === 'development' && props['debug']) {
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"}