@tamagui/animations-react-native 1.114.4 → 1.115.1

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,317 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf,
6
+ __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: !0
11
+ });
12
+ },
13
+ __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: !0
28
+ }) : target, mod)),
29
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
+ value: !0
31
+ }), mod);
32
+ var createAnimations_exports = {};
33
+ __export(createAnimations_exports, {
34
+ AnimatedText: () => AnimatedText,
35
+ AnimatedView: () => AnimatedView,
36
+ createAnimations: () => createAnimations,
37
+ useAnimatedNumber: () => useAnimatedNumber,
38
+ useAnimatedNumberReaction: () => useAnimatedNumberReaction,
39
+ useAnimatedNumberStyle: () => useAnimatedNumberStyle
40
+ });
41
+ module.exports = __toCommonJS(createAnimations_exports);
42
+ var import_react = __toESM(require("react")),
43
+ import_use_presence = require("@tamagui/use-presence"),
44
+ import_constants = require("@tamagui/constants"),
45
+ import_web = require("@tamagui/web"),
46
+ import_react_native = require("react-native-web");
47
+ const animatedStyleKey = {
48
+ transform: !0,
49
+ opacity: !0
50
+ },
51
+ colorStyleKey = {
52
+ backgroundColor: !0,
53
+ color: !0,
54
+ borderColor: !0,
55
+ borderLeftColor: !0,
56
+ borderRightColor: !0,
57
+ borderTopColor: !0,
58
+ borderBottomColor: !0
59
+ },
60
+ costlyToAnimateStyleKey = {
61
+ borderRadius: !0,
62
+ borderTopLeftRadius: !0,
63
+ borderTopRightRadius: !0,
64
+ borderBottomLeftRadius: !0,
65
+ borderBottomRightRadius: !0,
66
+ borderWidth: !0,
67
+ borderLeftWidth: !0,
68
+ borderRightWidth: !0,
69
+ borderTopWidth: !0,
70
+ borderBottomWidth: !0,
71
+ ...colorStyleKey
72
+ // TODO for other keys like height or width, it's better to not add them here till layout animations are ready
73
+ },
74
+ AnimatedView = import_react_native.Animated.View,
75
+ AnimatedText = import_react_native.Animated.Text;
76
+ function useAnimatedNumber(initial) {
77
+ const state = import_react.default.useRef(null);
78
+ return state.current || (state.current = {
79
+ composite: null,
80
+ val: new import_react_native.Animated.Value(initial),
81
+ strategy: {
82
+ type: "spring"
83
+ }
84
+ }), {
85
+ getInstance() {
86
+ return state.current.val;
87
+ },
88
+ getValue() {
89
+ return state.current.val._value;
90
+ },
91
+ stop() {
92
+ state.current.composite?.stop(), state.current.composite = null;
93
+ },
94
+ setValue(next, {
95
+ type,
96
+ ...config
97
+ } = {
98
+ type: "spring"
99
+ }, onFinish) {
100
+ const val = state.current.val,
101
+ handleFinish = onFinish ? ({
102
+ finished
103
+ }) => finished ? onFinish() : null : void 0;
104
+ if (type === "direct") val.setValue(next);else if (type === "spring") {
105
+ state.current.composite?.stop();
106
+ const composite = import_react_native.Animated.spring(val, {
107
+ ...config,
108
+ toValue: next,
109
+ useNativeDriver: !import_constants.isWeb
110
+ });
111
+ composite.start(handleFinish), state.current.composite = composite;
112
+ } else {
113
+ state.current.composite?.stop();
114
+ const composite = import_react_native.Animated.timing(val, {
115
+ ...config,
116
+ toValue: next,
117
+ useNativeDriver: !import_constants.isWeb
118
+ });
119
+ composite.start(handleFinish), state.current.composite = composite;
120
+ }
121
+ }
122
+ };
123
+ }
124
+ function useAnimatedNumberReaction({
125
+ value
126
+ }, onValue) {
127
+ const onChange = (0, import_web.useEvent)(current => {
128
+ onValue(current.value);
129
+ });
130
+ import_react.default.useEffect(() => {
131
+ const id = value.getInstance().addListener(onChange);
132
+ return () => {
133
+ value.getInstance().removeListener(id);
134
+ };
135
+ }, [value, onChange]);
136
+ }
137
+ function useAnimatedNumberStyle(value, getStyle) {
138
+ return getStyle(value.getInstance());
139
+ }
140
+ function createAnimations(animations) {
141
+ return {
142
+ isReactNative: !0,
143
+ animations,
144
+ View: AnimatedView,
145
+ Text: AnimatedText,
146
+ useAnimatedNumber,
147
+ useAnimatedNumberReaction,
148
+ useAnimatedNumberStyle,
149
+ usePresence: import_use_presence.usePresence,
150
+ ResetPresence: import_use_presence.ResetPresence,
151
+ useAnimations: ({
152
+ props,
153
+ onDidAnimate,
154
+ style,
155
+ componentState,
156
+ presence
157
+ }) => {
158
+ const isExiting = presence?.[0] === !1,
159
+ sendExitComplete = presence?.[1],
160
+ animateStyles = import_react.default.useRef({}),
161
+ animatedTranforms = import_react.default.useRef([]),
162
+ animationsState = import_react.default.useRef(/* @__PURE__ */new WeakMap()),
163
+ animateOnly = props.animateOnly || [],
164
+ hasAnimateOnly = !!props.animateOnly,
165
+ args = [JSON.stringify(style), componentState, isExiting, !!onDidAnimate],
166
+ isThereNoNativeStyleKeys = import_react.default.useMemo(() => import_constants.isWeb ? !0 : Object.keys(style).some(key => animateOnly.length ? !animatedStyleKey[key] && animateOnly.indexOf(key) === -1 : !animatedStyleKey[key]), args),
167
+ res = import_react.default.useMemo(() => {
168
+ const runners = [],
169
+ completions = [],
170
+ nonAnimatedStyle = {};
171
+ for (const key in style) {
172
+ const val = style[key];
173
+ if (animatedStyleKey[key] == null && !costlyToAnimateStyleKey[key]) {
174
+ nonAnimatedStyle[key] = val;
175
+ continue;
176
+ }
177
+ if (hasAnimateOnly && !animateOnly.includes(key)) {
178
+ nonAnimatedStyle[key] = val;
179
+ continue;
180
+ }
181
+ if (key !== "transform") {
182
+ animateStyles.current[key] = update(key, animateStyles.current[key], val);
183
+ continue;
184
+ }
185
+ if (val) {
186
+ if (typeof val == "string") {
187
+ console.warn("Warning: Tamagui can't animate string transforms yet!");
188
+ continue;
189
+ }
190
+ for (const [index, transform] of val.entries()) {
191
+ if (!transform) continue;
192
+ const tkey = Object.keys(transform)[0],
193
+ currentTransform = animatedTranforms.current[index]?.[tkey];
194
+ animatedTranforms.current[index] = {
195
+ [tkey]: update(tkey, currentTransform, transform[tkey])
196
+ }, animatedTranforms.current = [...animatedTranforms.current];
197
+ }
198
+ }
199
+ }
200
+ const animatedStyle = {
201
+ ...Object.fromEntries(Object.entries(animateStyles.current).map(([k, v]) => [k, animationsState.current.get(v)?.interpolation || v])),
202
+ transform: animatedTranforms.current.map(r => {
203
+ const key = Object.keys(r)[0],
204
+ val = animationsState.current.get(r[key])?.interpolation || r[key];
205
+ return {
206
+ [key]: val
207
+ };
208
+ })
209
+ };
210
+ return {
211
+ runners,
212
+ completions,
213
+ style: [nonAnimatedStyle, animatedStyle]
214
+ };
215
+ function update(key, animated, valIn) {
216
+ const isColorStyleKey = colorStyleKey[key],
217
+ [val, type] = isColorStyleKey ? [0, void 0] : getValue(valIn);
218
+ let animateToValue = val;
219
+ const value = animated || new import_react_native.Animated.Value(val),
220
+ curInterpolation = animationsState.current.get(value);
221
+ let interpolateArgs;
222
+ if (type && (interpolateArgs = getInterpolated(curInterpolation?.current ?? value._value, val, type), animationsState.current.set(value, {
223
+ interpolation: value.interpolate(interpolateArgs),
224
+ current: val
225
+ })), isColorStyleKey && (animateToValue = curInterpolation?.animateToValue ? 0 : 1, interpolateArgs = getColorInterpolated(curInterpolation?.current,
226
+ // valIn is the next color
227
+ valIn, animateToValue), animationsState.current.set(value, {
228
+ current: valIn,
229
+ interpolation: value.interpolate(interpolateArgs),
230
+ animateToValue: curInterpolation?.animateToValue ? 0 : 1
231
+ })), value) {
232
+ const animationConfig = getAnimationConfig(key, animations, props.animation);
233
+ let resolve;
234
+ const promise = new Promise(res2 => {
235
+ resolve = res2;
236
+ });
237
+ completions.push(promise), runners.push(() => {
238
+ value.stopAnimation();
239
+ function getAnimation() {
240
+ return import_react_native.Animated[animationConfig.type || "spring"](value, {
241
+ toValue: animateToValue,
242
+ useNativeDriver: !import_constants.isWeb && !isThereNoNativeStyleKeys,
243
+ ...animationConfig
244
+ });
245
+ }
246
+ (animationConfig.delay ? import_react_native.Animated.sequence([import_react_native.Animated.delay(animationConfig.delay), getAnimation()]) : getAnimation()).start(({
247
+ finished
248
+ }) => {
249
+ finished && resolve();
250
+ });
251
+ });
252
+ }
253
+ return process.env.NODE_ENV === "development" && props.debug === "verbose" && console.info(" \u{1F4A0} animate", key, `from (${value._value}) to`, valIn, `(${val})`, "type", type, "interpolate", interpolateArgs), value;
254
+ }
255
+ }, args);
256
+ return (0, import_constants.useIsomorphicLayoutEffect)(() => {
257
+ res.runners.forEach(r => r());
258
+ let cancel = !1;
259
+ return Promise.all(res.completions).then(() => {
260
+ cancel || (onDidAnimate?.(), isExiting && sendExitComplete?.());
261
+ }), () => {
262
+ cancel = !0;
263
+ };
264
+ }, args), process.env.NODE_ENV === "development" && props.debug === "verbose" && console.info("Animated", {
265
+ response: res,
266
+ inputStyle: style,
267
+ isExiting
268
+ }), res;
269
+ }
270
+ };
271
+ }
272
+ function getColorInterpolated(currentColor, nextColor, animateToValue) {
273
+ const inputRange = [0, 1],
274
+ outputRange = [currentColor || nextColor, nextColor];
275
+ return animateToValue === 0 && outputRange.reverse(), {
276
+ inputRange,
277
+ outputRange
278
+ };
279
+ }
280
+ function getInterpolated(current, next, postfix = "deg") {
281
+ next === current && (current = next - 1e-9);
282
+ const inputRange = [current, next],
283
+ outputRange = [`${current}${postfix}`, `${next}${postfix}`];
284
+ return next < current && (inputRange.reverse(), outputRange.reverse()), {
285
+ inputRange,
286
+ outputRange
287
+ };
288
+ }
289
+ function getAnimationConfig(key, animations, animation) {
290
+ if (typeof animation == "string") return animations[animation];
291
+ let type = "",
292
+ extraConf;
293
+ const shortKey = transformShorthands[key];
294
+ if (Array.isArray(animation)) {
295
+ type = animation[0];
296
+ const conf = animation[1]?.[key] ?? animation[1]?.[shortKey];
297
+ conf && (typeof conf == "string" ? type = conf : (type = conf.type || type, extraConf = conf));
298
+ } else {
299
+ const val = animation?.[key] ?? animation?.[shortKey];
300
+ type = val?.type, extraConf = val;
301
+ }
302
+ return {
303
+ ...animations[type],
304
+ ...extraConf
305
+ };
306
+ }
307
+ const transformShorthands = {
308
+ x: "translateX",
309
+ y: "translateY",
310
+ translateX: "x",
311
+ translateY: "y"
312
+ };
313
+ function getValue(input, isColor = !1) {
314
+ if (typeof input != "string") return [input];
315
+ const [_, number, after] = input.match(/([-0-9]+)(deg|%|px)/) ?? [];
316
+ return [+number, after];
317
+ }
@@ -0,0 +1,19 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
7
+ get: () => from[key],
8
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
9
+ });
10
+ return to;
11
+ },
12
+ __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
13
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
14
+ value: !0
15
+ }), mod);
16
+ var src_exports = {};
17
+ module.exports = __toCommonJS(src_exports);
18
+ var import_polyfill = require("./polyfill.cjs");
19
+ __reExport(src_exports, require("./createAnimations.cjs"), module.exports);
@@ -1,2 +1 @@
1
- typeof requestAnimationFrame > "u" && (globalThis.requestAnimationFrame = setImmediate);
2
- //# sourceMappingURL=polyfill.js.map
1
+ typeof requestAnimationFrame > "u" && (globalThis.requestAnimationFrame = setImmediate);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/animations-react-native",
3
- "version": "1.114.4",
3
+ "version": "1.115.1",
4
4
  "source": "src/index.ts",
