@tamagui/animations-css 1.2.8 → 1.2.10

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.
@@ -0,0 +1,72 @@
1
+ import {
2
+ Stack,
3
+ Text,
4
+ useIsomorphicLayoutEffect
5
+ } from "@tamagui/core";
6
+ import { usePresence } from "@tamagui/use-presence";
7
+ import { useMemo, useRef } from "react";
8
+ function createAnimations(animations) {
9
+ return {
10
+ View: Stack,
11
+ Text,
12
+ animations,
13
+ usePresence,
14
+ useAnimatedNumber(initial) {
15
+ const val = useRef(initial);
16
+ return {
17
+ getInstance() {
18
+ return val;
19
+ },
20
+ getValue() {
21
+ return val.current;
22
+ },
23
+ setValue(next) {
24
+ val.current = next;
25
+ },
26
+ stop() {
27
+ }
28
+ };
29
+ },
30
+ useAnimatedNumberReaction(val, reaction) {
31
+ },
32
+ useAnimatedNumberStyle(val, getStyle) {
33
+ return getStyle(val.getValue());
34
+ },
35
+ useAnimations: ({ props, presence, style, state, hostRef }) => {
36
+ const isEntering = !!state.unmounted;
37
+ const isExiting = (presence == null ? void 0 : presence[0]) === false;
38
+ const sendExitComplete = presence == null ? void 0 : presence[1];
39
+ const animationKey = Array.isArray(props.animation) ? props.animation[0] : props.animation;
40
+ const animation = animations[animationKey];
41
+ if (!animation) {
42
+ return null;
43
+ }
44
+ const keys = props.animateOnly ? props.animateOnly.join(" ") : "all";
45
+ useIsomorphicLayoutEffect(() => {
46
+ if (!sendExitComplete || !isExiting || !hostRef.current)
47
+ return;
48
+ const node = hostRef.current;
49
+ const onFinishAnimation = () => {
50
+ sendExitComplete == null ? void 0 : sendExitComplete();
51
+ };
52
+ node.addEventListener("transitionend", onFinishAnimation);
53
+ node.addEventListener("transitioncancel", onFinishAnimation);
54
+ return () => {
55
+ node.removeEventListener("transitionend", onFinishAnimation);
56
+ node.addEventListener("transitioncancel", onFinishAnimation);
57
+ };
58
+ }, [sendExitComplete, isExiting]);
59
+ style.transition = `${keys} ${animation}`;
60
+ if (process.env.NODE_ENV === "development" && props["debug"]) {
61
+ console.log("CSS animation", style, { isEntering, isExiting });
62
+ }
63
+ return useMemo(() => {
64
+ return { style };
65
+ }, [JSON.stringify(style)]);
66
+ }
67
+ };
68
+ }
69
+ export {
70
+ createAnimations
71
+ };
72
+ //# sourceMappingURL=createAnimations.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/createAnimations.tsx"],
4
+ "sourcesContent": ["import {\n AnimationDriver,\n Stack,\n Text,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport { usePresence } from '@tamagui/use-presence'\nimport { useMemo, useRef } from 'react'\n\nexport function createAnimations<A extends Object>(\n animations: A,\n): 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)\n ? props.animation[0]\n : 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,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,SAAS,cAAc;AAEzB,SAAS,iBACd,YACoB;AACpB,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,IAC9C,MAAM,UAAU,CAAC,IACjB,MAAM;AACV,YAAM,YAAY,WAAW,YAAmB;AAChD,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,OAAO,GAAG;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
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./createAnimations";
2
+ //# sourceMappingURL=index.mjs.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/animations-css",
3
- "version": "1.2.8",
3
+ "version": "1.2.10",
4
4
  "source": "src/index.ts",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",
@@ -13,11 +13,11 @@
13
13
  "dist"
14
14
  ],
15
15
  "dependencies": {
16
- "@tamagui/core": "^1.2.8",
17
- "@tamagui/use-presence": "^1.2.8"
16
+ "@tamagui/core": "^1.2.10",
17
+ "@tamagui/use-presence": "^1.2.10"
18
18
  },
19
19
  "devDependencies": {
20
- "@tamagui/build": "^1.2.8"
20
+ "@tamagui/build": "^1.2.10"
21
21
  },
22
22
  "scripts": {
23
23
  "build": "tamagui-build",