@tamagui/animations-motion 1.0.1-beta.18 → 1.0.1-beta.181

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,8 +1,8 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
6
  var __export = (target, all) => {
7
7
  for (var name in all)
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -18,21 +18,96 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var createAnimations_exports = {};
20
20
  __export(createAnimations_exports, {
21
- createAnimations: () => createAnimations
21
+ AnimatedText: () => AnimatedText,
22
+ AnimatedView: () => AnimatedView,
23
+ createAnimations: () => createAnimations,
24
+ useAnimatedNumber: () => useAnimatedNumber,
25
+ useAnimatedNumberReaction: () => useAnimatedNumberReaction,
26
+ useAnimatedNumberStyle: () => useAnimatedNumberStyle
22
27
  });
23
28
  module.exports = __toCommonJS(createAnimations_exports);
29
+ var import_animate_presence = require("@tamagui/animate-presence");
30
+ var import_react = require("react");
31
+ var import_react_native = require("react-native");
32
+ const AnimatedView = import_react_native.View;
33
+ const AnimatedText = import_react_native.Text;
34
+ function useAnimatedNumber(initial) {
35
+ const state = (0, import_react.useRef)(
36
+ null
37
+ );
38
+ if (!state.current) {
39
+ state.current = {
40
+ val: initial,
41
+ controls: null
42
+ };
43
+ }
44
+ return {
45
+ getInstance() {
46
+ return state.current.controls;
47
+ },
48
+ getValue() {
49
+ return state.current.val;
50
+ },
51
+ stop() {
52
+ var _a;
53
+ (_a = state.current.controls) == null ? void 0 : _a.stop();
54
+ },
55
+ setValue(next, { type, ...config } = { type: "spring" }) {
56
+ }
57
+ };
58
+ }
59
+ function useAnimatedNumberReaction(value, cb) {
60
+ }
61
+ function useAnimatedNumberStyle(value, getStyle) {
62
+ return getStyle(value.getInstance());
63
+ }
24
64
  function createAnimations(animations) {
25
- const useAnimations = /* @__PURE__ */ __name((props, extra) => {
26
- const { style, hoverStyle, pressStyle, exitStyle, onDidAnimate, delay } = extra;
27
- }, "useAnimations");
65
+ AnimatedView["displayName"] = "AnimatedView";
66
+ AnimatedText["displayName"] = "AnimatedText";
28
67
  return {
29
- useAnimations,
30
- animations
68
+ avoidClasses: true,
69
+ animations,
70
+ View: AnimatedView,
71
+ Text: AnimatedText,
72
+ useAnimatedNumber,
73
+ useAnimatedNumberReaction,
74
+ useAnimatedNumberStyle,
75
+ useAnimations: (props, helpers) => {
76
+ const { onDidAnimate, delay, getStyle, state } = helpers;
77
+ const [isPresent, sendExitComplete] = (0, import_animate_presence.usePresence)();
78
+ const presence = (0, import_react.useContext)(import_animate_presence.PresenceContext);
79
+ const isExiting = isPresent === false;
80
+ const isEntering = !state.mounted;
81
+ const all = getStyle({
82
+ isExiting,
83
+ isEntering,
84
+ exitVariant: presence == null ? void 0 : presence.exitVariant,
85
+ enterVariant: presence == null ? void 0 : presence.enterVariant
86
+ });
87
+ const args = [
88
+ JSON.stringify(all),
89
+ state.mounted,
90
+ state.hover,
91
+ state.press,
92
+ state.pressIn,
93
+ state.focus,
94
+ delay,
95
+ isPresent,
96
+ onDidAnimate,
97
+ presence == null ? void 0 : presence.exitVariant,
98
+ presence == null ? void 0 : presence.enterVariant
99
+ ];
100
+ return {};
101
+ }
31
102
  };
32
103
  }
33
- __name(createAnimations, "createAnimations");
34
104
  // Annotate the CommonJS export names for ESM import in node:
35
105
  0 && (module.exports = {
36
- createAnimations
106
+ AnimatedText,
107
+ AnimatedView,
108
+ createAnimations,
109
+ useAnimatedNumber,
110
+ useAnimatedNumberReaction,
111
+ useAnimatedNumberStyle
37
112
  });
38
113
  //# sourceMappingURL=createAnimations.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/createAnimations.tsx"],
4
- "sourcesContent": ["export function createAnimations<A>(animations: A): {\n useAnimations: any\n animations: A\n View?: any\n Text?: any\n} {\n const useAnimations = (props: Object, extra) => {\n const { style, hoverStyle, pressStyle, exitStyle, onDidAnimate, delay } = extra\n }\n return {\n useAnimations,\n animations,\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,0BAA6B,YAKlC;AACA,QAAM,gBAAgB,wBAAC,OAAe,UAAU;AAC9C,UAAM,EAAE,OAAO,YAAY,YAAY,WAAW,cAAc,UAAU;AAAA,EAC5E,GAFsB;AAGtB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAbgB;",
4
+ "sourcesContent": ["import { PresenceContext, usePresence } from '@tamagui/animate-presence'\nimport {\n AnimatedNumberStrategy,\n AnimationConfigType,\n AnimationDriver,\n AnimationProp,\n UniversalAnimatedNumber,\n isWeb,\n useEvent,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport { AnimationControls, animate } from 'motion'\nimport { useContext, useEffect, useMemo, useRef } from 'react'\nimport { Text, View } from 'react-native'\n\nexport const AnimatedView = View\nexport const AnimatedText = Text\n\nexport function useAnimatedNumber(\n initial: number\n): UniversalAnimatedNumber<AnimationControls | null> {\n const state = useRef(\n null as any as {\n val: number\n controls: AnimationControls | null\n }\n )\n if (!state.current) {\n state.current = {\n val: initial,\n controls: null,\n }\n }\n return {\n getInstance() {\n return state.current.controls\n },\n getValue() {\n return state.current.val\n },\n stop() {\n state.current.controls?.stop()\n },\n setValue(next: number, { type, ...config } = { type: 'spring' }) {\n // const val = state.current.val\n // if (type === 'direct') {\n // val.setValue(next)\n // } else if (type === 'spring') {\n // state.current.composite?.stop()\n // const composite = Animated.spring(val, {\n // ...config,\n // toValue: next,\n // useNativeDriver: !isWeb,\n // })\n // composite.start()\n // state.current.composite = composite\n // } else {\n // state.current.composite?.stop()\n // const composite = Animated.timing(val, {\n // ...config,\n // toValue: next,\n // useNativeDriver: !isWeb,\n // })\n // composite.start()\n // state.current.composite = composite\n // }\n },\n }\n}\n\nexport function useAnimatedNumberReaction(\n value: UniversalAnimatedNumber<any>,\n cb: (current: number) => void\n) {\n // const onChange = useEvent((current) => {\n // cb(current.value)\n // })\n // useEffect(() => {\n // const id = value.getInstance().addListener(onChange)\n // return () => {\n // value.getInstance().removeListener(id)\n // }\n // }, [value, onChange])\n}\n\nexport function useAnimatedNumberStyle<V extends UniversalAnimatedNumber<any>>(\n value: V,\n getStyle: (value: any) => any\n) {\n return getStyle(value.getInstance())\n}\n\n// @ts-ignore\nexport function createAnimations<A extends AnimationConfigType>(animations: A): AnimationDriver<A> {\n AnimatedView['displayName'] = 'AnimatedView'\n AnimatedText['displayName'] = 'AnimatedText'\n\n return {\n avoidClasses: true,\n animations,\n View: AnimatedView,\n Text: AnimatedText,\n useAnimatedNumber,\n useAnimatedNumberReaction,\n useAnimatedNumberStyle,\n useAnimations: (props, helpers) => {\n const { onDidAnimate, delay, getStyle, state } = helpers\n const [isPresent, sendExitComplete] = usePresence()\n const presence = useContext(PresenceContext)\n\n const isExiting = isPresent === false\n const isEntering = !state.mounted\n\n const all = getStyle({\n isExiting,\n isEntering,\n exitVariant: presence?.exitVariant,\n enterVariant: presence?.enterVariant,\n })\n\n const args = [\n JSON.stringify(all),\n state.mounted,\n state.hover,\n state.press,\n state.pressIn,\n state.focus,\n delay,\n isPresent,\n onDidAnimate,\n presence?.exitVariant,\n presence?.enterVariant,\n ]\n\n // return useMemo(() => {\n // return {\n // style: [nonAnimatedStyle, animatedStyle],\n // }\n // // eslint-disable-next-line react-hooks/exhaustive-deps\n // }, args)\n return {}\n },\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAA6C;A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,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN;AAAA,QACA;AAAA,QACA;AAAA,QACA,qCAAU;AAAA,QACV,qCAAU;AAAA,MACZ;AAQA,aAAO,CAAC;AAAA,IACV;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,16 +1,84 @@
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 { useContext, useRef } from "react";
3
+ import { Text, View } from "react-native";
4
+ const AnimatedView = View;
5
+ const AnimatedText = Text;
6
+ function useAnimatedNumber(initial) {
7
+ const state = useRef(
8
+ null
9
+ );
10
+ if (!state.current) {
11
+ state.current = {
12
+ val: initial,
13
+ controls: null
14
+ };
15
+ }
16
+ return {
17
+ getInstance() {
18
+ return state.current.controls;
19
+ },
20
+ getValue() {
21
+ return state.current.val;
22
+ },
23
+ stop() {
24
+ var _a;
25
+ (_a = state.current.controls) == null ? void 0 : _a.stop();
26
+ },
27
+ setValue(next, { type, ...config } = { type: "spring" }) {
28
+ }
29
+ };
30
+ }
31
+ function useAnimatedNumberReaction(value, cb) {
32
+ }
33
+ function useAnimatedNumberStyle(value, getStyle) {
34
+ return getStyle(value.getInstance());
35
+ }
3
36
  function createAnimations(animations) {
4
- const useAnimations = /* @__PURE__ */ __name((props, extra) => {
5
- const { style, hoverStyle, pressStyle, exitStyle, onDidAnimate, delay } = extra;
6
- }, "useAnimations");
37
+ AnimatedView["displayName"] = "AnimatedView";
38
+ AnimatedText["displayName"] = "AnimatedText";
7
39
  return {
8
- useAnimations,
9
- animations
40
+ avoidClasses: true,
41
+ animations,
42
+ View: AnimatedView,
43
+ Text: AnimatedText,
44
+ useAnimatedNumber,
45
+ useAnimatedNumberReaction,
46
+ useAnimatedNumberStyle,
47
+ useAnimations: (props, helpers) => {
48
+ const { onDidAnimate, delay, getStyle, state } = helpers;
49
+ const [isPresent, sendExitComplete] = usePresence();
50
+ const presence = useContext(PresenceContext);
51
+ const isExiting = isPresent === false;
52
+ const isEntering = !state.mounted;
53
+ const all = getStyle({
54
+ isExiting,
55
+ isEntering,
56
+ exitVariant: presence == null ? void 0 : presence.exitVariant,
57
+ enterVariant: presence == null ? void 0 : presence.enterVariant
58
+ });
59
+ const args = [
60
+ JSON.stringify(all),
61
+ state.mounted,
62
+ state.hover,
63
+ state.press,
64
+ state.pressIn,
65
+ state.focus,
66
+ delay,
67
+ isPresent,
68
+ onDidAnimate,
69
+ presence == null ? void 0 : presence.exitVariant,
70
+ presence == null ? void 0 : presence.enterVariant
71
+ ];
72
+ return {};
73
+ }
10
74
  };
11
75
  }
12
- __name(createAnimations, "createAnimations");
13
76
  export {
14
- createAnimations
77
+ AnimatedText,
78
+ AnimatedView,
79
+ createAnimations,
80
+ useAnimatedNumber,
81
+ useAnimatedNumberReaction,
82
+ useAnimatedNumberStyle
15
83
  };
16
84
  //# sourceMappingURL=createAnimations.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/createAnimations.tsx"],
4
- "sourcesContent": ["export function createAnimations<A>(animations: A): {\n useAnimations: any\n animations: A\n View?: any\n Text?: any\n} {\n const useAnimations = (props: Object, extra) => {\n const { style, hoverStyle, pressStyle, exitStyle, onDidAnimate, delay } = extra\n }\n return {\n useAnimations,\n animations,\n }\n}\n"],
5
- "mappings": ";;AAAO,0BAA6B,YAKlC;AACA,QAAM,gBAAgB,wBAAC,OAAe,UAAU;AAC9C,UAAM,EAAE,OAAO,YAAY,YAAY,WAAW,cAAc,UAAU;AAAA,EAC5E,GAFsB;AAGtB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAbgB;",
4
+ "sourcesContent": ["import { PresenceContext, usePresence } from '@tamagui/animate-presence'\nimport {\n AnimatedNumberStrategy,\n AnimationConfigType,\n AnimationDriver,\n AnimationProp,\n UniversalAnimatedNumber,\n isWeb,\n useEvent,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport { AnimationControls, animate } from 'motion'\nimport { useContext, useEffect, useMemo, useRef } from 'react'\nimport { Text, View } from 'react-native'\n\nexport const AnimatedView = View\nexport const AnimatedText = Text\n\nexport function useAnimatedNumber(\n initial: number\n): UniversalAnimatedNumber<AnimationControls | null> {\n const state = useRef(\n null as any as {\n val: number\n controls: AnimationControls | null\n }\n )\n if (!state.current) {\n state.current = {\n val: initial,\n controls: null,\n }\n }\n return {\n getInstance() {\n return state.current.controls\n },\n getValue() {\n return state.current.val\n },\n stop() {\n state.current.controls?.stop()\n },\n setValue(next: number, { type, ...config } = { type: 'spring' }) {\n // const val = state.current.val\n // if (type === 'direct') {\n // val.setValue(next)\n // } else if (type === 'spring') {\n // state.current.composite?.stop()\n // const composite = Animated.spring(val, {\n // ...config,\n // toValue: next,\n // useNativeDriver: !isWeb,\n // })\n // composite.start()\n // state.current.composite = composite\n // } else {\n // state.current.composite?.stop()\n // const composite = Animated.timing(val, {\n // ...config,\n // toValue: next,\n // useNativeDriver: !isWeb,\n // })\n // composite.start()\n // state.current.composite = composite\n // }\n },\n }\n}\n\nexport function useAnimatedNumberReaction(\n value: UniversalAnimatedNumber<any>,\n cb: (current: number) => void\n) {\n // const onChange = useEvent((current) => {\n // cb(current.value)\n // })\n // useEffect(() => {\n // const id = value.getInstance().addListener(onChange)\n // return () => {\n // value.getInstance().removeListener(id)\n // }\n // }, [value, onChange])\n}\n\nexport function useAnimatedNumberStyle<V extends UniversalAnimatedNumber<any>>(\n value: V,\n getStyle: (value: any) => any\n) {\n return getStyle(value.getInstance())\n}\n\n// @ts-ignore\nexport function createAnimations<A extends AnimationConfigType>(animations: A): AnimationDriver<A> {\n AnimatedView['displayName'] = 'AnimatedView'\n AnimatedText['displayName'] = 'AnimatedText'\n\n return {\n avoidClasses: true,\n animations,\n View: AnimatedView,\n Text: AnimatedText,\n useAnimatedNumber,\n useAnimatedNumberReaction,\n useAnimatedNumberStyle,\n useAnimations: (props, helpers) => {\n const { onDidAnimate, delay, getStyle, state } = helpers\n const [isPresent, sendExitComplete] = usePresence()\n const presence = useContext(PresenceContext)\n\n const isExiting = isPresent === false\n const isEntering = !state.mounted\n\n const all = getStyle({\n isExiting,\n isEntering,\n exitVariant: presence?.exitVariant,\n enterVariant: presence?.enterVariant,\n })\n\n const args = [\n JSON.stringify(all),\n state.mounted,\n state.hover,\n state.press,\n state.pressIn,\n state.focus,\n delay,\n isPresent,\n onDidAnimate,\n presence?.exitVariant,\n presence?.enterVariant,\n ]\n\n // return useMemo(() => {\n // return {\n // style: [nonAnimatedStyle, animatedStyle],\n // }\n // // eslint-disable-next-line react-hooks/exhaustive-deps\n // }, args)\n return {}\n },\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,iBAAiB,mBAAmB;AAY7C,SAAS,YAAgC,cAAc;AACvD,SAAS,MAAM,YAAY;AAEpB,MAAM,eAAe;AACrB,MAAM,eAAe;AAErB,SAAS,kBACd,SACmD;AACnD,QAAM,QAAQ;AAAA,IACZ;AAAA,EAIF;AACA,MAAI,CAAC,MAAM,SAAS;AAClB,UAAM,UAAU;AAAA,MACd,KAAK;AAAA,MACL,UAAU;AAAA,IACZ;AAAA,EACF;AACA,SAAO;AAAA,IACL,cAAc;AACZ,aAAO,MAAM,QAAQ;AAAA,IACvB;AAAA,IACA,WAAW;AACT,aAAO,MAAM,QAAQ;AAAA,IACvB;AAAA,IACA,OAAO;AAxCX;AAyCM,kBAAM,QAAQ,aAAd,mBAAwB;AAAA,IAC1B;AAAA,IACA,SAAS,MAAc,EAAE,SAAS,OAAO,IAAI,EAAE,MAAM,SAAS,GAAG;AAAA,IAuBjE;AAAA,EACF;AACF;AAEO,SAAS,0BACd,OACA,IACA;AAUF;AAEO,SAAS,uBACd,OACA,UACA;AACA,SAAO,SAAS,MAAM,YAAY,CAAC;AACrC;AAGO,SAAS,iBAAgD,YAAmC;AACjG,eAAa,iBAAiB;AAC9B,eAAa,iBAAiB;AAE9B,SAAO;AAAA,IACL,cAAc;AAAA,IACd;AAAA,IACA,MAAM;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe,CAAC,OAAO,YAAY;AACjC,YAAM,EAAE,cAAc,OAAO,UAAU,MAAM,IAAI;AACjD,YAAM,CAAC,WAAW,gBAAgB,IAAI,YAAY;AAClD,YAAM,WAAW,WAAW,eAAe;AAE3C,YAAM,YAAY,cAAc;AAChC,YAAM,aAAa,CAAC,MAAM;AAE1B,YAAM,MAAM,SAAS;AAAA,QACnB;AAAA,QACA;AAAA,QACA,aAAa,qCAAU;AAAA,QACvB,cAAc,qCAAU;AAAA,MAC1B,CAAC;AAED,YAAM,OAAO;AAAA,QACX,KAAK,UAAU,GAAG;AAAA,QAClB,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN;AAAA,QACA;AAAA,QACA;AAAA,QACA,qCAAU;AAAA,QACV,qCAAU;AAAA,MACZ;AAQA,aAAO,CAAC;AAAA,IACV;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,15 +1,83 @@
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 { useContext, useRef } from "react";
3
+ import { Text, View } from "react-native";
4
+ const AnimatedView = View;
5
+ const AnimatedText = Text;
6
+ function useAnimatedNumber(initial) {
7
+ const state = useRef(
8
+ null
9
+ );
10
+ if (!state.current) {
11
+ state.current = {
12
+ val: initial,
13
+ controls: null
14
+ };
15
+ }
16
+ return {
17
+ getInstance() {
18
+ return state.current.controls;
19
+ },
20
+ getValue() {
21
+ return state.current.val;
22
+ },
23
+ stop() {
24
+ state.current.controls?.stop();
25
+ },
26
+ setValue(next, { type, ...config } = { type: "spring" }) {
27
+ }
28
+ };
29
+ }
30
+ function useAnimatedNumberReaction(value, cb) {
31
+ }
32
+ function useAnimatedNumberStyle(value, getStyle) {
33
+ return getStyle(value.getInstance());
34
+ }
3
35
  function createAnimations(animations) {
4
- const useAnimations = /* @__PURE__ */ __name((props, extra) => {
5
- const { style, hoverStyle, pressStyle, exitStyle, onDidAnimate, delay } = extra;
6
- }, "useAnimations");
36
+ AnimatedView["displayName"] = "AnimatedView";
37
+ AnimatedText["displayName"] = "AnimatedText";
7
38
  return {
8
- useAnimations,
9
- animations
39
+ avoidClasses: true,
40
+ animations,
41
+ View: AnimatedView,
42
+ Text: AnimatedText,
43
+ useAnimatedNumber,
44
+ useAnimatedNumberReaction,
45
+ useAnimatedNumberStyle,
46
+ useAnimations: (props, helpers) => {
47
+ const { onDidAnimate, delay, getStyle, state } = helpers;
48
+ const [isPresent, sendExitComplete] = usePresence();
49
+ const presence = useContext(PresenceContext);
50
+ const isExiting = isPresent === false;
51
+ const isEntering = !state.mounted;
52
+ const all = getStyle({
53
+ isExiting,
54
+ isEntering,
55
+ exitVariant: presence?.exitVariant,
56
+ enterVariant: presence?.enterVariant
57
+ });
58
+ const args = [
59
+ JSON.stringify(all),
60
+ state.mounted,
61
+ state.hover,
62
+ state.press,
63
+ state.pressIn,
64
+ state.focus,
65
+ delay,
66
+ isPresent,
67
+ onDidAnimate,
68
+ presence?.exitVariant,
69
+ presence?.enterVariant
70
+ ];
71
+ return {};
72
+ }
10
73
  };
11
74
  }
12
- __name(createAnimations, "createAnimations");
13
75
  export {
14
- createAnimations
76
+ AnimatedText,
77
+ AnimatedView,
78
+ createAnimations,
79
+ useAnimatedNumber,
80
+ useAnimatedNumberReaction,
81
+ useAnimatedNumberStyle
15
82
  };
83
+ //# 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 {\n AnimatedNumberStrategy,\n AnimationConfigType,\n AnimationDriver,\n AnimationProp,\n UniversalAnimatedNumber,\n isWeb,\n useEvent,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport { AnimationControls, animate } from 'motion'\nimport { useContext, useEffect, useMemo, useRef } from 'react'\nimport { Text, View } from 'react-native'\n\nexport const AnimatedView = View\nexport const AnimatedText = Text\n\nexport function useAnimatedNumber(\n initial: number\n): UniversalAnimatedNumber<AnimationControls | null> {\n const state = useRef(\n null as any as {\n val: number\n controls: AnimationControls | null\n }\n )\n if (!state.current) {\n state.current = {\n val: initial,\n controls: null,\n }\n }\n return {\n getInstance() {\n return state.current.controls\n },\n getValue() {\n return state.current.val\n },\n stop() {\n state.current.controls?.stop()\n },\n setValue(next: number, { type, ...config } = { type: 'spring' }) {\n // const val = state.current.val\n // if (type === 'direct') {\n // val.setValue(next)\n // } else if (type === 'spring') {\n // state.current.composite?.stop()\n // const composite = Animated.spring(val, {\n // ...config,\n // toValue: next,\n // useNativeDriver: !isWeb,\n // })\n // composite.start()\n // state.current.composite = composite\n // } else {\n // state.current.composite?.stop()\n // const composite = Animated.timing(val, {\n // ...config,\n // toValue: next,\n // useNativeDriver: !isWeb,\n // })\n // composite.start()\n // state.current.composite = composite\n // }\n },\n }\n}\n\nexport function useAnimatedNumberReaction(\n value: UniversalAnimatedNumber<any>,\n cb: (current: number) => void\n) {\n // const onChange = useEvent((current) => {\n // cb(current.value)\n // })\n // useEffect(() => {\n // const id = value.getInstance().addListener(onChange)\n // return () => {\n // value.getInstance().removeListener(id)\n // }\n // }, [value, onChange])\n}\n\nexport function useAnimatedNumberStyle<V extends UniversalAnimatedNumber<any>>(\n value: V,\n getStyle: (value: any) => any\n) {\n return getStyle(value.getInstance())\n}\n\n// @ts-ignore\nexport function createAnimations<A extends AnimationConfigType>(animations: A): AnimationDriver<A> {\n AnimatedView['displayName'] = 'AnimatedView'\n AnimatedText['displayName'] = 'AnimatedText'\n\n return {\n avoidClasses: true,\n animations,\n View: AnimatedView,\n Text: AnimatedText,\n useAnimatedNumber,\n useAnimatedNumberReaction,\n useAnimatedNumberStyle,\n useAnimations: (props, helpers) => {\n const { onDidAnimate, delay, getStyle, state } = helpers\n const [isPresent, sendExitComplete] = usePresence()\n const presence = useContext(PresenceContext)\n\n const isExiting = isPresent === false\n const isEntering = !state.mounted\n\n const all = getStyle({\n isExiting,\n isEntering,\n exitVariant: presence?.exitVariant,\n enterVariant: presence?.enterVariant,\n })\n\n const args = [\n JSON.stringify(all),\n state.mounted,\n state.hover,\n state.press,\n state.pressIn,\n state.focus,\n delay,\n isPresent,\n onDidAnimate,\n presence?.exitVariant,\n presence?.enterVariant,\n ]\n\n // return useMemo(() => {\n // return {\n // style: [nonAnimatedStyle, animatedStyle],\n // }\n // // eslint-disable-next-line react-hooks/exhaustive-deps\n // }, args)\n return {}\n },\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,iBAAiB,mBAAmB;AAY7C,SAAS,YAAgC,cAAc;AACvD,SAAS,MAAM,YAAY;AAEpB,MAAM,eAAe;AACrB,MAAM,eAAe;AAErB,SAAS,kBACd,SAC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;AAAA,MACZ;AAQA,aAAO,CAAC;AAAA,IACV;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,23 @@
1
1
  {
2
2
  "name": "@tamagui/animations-motion",
3
- "version": "1.0.1-beta.18",
3
+ "version": "1.0.1-beta.181",
4
4
  "source": "src/index.ts",
5
5
  "license": "MIT",
6
- "typings": "types",
6
+ "types": "./types/index.d.ts",
7
7
  "main": "dist/cjs",
8
8
  "module": "dist/esm",
9
9
  "module:jsx": "dist/jsx",
10
10
  "files": [
11
+ "src",
11
12
  "types",
12
13
  "dist"
13
14
  ],
14
15
  "dependencies": {
15
- "@tamagui/core": "^1.0.1-beta.18"
16
+ "@tamagui/core": "^1.0.1-beta.181",
17
+ "motion": "^10.14.0"
16
18
  },
17
19
  "devDependencies": {
18
- "@tamagui/build": "^1.0.1-beta.18"
20
+ "@tamagui/build": "^1.0.1-beta.181"
19
21
  },
20
22
  "scripts": {
21
23
  "build": "tamagui-build",
@@ -0,0 +1,144 @@
1
+ import { PresenceContext, usePresence } from '@tamagui/animate-presence'
2
+ import {
3
+ AnimatedNumberStrategy,
4
+ AnimationConfigType,
5
+ AnimationDriver,
6
+ AnimationProp,
7
+ UniversalAnimatedNumber,
8
+ isWeb,
9
+ useEvent,
10
+ useIsomorphicLayoutEffect,
11
+ } from '@tamagui/core'
12
+ import { AnimationControls, animate } from 'motion'
13
+ import { useContext, useEffect, useMemo, useRef } from 'react'
14
+ import { Text, View } from 'react-native'
15
+
16
+ export const AnimatedView = View
17
+ export const AnimatedText = Text
18
+
19
+ export function useAnimatedNumber(
20
+ initial: number
21
+ ): UniversalAnimatedNumber<AnimationControls | null> {
22
+ const state = useRef(
23
+ null as any as {
24
+ val: number
25
+ controls: AnimationControls | null
26
+ }
27
+ )
28
+ if (!state.current) {
29
+ state.current = {
30
+ val: initial,
31
+ controls: null,
32
+ }
33
+ }
34
+ return {
35
+ getInstance() {
36
+ return state.current.controls
37
+ },
38
+ getValue() {
39
+ return state.current.val
40
+ },
41
+ stop() {
42
+ state.current.controls?.stop()
43
+ },
44
+ setValue(next: number, { type, ...config } = { type: 'spring' }) {
45
+ // const val = state.current.val
46
+ // if (type === 'direct') {
47
+ // val.setValue(next)
48
+ // } else if (type === 'spring') {
49
+ // state.current.composite?.stop()
50
+ // const composite = Animated.spring(val, {
51
+ // ...config,
52
+ // toValue: next,
53
+ // useNativeDriver: !isWeb,
54
+ // })
55
+ // composite.start()
56
+ // state.current.composite = composite
57
+ // } else {
58
+ // state.current.composite?.stop()
59
+ // const composite = Animated.timing(val, {
60
+ // ...config,
61
+ // toValue: next,
62
+ // useNativeDriver: !isWeb,
63
+ // })
64
+ // composite.start()
65
+ // state.current.composite = composite
66
+ // }
67
+ },
68
+ }
69
+ }
70
+
71
+ export function useAnimatedNumberReaction(
72
+ value: UniversalAnimatedNumber<any>,
73
+ cb: (current: number) => void
74
+ ) {
75
+ // const onChange = useEvent((current) => {
76
+ // cb(current.value)
77
+ // })
78
+ // useEffect(() => {
79
+ // const id = value.getInstance().addListener(onChange)
80
+ // return () => {
81
+ // value.getInstance().removeListener(id)
82
+ // }
83
+ // }, [value, onChange])
84
+ }
85
+
86
+ export function useAnimatedNumberStyle<V extends UniversalAnimatedNumber<any>>(
87
+ value: V,
88
+ getStyle: (value: any) => any
89
+ ) {
90
+ return getStyle(value.getInstance())
91
+ }
92
+
93
+ // @ts-ignore
94
+ export function createAnimations<A extends AnimationConfigType>(animations: A): AnimationDriver<A> {
95
+ AnimatedView['displayName'] = 'AnimatedView'
96
+ AnimatedText['displayName'] = 'AnimatedText'
97
+
98
+ return {
99
+ avoidClasses: true,
100
+ animations,
101
+ View: AnimatedView,
102
+ Text: AnimatedText,
103
+ useAnimatedNumber,
104
+ useAnimatedNumberReaction,
105
+ useAnimatedNumberStyle,
106
+ useAnimations: (props, helpers) => {
107
+ const { onDidAnimate, delay, getStyle, state } = helpers
108
+ const [isPresent, sendExitComplete] = usePresence()
109
+ const presence = useContext(PresenceContext)
110
+
111
+ const isExiting = isPresent === false
112
+ const isEntering = !state.mounted
113
+
114
+ const all = getStyle({
115
+ isExiting,
116
+ isEntering,
117
+ exitVariant: presence?.exitVariant,
118
+ enterVariant: presence?.enterVariant,
119
+ })
120
+
121
+ const args = [
122
+ JSON.stringify(all),
123
+ state.mounted,
124
+ state.hover,
125
+ state.press,
126
+ state.pressIn,
127
+ state.focus,
128
+ delay,
129
+ isPresent,
130
+ onDidAnimate,
131
+ presence?.exitVariant,
132
+ presence?.enterVariant,
133
+ ]
134
+
135
+ // return useMemo(() => {
136
+ // return {
137
+ // style: [nonAnimatedStyle, animatedStyle],
138
+ // }
139
+ // // eslint-disable-next-line react-hooks/exhaustive-deps
140
+ // }, args)
141
+ return {}
142
+ },
143
+ }
144
+ }
package/src/index.tsx ADDED
@@ -0,0 +1 @@
1
+ export * from './createAnimations'
@@ -1,7 +1,10 @@
1
- export declare function createAnimations<A>(animations: A): {
2
- useAnimations: any;
3
- animations: A;
4
- View?: any;
5
- Text?: any;
6
- };
1
+ import { AnimationConfigType, AnimationDriver, UniversalAnimatedNumber } from '@tamagui/core';
2
+ import { AnimationControls } from 'motion';
3
+ import { Text, View } from 'react-native';
4
+ export declare const AnimatedView: typeof View;
5
+ export declare const AnimatedText: typeof Text;
6
+ export declare function useAnimatedNumber(initial: number): UniversalAnimatedNumber<AnimationControls | null>;
7
+ export declare function useAnimatedNumberReaction(value: UniversalAnimatedNumber<any>, cb: (current: number) => void): void;
8
+ export declare function useAnimatedNumberStyle<V extends UniversalAnimatedNumber<any>>(value: V, getStyle: (value: any) => any): any;
9
+ export declare function createAnimations<A extends AnimationConfigType>(animations: A): AnimationDriver<A>;
7
10
  //# sourceMappingURL=createAnimations.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createAnimations.d.ts","sourceRoot":"","sources":["../src/createAnimations.tsx"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,GAAG;IAClD,aAAa,EAAE,GAAG,CAAA;IAClB,UAAU,EAAE,CAAC,CAAA;IACb,IAAI,CAAC,EAAE,GAAG,CAAA;IACV,IAAI,CAAC,EAAE,GAAG,CAAA;CACX,CAQA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA"}