@tamagui/animations-react-native 1.0.1-beta.98 → 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,70 +1,279 @@
1
- import { PresenceContext, usePresence } from "@tamagui/animate-presence";
2
- import { useCallback, useContext, useMemo, useRef } from "react";
1
+ import {
2
+ isWeb,
3
+ useEvent,
4
+ useIsomorphicLayoutEffect,
5
+ useSafeRef
6
+ } from "@tamagui/core";
7
+ import { usePresence } from "@tamagui/use-presence";
8
+ import { useEffect, useMemo } from "react";
3
9
  import { Animated } from "react-native";
10
+ const animatedStyleKey = {
11
+ transform: true,
12
+ opacity: true
13
+ };
14
+ const AnimatedView = Animated.View;
15
+ const AnimatedText = Animated.Text;
16
+ function useAnimatedNumber(initial) {
17
+ const state = useSafeRef(
18
+ null
19
+ );
20
+ if (!state.current) {
21
+ state.current = {
22
+ composite: null,
23
+ val: new Animated.Value(initial),
24
+ strategy: { type: "spring" }
25
+ };
26
+ }
27
+ return {
28
+ getInstance() {
29
+ return state.current.val;
30
+ },
31
+ getValue() {
32
+ return state.current.val["_value"];
33
+ },
34
+ stop() {
35
+ var _a;
36
+ (_a = state.current.composite) == null ? void 0 : _a.stop();
37
+ state.current.composite = null;
38
+ },
39
+ setValue(next, { type, ...config } = { type: "spring" }) {
40
+ var _a, _b;
41
+ const val = state.current.val;
42
+ if (type === "direct") {
43
+ val.setValue(next);
44
+ } else if (type === "spring") {
45
+ (_a = state.current.composite) == null ? void 0 : _a.stop();
46
+ const composite = Animated.spring(val, {
47
+ ...config,
48
+ toValue: next,
49
+ useNativeDriver: !isWeb
50
+ });
51
+ composite.start();
52
+ state.current.composite = composite;
53
+ } else {
54
+ (_b = state.current.composite) == null ? void 0 : _b.stop();
55
+ const composite = Animated.timing(val, {
56
+ ...config,
57
+ toValue: next,
58
+ useNativeDriver: !isWeb
59
+ });
60
+ composite.start();
61
+ state.current.composite = composite;
62
+ }
63
+ }
64
+ };
65
+ }
66
+ function useAnimatedNumberReaction(value, cb) {
67
+ const onChange = useEvent((current) => {
68
+ cb(current.value);
69
+ });
70
+ useEffect(() => {
71
+ const id = value.getInstance().addListener(onChange);
72
+ return () => {
73
+ value.getInstance().removeListener(id);
74
+ };
75
+ }, [value, onChange]);
76
+ }
77
+ function useAnimatedNumberStyle(value, getStyle) {
78
+ return getStyle(value.getInstance());
79
+ }
4
80
  function createAnimations(animations) {
5
- const AnimatedView = Animated.View;
6
- const AnimatedText = Animated.Text;
7
81
  AnimatedView["displayName"] = "AnimatedView";
8
82
  AnimatedText["displayName"] = "AnimatedText";
9
83
  return {
10
- avoidClasses: true,
84
+ isReactNative: true,
11
85
  animations,
12
86
  View: AnimatedView,
13
87
  Text: AnimatedText,
14
- useAnimations: (props, helpers) => {
15
- var _a, _b;
16
- const { pseudos, onDidAnimate, delay, getStyle, state, staticConfig } = helpers;
17
- const [isPresent, sendExitComplete] = usePresence();
18
- const presence = useContext(PresenceContext);
19
- const exitStyle = (presence == null ? void 0 : presence.exitVariant) ? ((_b = (_a = staticConfig.variantsParsed) == null ? void 0 : _a[presence.exitVariant]) == null ? void 0 : _b.true) || pseudos.exitStyle : pseudos.exitStyle;
20
- const onDidAnimateCb = useCallback((...args2) => {
21
- onDidAnimate == null ? void 0 : onDidAnimate(...args2);
22
- }, [onDidAnimate]);
23
- const isExiting = isPresent === false;
24
- const isEntering = !state.mounted;
25
- const all = getStyle({
26
- isExiting,
27
- isEntering,
28
- exitVariant: presence == null ? void 0 : presence.exitVariant,
29
- enterVariant: presence == null ? void 0 : presence.enterVariant
30
- });
31
- const animatedValues = useRef({});
32
- const [animatedStyles, nonAnimatedStyle] = [{}, {}];
33
- const animatedStyleKey = {
34
- transform: true,
35
- opacity: true
36
- };
37
- for (const key of Object.keys(all)) {
38
- if (animatedStyleKey[key]) {
39
- animatedStyles[key] = all[key];
40
- } else {
41
- nonAnimatedStyle[key] = all[key];
42
- }
88
+ useAnimatedNumber,
89
+ useAnimatedNumberReaction,
90
+ useAnimatedNumberStyle,
91
+ usePresence,
92
+ useAnimations: ({ props, onDidAnimate, style, state, presence }) => {
93
+ const isExiting = (presence == null ? void 0 : presence[0]) === false;
94
+ const sendExitComplete = presence == null ? void 0 : presence[1];
95
+ const mergedStyles = style;
96
+ const animateStyles = useSafeRef({});
97
+ const animatedTranforms = useSafeRef([]);
98
+ const animationsState = useSafeRef(null);
99
+ if (!animationsState.current) {
100
+ animationsState.current = /* @__PURE__ */ new WeakMap();
43
101
  }
44
- const animatedStyle = animatedStyleKey;
45
- const args = [
46
- JSON.stringify(all),
47
- state.mounted,
48
- state.hover,
49
- state.press,
50
- state.pressIn,
51
- state.focus,
52
- delay,
53
- isPresent,
54
- onDidAnimate,
55
- onDidAnimateCb,
56
- presence == null ? void 0 : presence.exitVariant,
57
- presence == null ? void 0 : presence.enterVariant
58
- ];
59
- return useMemo(() => {
102
+ const runners = [];
103
+ const completions = [];
104
+ const args = [JSON.stringify(mergedStyles), JSON.stringify(state), isExiting, !!onDidAnimate];
105
+ const res = useMemo(() => {
106
+ var _a;
107
+ const nonAnimatedStyle = {};
108
+ for (const key in mergedStyles) {
109
+ const val = mergedStyles[key];
110
+ if (!animatedStyleKey[key]) {
111
+ nonAnimatedStyle[key] = val;
112
+ continue;
113
+ }
114
+ if (key !== "transform") {
115
+ animateStyles.current[key] = update(key, animateStyles.current[key], val);
116
+ continue;
117
+ }
118
+ if (!val)
119
+ continue;
120
+ for (const [index, transform] of val.entries()) {
121
+ if (!transform)
122
+ continue;
123
+ const tkey = Object.keys(transform)[0];
124
+ const currentTransform = (_a = animatedTranforms.current[index]) == null ? void 0 : _a[tkey];
125
+ animatedTranforms.current[index] = {
126
+ [tkey]: update(tkey, currentTransform, transform[tkey])
127
+ };
128
+ animatedTranforms.current = [...animatedTranforms.current];
129
+ }
130
+ }
131
+ const animatedStyle = {
132
+ ...Object.fromEntries(
133
+ Object.entries({
134
+ ...animateStyles.current
135
+ }).map(([k, v]) => {
136
+ var _a2;
137
+ return [k, ((_a2 = animationsState.current.get(v)) == null ? void 0 : _a2.interopolation) || v];
138
+ })
139
+ ),
140
+ transform: animatedTranforms.current.map((r) => {
141
+ var _a2;
142
+ const key = Object.keys(r)[0];
143
+ const val = ((_a2 = animationsState.current.get(r[key])) == null ? void 0 : _a2.interopolation) || r[key];
144
+ return { [key]: val };
145
+ })
146
+ };
60
147
  return {
61
148
  style: [nonAnimatedStyle, animatedStyle]
62
149
  };
150
+ function update(key, animated, valIn) {
151
+ const [val, type] = getValue(valIn);
152
+ const value = animated || new Animated.Value(val);
153
+ let interpolateArgs;
154
+ if (type) {
155
+ const curInterpolation = animationsState.current.get(value);
156
+ interpolateArgs = getInterpolated(
157
+ (curInterpolation == null ? void 0 : curInterpolation.current) ?? value["_value"],
158
+ val,
159
+ type
160
+ );
161
+ animationsState.current.set(value, {
162
+ interopolation: value.interpolate(interpolateArgs),
163
+ current: val
164
+ });
165
+ }
166
+ if (value) {
167
+ const animationConfig = getAnimationConfig(key, animations, props.animation);
168
+ let resolve;
169
+ const promise = new Promise((res2) => {
170
+ resolve = res2;
171
+ });
172
+ completions.push(promise);
173
+ runners.push(() => {
174
+ value.stopAnimation();
175
+ Animated.spring(value, {
176
+ toValue: val,
177
+ useNativeDriver: !isWeb,
178
+ ...animationConfig
179
+ }).start(({ finished }) => {
180
+ if (finished) {
181
+ resolve();
182
+ }
183
+ });
184
+ });
185
+ }
186
+ if (process.env.NODE_ENV === "development") {
187
+ if (props["debug"]) {
188
+ console.log(" \u{1F4A0} animate", key, `from ${value["_value"]} to`, valIn, `(${val})`, "type", type, "interpolate", interpolateArgs);
189
+ }
190
+ }
191
+ return value;
192
+ }
63
193
  }, args);
194
+ useIsomorphicLayoutEffect(() => {
195
+ runners.forEach((r) => r());
196
+ let cancel = false;
197
+ Promise.all(completions).then(() => {
198
+ if (cancel)
199
+ return;
200
+ onDidAnimate == null ? void 0 : onDidAnimate();
201
+ if (isExiting) {
202
+ sendExitComplete == null ? void 0 : sendExitComplete();
203
+ }
204
+ });
205
+ return () => {
206
+ cancel = true;
207
+ };
208
+ }, args);
209
+ if (process.env.NODE_ENV === "development") {
210
+ if (props["debug"]) {
211
+ console.log(`Returning animated`, res);
212
+ }
213
+ }
214
+ return res;
64
215
  }
65
216
  };
66
217
  }
218
+ function getInterpolated(current, next, postfix = "deg") {
219
+ if (next === current) {
220
+ current = next - 1e-9;
221
+ }
222
+ const inputRange = [current, next];
223
+ const outputRange = [`${current}${postfix}`, `${next}${postfix}`];
224
+ if (next < current) {
225
+ inputRange.reverse();
226
+ outputRange.reverse();
227
+ }
228
+ return {
229
+ inputRange,
230
+ outputRange
231
+ };
232
+ }
233
+ function getAnimationConfig(key, animations, animation) {
234
+ if (typeof animation === "string") {
235
+ return animations[animation];
236
+ }
237
+ let type = "";
238
+ let extraConf;
239
+ if (Array.isArray(animation)) {
240
+ type = animation[0];
241
+ const conf = animation[1] && animation[1][key];
242
+ if (conf) {
243
+ if (typeof conf === "string") {
244
+ type = conf;
245
+ } else {
246
+ type = conf.type || type;
247
+ extraConf = conf;
248
+ }
249
+ }
250
+ } else {
251
+ const val = animation == null ? void 0 : animation[key];
252
+ type = val == null ? void 0 : val.type;
253
+ extraConf = val;
254
+ }
255
+ const found = animations[type];
256
+ if (!found) {
257
+ throw new Error(`No animation of type "${type}" for key "${key}"`);
258
+ }
259
+ return {
260
+ ...found,
261
+ ...extraConf
262
+ };
263
+ }
264
+ function getValue(input) {
265
+ if (typeof input !== "string") {
266
+ return [input];
267
+ }
268
+ const [_, number, after] = input.match(/([-0-9]+)(deg|%|px)/) ?? [];
269
+ return [+number, after];
270
+ }
67
271
  export {
68
- createAnimations
272
+ AnimatedText,
273
+ AnimatedView,
274
+ createAnimations,
275
+ useAnimatedNumber,
276
+ useAnimatedNumberReaction,
277
+ useAnimatedNumberStyle
69
278
  };
70
279
  //# sourceMappingURL=createAnimations.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/createAnimations.tsx"],
4
- "sourcesContent": ["import { PresenceContext, usePresence } from '@tamagui/animate-presence'\nimport { AnimationDriver, AnimationProp } from '@tamagui/core'\nimport { useCallback, useContext, useMemo, useRef, useState } from 'react'\nimport { Animated } from 'react-native'\n\ntype AnimationsConfig<A extends Object = any> = {\n [Key in keyof A]: AnimationConfig\n}\n\ntype AnimationConfig = {}\n// | ({ type: 'timing'; loop?: number; repeat?: number; repeatReverse?: boolean } & WithTimingConfig)\n// | ({ type: 'spring'; loop?: number; repeat?: number; repeatReverse?: boolean } & WithSpringConfig)\n// | ({ type: 'decay'; loop?: number; repeat?: number; repeatReverse?: boolean } & WithDecayConfig)\n\nexport function createAnimations<A extends AnimationsConfig>(animations: A): AnimationDriver<A> {\n const AnimatedView = Animated.View\n const AnimatedText = Animated.Text\n\n AnimatedView['displayName'] = 'AnimatedView'\n AnimatedText['displayName'] = 'AnimatedText'\n\n return {\n avoidClasses: true,\n animations,\n View: AnimatedView,\n Text: AnimatedText,\n useAnimations: (props, helpers) => {\n const { pseudos, onDidAnimate, delay, getStyle, state, staticConfig } = helpers\n const [isPresent, sendExitComplete] = usePresence()\n const presence = useContext(PresenceContext)\n\n const exitStyle = presence?.exitVariant\n ? staticConfig.variantsParsed?.[presence.exitVariant]?.true || pseudos.exitStyle\n : pseudos.exitStyle\n\n const onDidAnimateCb = useCallback<NonNullable<typeof onDidAnimate>>(\n (...args) => {\n onDidAnimate?.(...args)\n },\n [onDidAnimate]\n )\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 animatedValues = useRef<Record<string, Animated.Value>>({})\n\n // TODO loop and create values, run them if they change\n\n const [animatedStyles, nonAnimatedStyle] = [{}, {}]\n const animatedStyleKey = {\n transform: true,\n opacity: true,\n }\n for (const key of Object.keys(all)) {\n if (animatedStyleKey[key]) {\n animatedStyles[key] = all[key]\n } else {\n nonAnimatedStyle[key] = all[key]\n }\n }\n\n const animatedStyle = animatedStyleKey\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 onDidAnimateCb,\n presence?.exitVariant,\n presence?.enterVariant,\n ]\n\n // const callback = (\n // isExiting: boolean,\n // exitingStyleProps: Record<string, boolean>,\n // key: string,\n // value: any\n // ) => {\n // return (completed, current) => {\n // onDidAnimateCb(key, completed, current, {\n // attemptedValue: value,\n // })\n // if (isExiting) {\n // exitingStyleProps[key] = false\n // const areStylesExiting = Object.values(exitingStyleProps).some(Boolean)\n // // if this is true, then we've finished our exit animations\n // if (!areStylesExiting) {\n // sendExitComplete?.()\n // }\n // }\n // }\n // }\n\n return useMemo(() => {\n return {\n style: [nonAnimatedStyle, animatedStyle],\n }\n }, args)\n },\n }\n}\n"],
5
- "mappings": "AAAA;AAEA;AACA;AAWO,0BAAsD,YAAmC;AAC9F,QAAM,eAAe,SAAS;AAC9B,QAAM,eAAe,SAAS;AAE9B,eAAa,iBAAiB;AAC9B,eAAa,iBAAiB;AAE9B,SAAO;AAAA,IACL,cAAc;AAAA,IACd;AAAA,IACA,MAAM;AAAA,IACN,MAAM;AAAA,IACN,eAAe,CAAC,OAAO,YAAY;AA1BvC;AA2BM,YAAM,EAAE,SAAS,cAAc,OAAO,UAAU,OAAO,iBAAiB;AACxE,YAAM,CAAC,WAAW,oBAAoB,YAAY;AAClD,YAAM,WAAW,WAAW,eAAe;AAE3C,YAAM,YAAY,sCAAU,eACxB,0BAAa,mBAAb,mBAA8B,SAAS,iBAAvC,mBAAqD,SAAQ,QAAQ,YACrE,QAAQ;AAEZ,YAAM,iBAAiB,YACrB,IAAI,UAAS;AACX,qDAAe,GAAG;AAAA,MACpB,GACA,CAAC,YAAY,CACf;AAEA,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,iBAAiB,OAAuC,CAAC,CAAC;AAIhE,YAAM,CAAC,gBAAgB,oBAAoB,CAAC,CAAC,GAAG,CAAC,CAAC;AAClD,YAAM,mBAAmB;AAAA,QACvB,WAAW;AAAA,QACX,SAAS;AAAA,MACX;AACA,iBAAW,OAAO,OAAO,KAAK,GAAG,GAAG;AAClC,YAAI,iBAAiB,MAAM;AACzB,yBAAe,OAAO,IAAI;AAAA,QAC5B,OAAO;AACL,2BAAiB,OAAO,IAAI;AAAA,QAC9B;AAAA,MACF;AAEA,YAAM,gBAAgB;AAEtB,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;AAAA,QACA,qCAAU;AAAA,QACV,qCAAU;AAAA,MACZ;AAuBA,aAAO,QAAQ,MAAM;AACnB,eAAO;AAAA,UACL,OAAO,CAAC,kBAAkB,aAAa;AAAA,QACzC;AAAA,MACF,GAAG,IAAI;AAAA,IACT;AAAA,EACF;AACF;",
6
- "names": []
4
+ "sourcesContent": ["import {\n AnimatedNumberStrategy,\n AnimationDriver,\n AnimationProp,\n UniversalAnimatedNumber,\n isWeb,\n useEvent,\n useIsomorphicLayoutEffect,\n useSafeRef,\n} from '@tamagui/core'\nimport { usePresence } from '@tamagui/use-presence'\nimport { useEffect, useMemo } from 'react'\nimport { Animated } from 'react-native'\n\ntype AnimationsConfig<A extends Object = any> = {\n [Key in keyof A]: AnimationConfig\n}\n\ntype AnimationConfig = Partial<\n Pick<\n Animated.SpringAnimationConfig,\n | 'delay'\n | 'bounciness'\n | 'damping'\n | 'friction'\n | 'mass'\n | 'overshootClamping'\n | 'speed'\n | 'stiffness'\n | 'tension'\n | 'velocity'\n >\n>\n\nconst animatedStyleKey = {\n transform: true,\n opacity: true,\n}\n\nexport const AnimatedView = Animated.View\nexport const AnimatedText = Animated.Text\n\nexport function useAnimatedNumber(initial: number): UniversalAnimatedNumber<Animated.Value> {\n const state = useSafeRef(\n null as any as {\n val: Animated.Value\n composite: Animated.CompositeAnimation | null\n strategy: AnimatedNumberStrategy\n }\n )\n if (!state.current) {\n state.current = {\n composite: null,\n val: new Animated.Value(initial),\n strategy: { type: 'spring' },\n }\n }\n\n return {\n getInstance() {\n return state.current.val\n },\n getValue() {\n return state.current.val['_value']\n },\n stop() {\n state.current.composite?.stop()\n state.current.composite = null\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<Animated.Value>,\n cb: (current: number) => void\n) {\n const onChange = useEvent((current) => {\n cb(current.value)\n })\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<Animated.Value>>(\n value: V,\n getStyle: (value: any) => any\n) {\n return getStyle(value.getInstance())\n}\n\nexport function createAnimations<A extends AnimationsConfig>(animations: A): AnimationDriver<A> {\n AnimatedView['displayName'] = 'AnimatedView'\n AnimatedText['displayName'] = 'AnimatedText'\n\n return {\n isReactNative: true,\n animations,\n View: AnimatedView,\n Text: AnimatedText,\n useAnimatedNumber,\n useAnimatedNumberReaction,\n useAnimatedNumberStyle,\n usePresence,\n useAnimations: ({ props, onDidAnimate, style, state, presence }) => {\n const isExiting = presence?.[0] === false\n const sendExitComplete = presence?.[1]\n const mergedStyles = style\n const animateStyles = useSafeRef<Record<string, Animated.Value>>({})\n const animatedTranforms = useSafeRef<{ [key: string]: Animated.Value }[]>([])\n const animationsState = useSafeRef<\n WeakMap<\n Animated.Value,\n {\n interopolation: Animated.AnimatedInterpolation\n current?: number | undefined\n }\n >\n >(null as any)\n if (!animationsState.current) {\n animationsState.current = new WeakMap()\n }\n\n const runners: Function[] = []\n const completions: Promise<void>[] = []\n\n // const args = [JSON.stringify(mergedStyles)]\n const args = [JSON.stringify(mergedStyles), JSON.stringify(state), isExiting, !!onDidAnimate]\n\n const res = useMemo(() => {\n const nonAnimatedStyle = {}\n for (const key in mergedStyles) {\n const val = mergedStyles[key]\n if (!animatedStyleKey[key]) {\n nonAnimatedStyle[key] = val\n continue\n }\n if (key !== 'transform') {\n animateStyles.current[key] = update(key, animateStyles.current[key], val)\n continue\n }\n // key: 'transform'\n // for now just support one transform key\n if (!val) continue\n for (const [index, transform] of val.entries()) {\n if (!transform) continue\n const tkey = Object.keys(transform)[0]\n const currentTransform = animatedTranforms.current[index]?.[tkey]\n animatedTranforms.current[index] = {\n [tkey]: update(tkey, currentTransform, transform[tkey]),\n }\n animatedTranforms.current = [...animatedTranforms.current]\n }\n }\n\n const animatedStyle = {\n ...Object.fromEntries(\n Object.entries({\n ...animateStyles.current,\n }).map(([k, v]) => [k, animationsState.current!.get(v)?.interopolation || v])\n ),\n transform: animatedTranforms.current.map((r) => {\n const key = Object.keys(r)[0]\n const val = animationsState.current!.get(r[key])?.interopolation || r[key]\n return { [key]: val }\n }),\n }\n\n return {\n style: [nonAnimatedStyle, animatedStyle],\n }\n\n function update(key: string, animated: Animated.Value | undefined, valIn: string | number) {\n const [val, type] = getValue(valIn)\n const value = animated || new Animated.Value(val)\n let interpolateArgs: any\n if (type) {\n const curInterpolation = animationsState.current.get(value)\n interpolateArgs = getInterpolated(\n curInterpolation?.current ?? value['_value'],\n val,\n type\n )\n animationsState.current!.set(value, {\n interopolation: value.interpolate(interpolateArgs),\n current: val,\n })\n }\n if (value) {\n const animationConfig = getAnimationConfig(key, animations, props.animation)\n\n let resolve\n const promise = new Promise<void>((res) => {\n resolve = res\n })\n completions.push(promise)\n\n runners.push(() => {\n value.stopAnimation()\n Animated.spring(value, {\n toValue: val,\n useNativeDriver: !isWeb,\n ...animationConfig,\n }).start(({ finished }) => {\n if (finished) {\n resolve()\n }\n })\n })\n }\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n // prettier-ignore\n // eslint-disable-next-line no-console\n console.log(' \uD83D\uDCA0 animate', key, `from ${value['_value']} to`, valIn, `(${val})`, 'type', type, 'interpolate', interpolateArgs)\n }\n }\n return value\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, args)\n\n useIsomorphicLayoutEffect(() => {\n runners.forEach((r) => r())\n let cancel = false\n Promise.all(completions).then(() => {\n if (cancel) return\n onDidAnimate?.()\n if (isExiting) {\n sendExitComplete?.()\n }\n })\n return () => {\n cancel = true\n }\n }, args)\n\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n // eslint-disable-next-line no-console\n console.log(`Returning animated`, res)\n }\n }\n\n return res\n },\n }\n}\n\nfunction getInterpolated(current: number, next: number, postfix = 'deg') {\n if (next === current) {\n current = next - 0.000000001\n }\n const inputRange = [current, next]\n const outputRange = [`${current}${postfix}`, `${next}${postfix}`]\n if (next < current) {\n inputRange.reverse()\n outputRange.reverse()\n }\n return {\n inputRange,\n outputRange,\n }\n}\n\nfunction getAnimationConfig(key: string, animations: AnimationsConfig, animation?: AnimationProp) {\n if (typeof animation === 'string') {\n return animations[animation]\n }\n let type = ''\n let extraConf: any\n if (Array.isArray(animation)) {\n type = animation[0] as string\n const conf = animation[1] && animation[1][key]\n if (conf) {\n if (typeof conf === 'string') {\n type = conf\n } else {\n type = (conf as any).type || type\n extraConf = conf\n }\n }\n } else {\n const val = animation?.[key]\n type = val?.type\n extraConf = val\n }\n const found = animations[type]\n if (!found) {\n throw new Error(`No animation of type \"${type}\" for key \"${key}\"`)\n }\n return {\n ...found,\n ...extraConf,\n }\n}\n\nfunction getValue(input: number | string) {\n if (typeof input !== 'string') {\n return [input] as const\n }\n const [_, number, after] = input.match(/([-0-9]+)(deg|%|px)/) ?? []\n return [+number, after] as const\n}\n"],
5
+ "mappings": "AAAA;AAAA,EAKE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,WAAW,eAAe;AACnC,SAAS,gBAAgB;AAsBzB,MAAM,mBAAmB;AAAA,EACvB,WAAW;AAAA,EACX,SAAS;AACX;AAEO,MAAM,eAAe,SAAS;AAC9B,MAAM,eAAe,SAAS;AAE9B,SAAS,kBAAkB,SAA0D;AAC1F,QAAM,QAAQ;AAAA,IACZ;AAAA,EAKF;AACA,MAAI,CAAC,MAAM,SAAS;AAClB,UAAM,UAAU;AAAA,MACd,WAAW;AAAA,MACX,KAAK,IAAI,SAAS,MAAM,OAAO;AAAA,MAC/B,UAAU,EAAE,MAAM,SAAS;AAAA,IAC7B;AAAA,EACF;AAEA,SAAO;AAAA,IACL,cAAc;AACZ,aAAO,MAAM,QAAQ;AAAA,IACvB;AAAA,IACA,WAAW;AACT,aAAO,MAAM,QAAQ,IAAI;AAAA,IAC3B;AAAA,IACA,OAAO;AAjEX;AAkEM,kBAAM,QAAQ,cAAd,mBAAyB;AACzB,YAAM,QAAQ,YAAY;AAAA,IAC5B;AAAA,IACA,SAAS,MAAc,EAAE,SAAS,OAAO,IAAI,EAAE,MAAM,SAAS,GAAG;AArErE;AAsEM,YAAM,MAAM,MAAM,QAAQ;AAC1B,UAAI,SAAS,UAAU;AACrB,YAAI,SAAS,IAAI;AAAA,MACnB,WAAW,SAAS,UAAU;AAC5B,oBAAM,QAAQ,cAAd,mBAAyB;AACzB,cAAM,YAAY,SAAS,OAAO,KAAK;AAAA,UACrC,GAAG;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M,uCAAY;AACxB,WAAO,2BAAK;AACZ,gBAAY;AAAA,EACd;AACA,QAAM,QAAQ,WAAW;AACzB,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,yBAAyB,kBAAkB,MAAM;AAAA,EACnE;AACA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACF;AAEA,SAAS,SAAS,OAAwB;AACxC,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,CAAC,KAAK;AAAA,EACf;AACA,QAAM,CAAC,GAAG,QAAQ,KAAK,IAAI,MAAM,MAAM,qBAAqB,KAAK,CAAC;AAClE,SAAO,CAAC,CAAC,QAAQ,KAAK;AACxB;",
6
+ "names": ["_a", "res"]
7
7
  }
package/dist/esm/index.js CHANGED
@@ -1,2 +1,3 @@
1
+ import "./polyfill";
1
2
  export * from "./createAnimations";
2
3
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.tsx"],
4
- "sourcesContent": ["export * from './createAnimations'\n"],
5
- "mappings": "AAAA;",
4
+ "sourcesContent": ["import './polyfill'\n\nexport * from './createAnimations'\n"],
5
+ "mappings": "AAAA,OAAO;AAEP,cAAc;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,4 @@
1
+ if (typeof requestAnimationFrame === "undefined") {
2
+ globalThis["requestAnimationFrame"] = setImmediate;
3
+ }
4
+ //# sourceMappingURL=polyfill.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/polyfill.ts"],
4
+ "sourcesContent": ["// for SSR\nif (typeof requestAnimationFrame === 'undefined') {\n globalThis['requestAnimationFrame'] = setImmediate\n}\n"],
5
+ "mappings": "AACA,IAAI,OAAO,0BAA0B,aAAa;AAChD,aAAW,2BAA2B;AACxC;",
6
+ "names": []
7
+ }