@tamagui/animations-react-native 1.116.0 → 1.116.2
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.
- package/dist/cjs/createAnimations.js +290 -0
- package/dist/cjs/index.js +16 -0
- package/dist/cjs/polyfill.js +2 -0
- package/package.json +5 -5
- /package/dist/cjs/{createAnimations.cjs.map → createAnimations.js.map} +0 -0
- /package/dist/cjs/{index.cjs.map → index.js.map} +0 -0
- /package/dist/cjs/{polyfill.cjs.map → polyfill.js.map} +0 -0
|
@@ -0,0 +1,290 @@
|
|
|
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
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/animations-react-native",
|
|
3
|
-
"version": "1.116.
|
|
3
|
+
"version": "1.116.2",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"removeSideEffects": true,
|
|
6
6
|
"sideEffects": [
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@tamagui/constants": "1.116.
|
|
31
|
-
"@tamagui/use-presence": "1.116.
|
|
32
|
-
"@tamagui/web": "1.116.
|
|
30
|
+
"@tamagui/constants": "1.116.2",
|
|
31
|
+
"@tamagui/use-presence": "1.116.2",
|
|
32
|
+
"@tamagui/web": "1.116.2"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@tamagui/build": "1.116.
|
|
35
|
+
"@tamagui/build": "1.116.2",
|
|
36
36
|
"react": "^18.2.0 || ^19.0.0",
|
|
37
37
|
"react-native": "0.74.1"
|
|
38
38
|
},
|
|
File without changes
|
|
File without changes
|
|
File without changes
|