5
5
  "removeSideEffects": true,
6
6
  "sideEffects": [
@@ -22,16 +22,17 @@
22
22
  "react-native": "./dist/cjs/index.native.js",
23
23
  "types": "./types/index.d.ts",
24
24
  "import": "./dist/esm/index.mjs",
25
- "require": "./dist/cjs/index.js"
25
+ "require": "./dist/cjs/index.cjs",
26
+ "default": "./dist/cjs/index.native.js"
26
27
  }
27
28
  },
28
29
  "dependencies": {
29
- "@tamagui/constants": "1.114.4",
30
- "@tamagui/use-presence": "1.114.4",
31
- "@tamagui/web": "1.114.4"
30
+ "@tamagui/constants": "1.115.1",
31
+ "@tamagui/use-presence": "1.115.1",
32
+ "@tamagui/web": "1.115.1"
32
33
  },
33
34
  "devDependencies": {
34
- "@tamagui/build": "1.114.4",
35
+ "@tamagui/build": "1.115.1",
35
36
  "react": "^18.2.0 || ^19.0.0",
36
37
  "react-native": "0.74.1"
37
38
  },
@@ -1,290 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: !0 });
9
- }, __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from == "object" || typeof from == "function")
11
- for (let key of __getOwnPropNames(from))
12
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- return to;
14
- };
15
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
- // If the importer is in node compatibility mode or this is not an ESM
17
- // file that has been converted to a CommonJS file using a Babel-
18
- // compatible transform (i.e. "__esModule" has not been set), then set
19
- // "default" to the CommonJS "module.exports" for node compatibility.
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
- mod
22
- )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
- var createAnimations_exports = {};
24
- __export(createAnimations_exports, {
25
- AnimatedText: () => AnimatedText,
26
- AnimatedView: () => AnimatedView,
27
- createAnimations: () => createAnimations,
28
- useAnimatedNumber: () => useAnimatedNumber,
29
- useAnimatedNumberReaction: () => useAnimatedNumberReaction,
30
- useAnimatedNumberStyle: () => useAnimatedNumberStyle
31
- });
32
- module.exports = __toCommonJS(createAnimations_exports);
33
- var import_react = __toESM(require("react")), import_use_presence = require("@tamagui/use-presence"), import_constants = require("@tamagui/constants"), import_web = require("@tamagui/web"), import_react_native = require("react-native-web");
34
- const animatedStyleKey = {
35
- transform: !0,
36
- opacity: !0
37
- }, colorStyleKey = {
38
- backgroundColor: !0,
39
- color: !0,
40
- borderColor: !0,
41
- borderLeftColor: !0,
42
- borderRightColor: !0,
43
- borderTopColor: !0,
44
- borderBottomColor: !0
45
- }, costlyToAnimateStyleKey = {
46
- borderRadius: !0,
47
- borderTopLeftRadius: !0,
48
- borderTopRightRadius: !0,
49
- borderBottomLeftRadius: !0,
50
- borderBottomRightRadius: !0,
51
- borderWidth: !0,
52
- borderLeftWidth: !0,
53
- borderRightWidth: !0,
54
- borderTopWidth: !0,
55
- borderBottomWidth: !0,
56
- ...colorStyleKey
57
- // TODO for other keys like height or width, it's better to not add them here till layout animations are ready
58
- }, AnimatedView = import_react_native.Animated.View, AnimatedText = import_react_native.Animated.Text;
59
- function useAnimatedNumber(initial) {
60
- const state = import_react.default.useRef(
61
- null
62
- );
63
- return state.current || (state.current = {
64
- composite: null,
65
- val: new import_react_native.Animated.Value(initial),
66
- strategy: { type: "spring" }
67
- }), {
68
- getInstance() {
69
- return state.current.val;
70
- },
71
- getValue() {
72
- return state.current.val._value;
73
- },
74
- stop() {
75
- state.current.composite?.stop(), state.current.composite = null;
76
- },
77
- setValue(next, { type, ...config } = { type: "spring" }, onFinish) {
78
- const val = state.current.val, handleFinish = onFinish ? ({ finished }) => finished ? onFinish() : null : void 0;
79
- if (type === "direct")
80
- val.setValue(next);
81
- else if (type === "spring") {
82
- state.current.composite?.stop();
83
- const composite = import_react_native.Animated.spring(val, {
84
- ...config,
85
- toValue: next,
86
- useNativeDriver: !import_constants.isWeb
87
- });
88
- composite.start(handleFinish), state.current.composite = composite;
89
- } else {
90
- state.current.composite?.stop();
91
- const composite = import_react_native.Animated.timing(val, {
92
- ...config,
93
- toValue: next,
94
- useNativeDriver: !import_constants.isWeb
95
- });
96
- composite.start(handleFinish), state.current.composite = composite;
97
- }
98
- }
99
- };
100
- }
101
- function useAnimatedNumberReaction({ value }, onValue) {
102
- const onChange = (0, import_web.useEvent)((current) => {
103
- onValue(current.value);
104
- });
105
- import_react.default.useEffect(() => {
106
- const id = value.getInstance().addListener(onChange);
107
- return () => {
108
- value.getInstance().removeListener(id);
109
- };
110
- }, [value, onChange]);
111
- }
112
- function useAnimatedNumberStyle(value, getStyle) {
113
- return getStyle(value.getInstance());
114
- }
115
- function createAnimations(animations) {
116
- return {
117
- isReactNative: !0,
118
- animations,
119
- View: AnimatedView,
120
- Text: AnimatedText,
121
- useAnimatedNumber,
122
- useAnimatedNumberReaction,
123
- useAnimatedNumberStyle,
124
- usePresence: import_use_presence.usePresence,
125
- ResetPresence: import_use_presence.ResetPresence,
126
- useAnimations: ({ props, onDidAnimate, style, componentState, presence }) => {
127
- const isExiting = presence?.[0] === !1, sendExitComplete = presence?.[1], animateStyles = import_react.default.useRef({}), animatedTranforms = import_react.default.useRef([]), animationsState = import_react.default.useRef(
128
- /* @__PURE__ */ new WeakMap()
129
- ), animateOnly = props.animateOnly || [], hasAnimateOnly = !!props.animateOnly, args = [JSON.stringify(style), componentState, isExiting, !!onDidAnimate], isThereNoNativeStyleKeys = import_react.default.useMemo(() => import_constants.isWeb ? !0 : Object.keys(style).some((key) => animateOnly.length ? !animatedStyleKey[key] && animateOnly.indexOf(key) === -1 : !animatedStyleKey[key]), args), res = import_react.default.useMemo(() => {
130
- const runners = [], completions = [], nonAnimatedStyle = {};
131
- for (const key in style) {
132
- const val = style[key];
133
- if (animatedStyleKey[key] == null && !costlyToAnimateStyleKey[key]) {
134
- nonAnimatedStyle[key] = val;
135
- continue;
136
- }
137
- if (hasAnimateOnly && !animateOnly.includes(key)) {
138
- nonAnimatedStyle[key] = val;
139
- continue;
140
- }
141
- if (key !== "transform") {
142
- animateStyles.current[key] = update(key, animateStyles.current[key], val);
143
- continue;
144
- }
145
- if (val) {
146
- if (typeof val == "string") {
147
- console.warn("Warning: Tamagui can't animate string transforms yet!");
148
- continue;
149
- }
150
- for (const [index, transform] of val.entries()) {
151
- if (!transform) continue;
152
- const tkey = Object.keys(transform)[0], currentTransform = animatedTranforms.current[index]?.[tkey];
153
- animatedTranforms.current[index] = {
154
- [tkey]: update(tkey, currentTransform, transform[tkey])
155
- }, animatedTranforms.current = [...animatedTranforms.current];
156
- }
157
- }
158
- }
159
- const animatedStyle = {
160
- ...Object.fromEntries(
161
- Object.entries(animateStyles.current).map(([k, v]) => [
162
- k,
163
- animationsState.current.get(v)?.interpolation || v
164
- ])
165
- ),
166
- transform: animatedTranforms.current.map((r) => {
167
- const key = Object.keys(r)[0], val = animationsState.current.get(r[key])?.interpolation || r[key];
168
- return { [key]: val };
169
- })
170
- };
171
- return {
172
- runners,
173
- completions,
174
- style: [nonAnimatedStyle, animatedStyle]
175
- };
176
- function update(key, animated, valIn) {
177
- const isColorStyleKey = colorStyleKey[key], [val, type] = isColorStyleKey ? [0, void 0] : getValue(valIn);
178
- let animateToValue = val;
179
- const value = animated || new import_react_native.Animated.Value(val), curInterpolation = animationsState.current.get(value);
180
- let interpolateArgs;
181
- if (type && (interpolateArgs = getInterpolated(
182
- curInterpolation?.current ?? value._value,
183
- val,
184
- type
185
- ), animationsState.current.set(value, {
186
- interpolation: value.interpolate(interpolateArgs),
187
- current: val
188
- })), isColorStyleKey && (animateToValue = curInterpolation?.animateToValue ? 0 : 1, interpolateArgs = getColorInterpolated(
189
- curInterpolation?.current,
190
- // valIn is the next color
191
- valIn,
192
- animateToValue
193
- ), animationsState.current.set(value, {
194
- current: valIn,
195
- interpolation: value.interpolate(interpolateArgs),
196
- animateToValue: curInterpolation?.animateToValue ? 0 : 1
197
- })), value) {
198
- const animationConfig = getAnimationConfig(key, animations, props.animation);
199
- let resolve;
200
- const promise = new Promise((res2) => {
201
- resolve = res2;
202
- });
203
- completions.push(promise), runners.push(() => {
204
- value.stopAnimation();
205
- function getAnimation() {
206
- return import_react_native.Animated[animationConfig.type || "spring"](value, {
207
- toValue: animateToValue,
208
- useNativeDriver: !import_constants.isWeb && !isThereNoNativeStyleKeys,
209
- ...animationConfig
210
- });
211
- }
212
- (animationConfig.delay ? import_react_native.Animated.sequence([
213
- import_react_native.Animated.delay(animationConfig.delay),
214
- getAnimation()
215
- ]) : getAnimation()).start(({ finished }) => {
216
- finished && resolve();
217
- });
218
- });
219
- }
220
- return process.env.NODE_ENV === "development" && props.debug === "verbose" && console.info(
221
- " \u{1F4A0} animate",
222
- key,
223
- `from (${value._value}) to`,
224
- valIn,
225
- `(${val})`,
226
- "type",
227
- type,
228
- "interpolate",
229
- interpolateArgs
230
- ), value;
231
- }
232
- }, args);
233
- return (0, import_constants.useIsomorphicLayoutEffect)(() => {
234
- res.runners.forEach((r) => r());
235
- let cancel = !1;
236
- return Promise.all(res.completions).then(() => {
237
- cancel || (onDidAnimate?.(), isExiting && sendExitComplete?.());
238
- }), () => {
239
- cancel = !0;
240
- };
241
- }, args), process.env.NODE_ENV === "development" && props.debug === "verbose" && console.info("Animated", { response: res, inputStyle: style, isExiting }), res;
242
- }
243
- };
244
- }
245
- function getColorInterpolated(currentColor, nextColor, animateToValue) {
246
- const inputRange = [0, 1], outputRange = [currentColor || nextColor, nextColor];
247
- return animateToValue === 0 && outputRange.reverse(), {
248
- inputRange,
249
- outputRange
250
- };
251
- }
252
- function getInterpolated(current, next, postfix = "deg") {
253
- next === current && (current = next - 1e-9);
254
- const inputRange = [current, next], outputRange = [`${current}${postfix}`, `${next}${postfix}`];
255
- return next < current && (inputRange.reverse(), outputRange.reverse()), {
256
- inputRange,
257
- outputRange
258
- };
259
- }
260
- function getAnimationConfig(key, animations, animation) {
261
- if (typeof animation == "string")
262
- return animations[animation];
263
- let type = "", extraConf;
264
- const shortKey = transformShorthands[key];
265
- if (Array.isArray(animation)) {
266
- type = animation[0];
267
- const conf = animation[1]?.[key] ?? animation[1]?.[shortKey];
268
- conf && (typeof conf == "string" ? type = conf : (type = conf.type || type, extraConf = conf));
269
- } else {
270
- const val = animation?.[key] ?? animation?.[shortKey];
271
- type = val?.type, extraConf = val;
272
- }
273
- return {
274
- ...animations[type],
275
- ...extraConf
276
- };
277
- }
278
- const transformShorthands = {
279
- x: "translateX",
280
- y: "translateY",
281
- translateX: "x",
282
- translateY: "y"
283
- };
284
- function getValue(input, isColor = !1) {
285
- if (typeof input != "string")
286
- return [input];
287
- const [_, number, after] = input.match(/([-0-9]+)(deg|%|px)/) ?? [];
288
- return [+number, after];
289
- }
290
- //# sourceMappingURL=createAnimations.js.map
package/dist/cjs/index.js DELETED
@@ -1,16 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from == "object" || typeof from == "function")
7
- for (let key of __getOwnPropNames(from))
8
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
- return to;
10
- }, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
11
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
12
- var src_exports = {};
13
- module.exports = __toCommonJS(src_exports);
14
- var import_polyfill = require("./polyfill");
15
- __reExport(src_exports, require("./createAnimations"), module.exports);
16
- //# sourceMappingURL=index.js.map
File without changes
File without changes