@tamagui/animations-css 1.0.1-beta.99 → 1.0.1-rc.0

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,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
- avoidClasses: false,
40
- View: "div",
41
- Text: "span",
29
+ View: import_core.Stack,
30
+ Text: import_core.Text,
42
31
  animations,
43
- useAnimations: (props, { getStyle }) => {
44
- const animation = animations[props.animation];
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
- throw new Error(`no animation found: ${props.animation}`);
61
+ return null;
47
62
  }
48
63
  const keys = props.animateOnly ? props.animateOnly.join(" ") : "all";
49
- return {
50
- style: __spreadValues({
51
- transition: `${keys} ${animation}`
52
- }, getStyle())
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 avoidClasses: false,\n View: 'div',\n Text: 'span',\n animations,\n useAnimations: (props, { getStyle }) => {\n const animation = animations[props.animation as any]\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;",
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
@@ -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,36 +1,64 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
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
- avoidClasses: false,
20
- View: "div",
21
- Text: "span",
6
+ View: Stack,
7
+ Text,
22
8
  animations,
23
- useAnimations: (props, { getStyle }) => {
24
- const animation = animations[props.animation];
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
- throw new Error(`no animation found: ${props.animation}`);
38
+ return null;
27
39
  }
28
40
  const keys = props.animateOnly ? props.animateOnly.join(" ") : "all";
29
- return {
30
- style: __spreadValues({
31
- transition: `${keys} ${animation}`
32
- }, getStyle())
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 avoidClasses: false,\n View: 'div',\n Text: 'span',\n animations,\n useAnimations: (props, { getStyle }) => {\n const animation = animations[props.animation as any]\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,WACpB,SAAS;AAAA,MAEhB;AAAA,IACF;AAAA,EACF;AACF;",
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
@@ -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,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
- avoidClasses: false,
4
- View: "div",
5
- Text: "span",
6
+ View: Stack,
7
+ Text,
6
8
  animations,
7
- useAnimations: (props, { getStyle }) => {
8
- const animation = animations[props.animation];
9
- if (!animation) {
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
- style: {
15
- transition: `${keys} ${animation}`,
16
- ...getStyle()
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 avoidClasses: false,\n View: 'div',\n Text: 'span',\n animations,\n useAnimations: (props, { getStyle }) => {\n const animation = animations[props.animation as any]\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,UACvB,GAAG,SAAS;AAAA,QACd;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
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
@@ -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
  }
package/package.json CHANGED
@@ -1,23 +1,23 @@
1
1
  {
2
2
  "name": "@tamagui/animations-css",
3
- "version": "1.0.1-beta.99",
3
+ "version": "1.0.1-rc.0",
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-beta.99"
16
+ "@tamagui/core": "^1.0.1-rc.0",
17
+ "@tamagui/use-presence": "^1.0.1-rc.0"
18
18
  },
19
19
  "devDependencies": {
20
- "@tamagui/build": "^1.0.1-beta.99"
20
+ "@tamagui/build": "^1.0.1-rc.0"
21
21
  },
22
22
  "scripts": {
23
23
  "build": "tamagui-build",
@@ -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
- avoidClasses: false,
6
- View: 'div',
7
- Text: 'span',
7
+ View: Stack,
8
+ Text: Text,
8
9
  animations,
9
- useAnimations: (props, { getStyle }) => {
10
- const animation = animations[props.animation as any]
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
- throw new Error(`no animation found: ${props.animation}`)
43
+ return null
13
44
  }
14
45
 
15
46
  const keys = props.animateOnly ? props.animateOnly.join(' ') : 'all'
16
47
 
17
- return {
18
- style: {
19
- transition: `${keys} ${animation}`,
20
- ...getStyle(),
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"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA"}