@hanzogui/animations-moti 8.3.0 → 8.3.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 +304 -0
- package/dist/cjs/createAnimations.js.map +1 -0
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/polyfill.js +10 -0
- package/dist/cjs/polyfill.js.map +1 -0
- package/dist/esm/createAnimations.js +300 -0
- package/dist/esm/createAnimations.js.map +1 -0
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/polyfill.js +10 -0
- package/dist/esm/polyfill.js.map +1 -0
- package/package.json +17 -17
- package/src/index.ts +2 -2
- package/types/createAnimations.d.ts +2 -3
- package/types/createAnimations.d.ts.map +1 -11
- package/types/index.d.ts +2 -3
- package/types/index.d.ts.map +1 -11
- package/types/polyfill.d.ts +0 -1
- package/types/polyfill.d.ts.map +1 -11
- package/dist/cjs/createAnimations.cjs +0 -308
- package/dist/cjs/createAnimations.native.js +0 -328
- package/dist/cjs/createAnimations.native.js.map +0 -1
- package/dist/cjs/index.cjs +0 -21
- package/dist/cjs/index.native.js +0 -24
- package/dist/cjs/index.native.js.map +0 -1
- package/dist/cjs/polyfill.cjs +0 -6
- package/dist/cjs/polyfill.native.js +0 -9
- package/dist/cjs/polyfill.native.js.map +0 -1
- package/dist/esm/createAnimations.mjs +0 -272
- package/dist/esm/createAnimations.mjs.map +0 -1
- package/dist/esm/createAnimations.native.js +0 -289
- package/dist/esm/createAnimations.native.js.map +0 -1
- package/dist/esm/index.mjs +0 -3
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js +0 -3
- package/dist/esm/index.native.js.map +0 -1
- package/dist/esm/polyfill.mjs +0 -7
- package/dist/esm/polyfill.mjs.map +0 -1
- package/dist/esm/polyfill.native.js +0 -7
- package/dist/esm/polyfill.native.js.map +0 -1
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAnimations = createAnimations;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
// @ts-nocheck - deprecated package, moti dependency intentionally not included
|
|
7
|
+
const use_presence_1 = require("@hanzogui/use-presence");
|
|
8
|
+
// we need core for hooks.usePropsTransform
|
|
9
|
+
const core_1 = require("@hanzogui/core");
|
|
10
|
+
// Helper to resolve dynamic theme values like {dynamic: {dark: "value", light: undefined}}
|
|
11
|
+
const resolveDynamicValue = (value, isDark) => {
|
|
12
|
+
if (value && typeof value === 'object' && 'dynamic' in value) {
|
|
13
|
+
const dynamicValue = isDark ? value.dynamic.dark : value.dynamic.light;
|
|
14
|
+
return dynamicValue;
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
};
|
|
18
|
+
const author_1 = require("moti/author");
|
|
19
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
20
|
+
const react_native_reanimated_1 = tslib_1.__importStar(require("react-native-reanimated"));
|
|
21
|
+
// fix for building with type module
|
|
22
|
+
// see https://github.com/evanw/esbuild/issues/2480#issuecomment-1833104754
|
|
23
|
+
const safeESModule = (a) => {
|
|
24
|
+
const b = a;
|
|
25
|
+
const out = b.__esModule || b[Symbol.toStringTag] === 'Module' ? b.default : b;
|
|
26
|
+
// add metro support
|
|
27
|
+
return out || a;
|
|
28
|
+
};
|
|
29
|
+
const Animated = safeESModule(react_native_reanimated_1.default);
|
|
30
|
+
// this is our own custom reanimated animated component so we can allow data- attributes, className etc
|
|
31
|
+
// this should ultimately be merged with react-native-web-lite
|
|
32
|
+
function createGuiAnimatedComponent(defaultTag = 'div') {
|
|
33
|
+
const isText = defaultTag === 'span';
|
|
34
|
+
const Component = Animated.createAnimatedComponent((0, react_1.forwardRef)((propsIn, ref) => {
|
|
35
|
+
const { forwardedRef, animation, render = defaultTag, ...propsRest } = propsIn;
|
|
36
|
+
const hostRef = (0, react_1.useRef)(null);
|
|
37
|
+
const composedRefs = (0, core_1.useComposedRefs)(forwardedRef, ref, hostRef);
|
|
38
|
+
const stateRef = (0, react_1.useRef)(null);
|
|
39
|
+
if (!stateRef.current) {
|
|
40
|
+
stateRef.current = {
|
|
41
|
+
get host() {
|
|
42
|
+
return hostRef.current;
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const [_, state] = (0, core_1.useThemeWithState)({});
|
|
47
|
+
// get styles but only inline style
|
|
48
|
+
const result = (0, core_1.getSplitStyles)(propsRest, isText ? core_1.Text.staticConfig : core_1.View.staticConfig, state?.theme, state?.name, {
|
|
49
|
+
unmounted: false,
|
|
50
|
+
}, {
|
|
51
|
+
isAnimated: false,
|
|
52
|
+
noClass: true,
|
|
53
|
+
});
|
|
54
|
+
const props = result?.viewProps || {};
|
|
55
|
+
const Element = render;
|
|
56
|
+
const transformedProps = core_1.hooks.usePropsTransform?.(render, props, stateRef, false);
|
|
57
|
+
return (0, jsx_runtime_1.jsx)(Element, { ...transformedProps, ref: composedRefs });
|
|
58
|
+
}));
|
|
59
|
+
Component['acceptRenderProp'] = true;
|
|
60
|
+
return Component;
|
|
61
|
+
}
|
|
62
|
+
const AnimatedView = createGuiAnimatedComponent('div');
|
|
63
|
+
const AnimatedText = createGuiAnimatedComponent('span');
|
|
64
|
+
// const AnimatedView = styled(View, {
|
|
65
|
+
// disableClassName: true,
|
|
66
|
+
// })
|
|
67
|
+
// const AnimatedText = styled(Text, {
|
|
68
|
+
// disableClassName: true,
|
|
69
|
+
// })
|
|
70
|
+
const onlyAnimateKeys = {
|
|
71
|
+
transform: true,
|
|
72
|
+
opacity: true,
|
|
73
|
+
height: true,
|
|
74
|
+
width: true,
|
|
75
|
+
backgroundColor: true,
|
|
76
|
+
borderColor: true,
|
|
77
|
+
borderLeftColor: true,
|
|
78
|
+
borderRightColor: true,
|
|
79
|
+
borderTopColor: true,
|
|
80
|
+
borderBottomColor: true,
|
|
81
|
+
borderRadius: true,
|
|
82
|
+
borderTopLeftRadius: true,
|
|
83
|
+
borderTopRightRadius: true,
|
|
84
|
+
borderBottomLeftRadius: true,
|
|
85
|
+
borderBottomRightRadius: true,
|
|
86
|
+
borderLeftWidth: true,
|
|
87
|
+
borderRightWidth: true,
|
|
88
|
+
borderTopWidth: true,
|
|
89
|
+
borderBottomWidth: true,
|
|
90
|
+
color: true,
|
|
91
|
+
left: true,
|
|
92
|
+
right: true,
|
|
93
|
+
top: true,
|
|
94
|
+
bottom: true,
|
|
95
|
+
fontSize: true,
|
|
96
|
+
fontWeight: true,
|
|
97
|
+
lineHeight: true,
|
|
98
|
+
letterSpacing: true,
|
|
99
|
+
};
|
|
100
|
+
function createAnimations(animations) {
|
|
101
|
+
return {
|
|
102
|
+
needsCustomComponent: true,
|
|
103
|
+
View: core_1.isWeb ? AnimatedView : Animated.View,
|
|
104
|
+
Text: core_1.isWeb ? AnimatedText : Animated.Text,
|
|
105
|
+
// View: Animated.View,
|
|
106
|
+
// Text: Animated.Text,
|
|
107
|
+
isReactNative: true,
|
|
108
|
+
inputStyle: 'value',
|
|
109
|
+
outputStyle: 'inline',
|
|
110
|
+
animations,
|
|
111
|
+
usePresence: use_presence_1.usePresence,
|
|
112
|
+
ResetPresence: use_presence_1.ResetPresence,
|
|
113
|
+
useAnimatedNumber(initial) {
|
|
114
|
+
const sharedValue = (0, react_native_reanimated_1.useSharedValue)(initial);
|
|
115
|
+
return react_1.default.useMemo(() => ({
|
|
116
|
+
getInstance() {
|
|
117
|
+
'worklet';
|
|
118
|
+
return sharedValue;
|
|
119
|
+
},
|
|
120
|
+
getValue() {
|
|
121
|
+
'worklet';
|
|
122
|
+
return sharedValue.value;
|
|
123
|
+
},
|
|
124
|
+
setValue(next, config = { type: 'spring' }, onFinish) {
|
|
125
|
+
'worklet';
|
|
126
|
+
if (config.type === 'direct') {
|
|
127
|
+
sharedValue.value = next;
|
|
128
|
+
onFinish?.();
|
|
129
|
+
}
|
|
130
|
+
else if (config.type === 'spring') {
|
|
131
|
+
sharedValue.value = (0, react_native_reanimated_1.withSpring)(next, config, onFinish
|
|
132
|
+
? () => {
|
|
133
|
+
'worklet';
|
|
134
|
+
(0, react_native_reanimated_1.runOnJS)(onFinish)();
|
|
135
|
+
}
|
|
136
|
+
: undefined);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
sharedValue.value = (0, react_native_reanimated_1.withTiming)(next, config, onFinish
|
|
140
|
+
? () => {
|
|
141
|
+
'worklet';
|
|
142
|
+
(0, react_native_reanimated_1.runOnJS)(onFinish)();
|
|
143
|
+
}
|
|
144
|
+
: undefined);
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
stop() {
|
|
148
|
+
'worklet';
|
|
149
|
+
(0, react_native_reanimated_1.cancelAnimation)(sharedValue);
|
|
150
|
+
},
|
|
151
|
+
}), [sharedValue]);
|
|
152
|
+
},
|
|
153
|
+
useAnimatedNumberReaction({ value }, onValue) {
|
|
154
|
+
const instance = value.getInstance();
|
|
155
|
+
return (0, react_native_reanimated_1.useAnimatedReaction)(() => {
|
|
156
|
+
return instance.value;
|
|
157
|
+
}, (next, prev) => {
|
|
158
|
+
if (prev !== next) {
|
|
159
|
+
// @nate what is the point of this hook? is this necessary?
|
|
160
|
+
// without runOnJS, onValue would need to be a worklet
|
|
161
|
+
(0, react_native_reanimated_1.runOnJS)(onValue)(next);
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
// dependency array is very important here
|
|
165
|
+
[onValue, instance]);
|
|
166
|
+
},
|
|
167
|
+
/**
|
|
168
|
+
* `getStyle` must be a worklet
|
|
169
|
+
*/
|
|
170
|
+
useAnimatedNumberStyle(val, getStyle) {
|
|
171
|
+
const instance = val.getInstance();
|
|
172
|
+
// this seems wrong but it works
|
|
173
|
+
const derivedValue = (0, react_native_reanimated_1.useDerivedValue)(() => {
|
|
174
|
+
return instance.value;
|
|
175
|
+
// dependency array is very important here
|
|
176
|
+
}, [instance, getStyle]);
|
|
177
|
+
return (0, react_native_reanimated_1.useAnimatedStyle)(() => {
|
|
178
|
+
return getStyle(derivedValue.value);
|
|
179
|
+
// dependency array is very important here
|
|
180
|
+
}, [val, getStyle, derivedValue, instance]);
|
|
181
|
+
},
|
|
182
|
+
useAnimations: (animationProps) => {
|
|
183
|
+
const { props, presence, style, componentState } = animationProps;
|
|
184
|
+
const animationKey = Array.isArray(props.transition)
|
|
185
|
+
? props.transition[0]
|
|
186
|
+
: props.transition;
|
|
187
|
+
const isHydrating = componentState.unmounted === true;
|
|
188
|
+
const disableAnimation = isHydrating || !animationKey;
|
|
189
|
+
const presenceContext = react_1.default.useContext(use_presence_1.PresenceContext);
|
|
190
|
+
const [, themeState] = (0, core_1.useThemeWithState)({});
|
|
191
|
+
// Check scheme first, then fall back to checking theme name for 'dark'
|
|
192
|
+
const isDark = themeState?.scheme === 'dark' || themeState?.name?.startsWith('dark');
|
|
193
|
+
// this memo is very important for performance, there's a big cost to
|
|
194
|
+
// updating these values every render
|
|
195
|
+
const { dontAnimate, motiProps } = (0, react_1.useMemo)(() => {
|
|
196
|
+
let animate = {};
|
|
197
|
+
let dontAnimate = {};
|
|
198
|
+
if (disableAnimation) {
|
|
199
|
+
// Resolve dynamic objects based on current theme
|
|
200
|
+
for (const key in style) {
|
|
201
|
+
const rawValue = style[key];
|
|
202
|
+
const value = resolveDynamicValue(rawValue, isDark);
|
|
203
|
+
if (value === undefined)
|
|
204
|
+
continue;
|
|
205
|
+
dontAnimate[key] = value;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
const animateOnly = props.animateOnly;
|
|
210
|
+
for (const key in style) {
|
|
211
|
+
const rawValue = style[key];
|
|
212
|
+
// Resolve dynamic theme values (like $theme-dark)
|
|
213
|
+
const value = resolveDynamicValue(rawValue, isDark);
|
|
214
|
+
if (value === undefined)
|
|
215
|
+
continue;
|
|
216
|
+
if (!onlyAnimateKeys[key] ||
|
|
217
|
+
value === 'auto' ||
|
|
218
|
+
(typeof value === 'string' && value.startsWith('calc')) ||
|
|
219
|
+
(animateOnly && !animateOnly.includes(key))) {
|
|
220
|
+
dontAnimate[key] = value;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
animate[key] = value;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// if we don't do this moti seems to flicker a frame before applying animation
|
|
228
|
+
if (componentState.unmounted === 'should-enter') {
|
|
229
|
+
// Resolve dynamic objects based on current theme
|
|
230
|
+
for (const key in style) {
|
|
231
|
+
const rawValue = style[key];
|
|
232
|
+
const value = resolveDynamicValue(rawValue, isDark);
|
|
233
|
+
if (value === undefined)
|
|
234
|
+
continue;
|
|
235
|
+
dontAnimate[key] = value;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const styles = animate;
|
|
239
|
+
const isExiting = Boolean(presence?.[1]);
|
|
240
|
+
const usePresenceValue = (presence || undefined);
|
|
241
|
+
// TODO moti is giving us type troubles, but this should work
|
|
242
|
+
let transition = isHydrating
|
|
243
|
+
? { type: 'transition', duration: 0 }
|
|
244
|
+
: animations[animationKey];
|
|
245
|
+
let hasClonedTransition = false;
|
|
246
|
+
if (Array.isArray(props.transition)) {
|
|
247
|
+
const config = props.transition[1];
|
|
248
|
+
if (config && typeof config === 'object') {
|
|
249
|
+
for (const key in config) {
|
|
250
|
+
const val = config[key];
|
|
251
|
+
// performance - this seems to have (strangely) huge performance effect in uniswap
|
|
252
|
+
// so instead of cloning up front, we clone only when we absolutely have to
|
|
253
|
+
if (!hasClonedTransition) {
|
|
254
|
+
transition = Object.assign({}, transition);
|
|
255
|
+
hasClonedTransition = true;
|
|
256
|
+
}
|
|
257
|
+
// referencing a pre-defined config
|
|
258
|
+
if (typeof val === 'string') {
|
|
259
|
+
transition[key] = animations[val];
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
transition[key] = val;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
dontAnimate,
|
|
269
|
+
motiProps: {
|
|
270
|
+
animate: isExiting || componentState.unmounted === true ? {} : styles,
|
|
271
|
+
transition: componentState.unmounted ? { duration: 0 } : transition,
|
|
272
|
+
usePresenceValue,
|
|
273
|
+
presenceContext,
|
|
274
|
+
exit: isExiting ? styles : undefined,
|
|
275
|
+
},
|
|
276
|
+
};
|
|
277
|
+
}, [
|
|
278
|
+
presenceContext,
|
|
279
|
+
presence,
|
|
280
|
+
animationKey,
|
|
281
|
+
componentState.unmounted,
|
|
282
|
+
JSON.stringify(style),
|
|
283
|
+
presenceContext,
|
|
284
|
+
isDark,
|
|
285
|
+
]);
|
|
286
|
+
const moti = (0, author_1.useMotify)(motiProps);
|
|
287
|
+
if (process.env.NODE_ENV === 'development' &&
|
|
288
|
+
props['debug'] &&
|
|
289
|
+
props['debug'] !== 'profile') {
|
|
290
|
+
console.info(`useMotify(`, JSON.stringify(motiProps, null, 2) + ')', {
|
|
291
|
+
'componentState.unmounted': componentState.unmounted,
|
|
292
|
+
animationProps,
|
|
293
|
+
motiProps,
|
|
294
|
+
moti,
|
|
295
|
+
style: [dontAnimate, moti.style],
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
style: [dontAnimate, moti.style],
|
|
300
|
+
};
|
|
301
|
+
},
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
//# sourceMappingURL=createAnimations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createAnimations.js","sourceRoot":"","sources":["../../src/createAnimations.tsx"],"names":[],"mappings":";;;;;AAAA,+EAA+E;AAC/E,yDAAoF;AACpF,2CAA2C;AAC3C,yCAUuB;AAEvB,2FAA2F;AAC3F,MAAM,mBAAmB,GAAG,CAAC,KAAU,EAAE,MAAe,EAAO,EAAE;IAC/D,IAAI,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AC,SAAS,CAAC,CAAA;YAEjC,IACE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa;gBACtC,KAAK,CAAC,OAAO,CAAC;gBACd,KAAK,CAAC,OAAO,CAAC,KAAK,SAAS,EAC5B,CAAC;gBACD,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,GAAG,EAAE;oBACnE,0BAA0B,EAAE,cAAc,CAAC,SAAS;oBACpD,cAAc;oBACd,SAAS;oBACT,IAAI;oBACJ,KAAK,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC;iBACjC,CAAC,CAAA;YACJ,CAAC;YAED,OAAO;gBACL,KAAK,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC;aACjC,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yBAAsB;AAEtB,gEAAsC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "commonjs" }
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// for SSR
|
|
3
|
+
if (typeof requestAnimationFrame === 'undefined') {
|
|
4
|
+
globalThis['requestAnimationFrame'] = setTimeout;
|
|
5
|
+
}
|
|
6
|
+
// for reanimated
|
|
7
|
+
if (typeof global === 'undefined') {
|
|
8
|
+
globalThis['global'] = globalThis;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=polyfill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyfill.js","sourceRoot":"","sources":["../../src/polyfill.ts"],"names":[],"mappings":";AAAA,UAAU;AACV,IAAI,OAAO,qBAAqB,KAAK,WAAW,EAAE,CAAC;IACjD,UAAU,CAAC,uBAAuB,CAAC,GAAG,UAAU,CAAA;AAClD,CAAC;AAED,iBAAiB;AACjB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,UAAU,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAA;AACnC,CAAC"}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// @ts-nocheck - deprecated package, moti dependency intentionally not included
|
|
3
|
+
import { PresenceContext, ResetPresence, usePresence } from '@hanzogui/use-presence';
|
|
4
|
+
// we need core for hooks.usePropsTransform
|
|
5
|
+
import { getSplitStyles, hooks, isWeb, Text, useComposedRefs, useThemeWithState, View, } from '@hanzogui/core';
|
|
6
|
+
// Helper to resolve dynamic theme values like {dynamic: {dark: "value", light: undefined}}
|
|
7
|
+
const resolveDynamicValue = (value, isDark) => {
|
|
8
|
+
if (value && typeof value === 'object' && 'dynamic' in value) {
|
|
9
|
+
const dynamicValue = isDark ? value.dynamic.dark : value.dynamic.light;
|
|
10
|
+
return dynamicValue;
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
};
|
|
14
|
+
import { useMotify } from 'moti/author';
|
|
15
|
+
import React, { forwardRef, useMemo, useRef } from 'react';
|
|
16
|
+
import Animated_, { cancelAnimation, runOnJS, useAnimatedReaction, useAnimatedStyle, useDerivedValue, useSharedValue, withSpring, withTiming, } from 'react-native-reanimated';
|
|
17
|
+
// fix for building with type module
|
|
18
|
+
// see https://github.com/evanw/esbuild/issues/2480#issuecomment-1833104754
|
|
19
|
+
const safeESModule = (a) => {
|
|
20
|
+
const b = a;
|
|
21
|
+
const out = b.__esModule || b[Symbol.toStringTag] === 'Module' ? b.default : b;
|
|
22
|
+
// add metro support
|
|
23
|
+
return out || a;
|
|
24
|
+
};
|
|
25
|
+
const Animated = safeESModule(Animated_);
|
|
26
|
+
// this is our own custom reanimated animated component so we can allow data- attributes, className etc
|
|
27
|
+
// this should ultimately be merged with react-native-web-lite
|
|
28
|
+
function createGuiAnimatedComponent(defaultTag = 'div') {
|
|
29
|
+
const isText = defaultTag === 'span';
|
|
30
|
+
const Component = Animated.createAnimatedComponent(forwardRef((propsIn, ref) => {
|
|
31
|
+
const { forwardedRef, animation, render = defaultTag, ...propsRest } = propsIn;
|
|
32
|
+
const hostRef = useRef(null);
|
|
33
|
+
const composedRefs = useComposedRefs(forwardedRef, ref, hostRef);
|
|
34
|
+
const stateRef = useRef(null);
|
|
35
|
+
if (!stateRef.current) {
|
|
36
|
+
stateRef.current = {
|
|
37
|
+
get host() {
|
|
38
|
+
return hostRef.current;
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const [_, state] = useThemeWithState({});
|
|
43
|
+
// get styles but only inline style
|
|
44
|
+
const result = getSplitStyles(propsRest, isText ? Text.staticConfig : View.staticConfig, state?.theme, state?.name, {
|
|
45
|
+
unmounted: false,
|
|
46
|
+
}, {
|
|
47
|
+
isAnimated: false,
|
|
48
|
+
noClass: true,
|
|
49
|
+
});
|
|
50
|
+
const props = result?.viewProps || {};
|
|
51
|
+
const Element = render;
|
|
52
|
+
const transformedProps = hooks.usePropsTransform?.(render, props, stateRef, false);
|
|
53
|
+
return _jsx(Element, { ...transformedProps, ref: composedRefs });
|
|
54
|
+
}));
|
|
55
|
+
Component['acceptRenderProp'] = true;
|
|
56
|
+
return Component;
|
|
57
|
+
}
|
|
58
|
+
const AnimatedView = createGuiAnimatedComponent('div');
|
|
59
|
+
const AnimatedText = createGuiAnimatedComponent('span');
|
|
60
|
+
// const AnimatedView = styled(View, {
|
|
61
|
+
// disableClassName: true,
|
|
62
|
+
// })
|
|
63
|
+
// const AnimatedText = styled(Text, {
|
|
64
|
+
// disableClassName: true,
|
|
65
|
+
// })
|
|
66
|
+
const onlyAnimateKeys = {
|
|
67
|
+
transform: true,
|
|
68
|
+
opacity: true,
|
|
69
|
+
height: true,
|
|
70
|
+
width: true,
|
|
71
|
+
backgroundColor: true,
|
|
72
|
+
borderColor: true,
|
|
73
|
+
borderLeftColor: true,
|
|
74
|
+
borderRightColor: true,
|
|
75
|
+
borderTopColor: true,
|
|
76
|
+
borderBottomColor: true,
|
|
77
|
+
borderRadius: true,
|
|
78
|
+
borderTopLeftRadius: true,
|
|
79
|
+
borderTopRightRadius: true,
|
|
80
|
+
borderBottomLeftRadius: true,
|
|
81
|
+
borderBottomRightRadius: true,
|
|
82
|
+
borderLeftWidth: true,
|
|
83
|
+
borderRightWidth: true,
|
|
84
|
+
borderTopWidth: true,
|
|
85
|
+
borderBottomWidth: true,
|
|
86
|
+
color: true,
|
|
87
|
+
left: true,
|
|
88
|
+
right: true,
|
|
89
|
+
top: true,
|
|
90
|
+
bottom: true,
|
|
91
|
+
fontSize: true,
|
|
92
|
+
fontWeight: true,
|
|
93
|
+
lineHeight: true,
|
|
94
|
+
letterSpacing: true,
|
|
95
|
+
};
|
|
96
|
+
export function createAnimations(animations) {
|
|
97
|
+
return {
|
|
98
|
+
needsCustomComponent: true,
|
|
99
|
+
View: isWeb ? AnimatedView : Animated.View,
|
|
100
|
+
Text: isWeb ? AnimatedText : Animated.Text,
|
|
101
|
+
// View: Animated.View,
|
|
102
|
+
// Text: Animated.Text,
|
|
103
|
+
isReactNative: true,
|
|
104
|
+
inputStyle: 'value',
|
|
105
|
+
outputStyle: 'inline',
|
|
106
|
+
animations,
|
|
107
|
+
usePresence,
|
|
108
|
+
ResetPresence,
|
|
109
|
+
useAnimatedNumber(initial) {
|
|
110
|
+
const sharedValue = useSharedValue(initial);
|
|
111
|
+
return React.useMemo(() => ({
|
|
112
|
+
getInstance() {
|
|
113
|
+
'worklet';
|
|
114
|
+
return sharedValue;
|
|
115
|
+
},
|
|
116
|
+
getValue() {
|
|
117
|
+
'worklet';
|
|
118
|
+
return sharedValue.value;
|
|
119
|
+
},
|
|
120
|
+
setValue(next, config = { type: 'spring' }, onFinish) {
|
|
121
|
+
'worklet';
|
|
122
|
+
if (config.type === 'direct') {
|
|
123
|
+
sharedValue.value = next;
|
|
124
|
+
onFinish?.();
|
|
125
|
+
}
|
|
126
|
+
else if (config.type === 'spring') {
|
|
127
|
+
sharedValue.value = withSpring(next, config, onFinish
|
|
128
|
+
? () => {
|
|
129
|
+
'worklet';
|
|
130
|
+
runOnJS(onFinish)();
|
|
131
|
+
}
|
|
132
|
+
: undefined);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
sharedValue.value = withTiming(next, config, onFinish
|
|
136
|
+
? () => {
|
|
137
|
+
'worklet';
|
|
138
|
+
runOnJS(onFinish)();
|
|
139
|
+
}
|
|
140
|
+
: undefined);
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
stop() {
|
|
144
|
+
'worklet';
|
|
145
|
+
cancelAnimation(sharedValue);
|
|
146
|
+
},
|
|
147
|
+
}), [sharedValue]);
|
|
148
|
+
},
|
|
149
|
+
useAnimatedNumberReaction({ value }, onValue) {
|
|
150
|
+
const instance = value.getInstance();
|
|
151
|
+
return useAnimatedReaction(() => {
|
|
152
|
+
return instance.value;
|
|
153
|
+
}, (next, prev) => {
|
|
154
|
+
if (prev !== next) {
|
|
155
|
+
// @nate what is the point of this hook? is this necessary?
|
|
156
|
+
// without runOnJS, onValue would need to be a worklet
|
|
157
|
+
runOnJS(onValue)(next);
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
// dependency array is very important here
|
|
161
|
+
[onValue, instance]);
|
|
162
|
+
},
|
|
163
|
+
/**
|
|
164
|
+
* `getStyle` must be a worklet
|
|
165
|
+
*/
|
|
166
|
+
useAnimatedNumberStyle(val, getStyle) {
|
|
167
|
+
const instance = val.getInstance();
|
|
168
|
+
// this seems wrong but it works
|
|
169
|
+
const derivedValue = useDerivedValue(() => {
|
|
170
|
+
return instance.value;
|
|
171
|
+
// dependency array is very important here
|
|
172
|
+
}, [instance, getStyle]);
|
|
173
|
+
return useAnimatedStyle(() => {
|
|
174
|
+
return getStyle(derivedValue.value);
|
|
175
|
+
// dependency array is very important here
|
|
176
|
+
}, [val, getStyle, derivedValue, instance]);
|
|
177
|
+
},
|
|
178
|
+
useAnimations: (animationProps) => {
|
|
179
|
+
const { props, presence, style, componentState } = animationProps;
|
|
180
|
+
const animationKey = Array.isArray(props.transition)
|
|
181
|
+
? props.transition[0]
|
|
182
|
+
: props.transition;
|
|
183
|
+
const isHydrating = componentState.unmounted === true;
|
|
184
|
+
const disableAnimation = isHydrating || !animationKey;
|
|
185
|
+
const presenceContext = React.useContext(PresenceContext);
|
|
186
|
+
const [, themeState] = useThemeWithState({});
|
|
187
|
+
// Check scheme first, then fall back to checking theme name for 'dark'
|
|
188
|
+
const isDark = themeState?.scheme === 'dark' || themeState?.name?.startsWith('dark');
|
|
189
|
+
// this memo is very important for performance, there's a big cost to
|
|
190
|
+
// updating these values every render
|
|
191
|
+
const { dontAnimate, motiProps } = useMemo(() => {
|
|
192
|
+
let animate = {};
|
|
193
|
+
let dontAnimate = {};
|
|
194
|
+
if (disableAnimation) {
|
|
195
|
+
// Resolve dynamic objects based on current theme
|
|
196
|
+
for (const key in style) {
|
|
197
|
+
const rawValue = style[key];
|
|
198
|
+
const value = resolveDynamicValue(rawValue, isDark);
|
|
199
|
+
if (value === undefined)
|
|
200
|
+
continue;
|
|
201
|
+
dontAnimate[key] = value;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
const animateOnly = props.animateOnly;
|
|
206
|
+
for (const key in style) {
|
|
207
|
+
const rawValue = style[key];
|
|
208
|
+
// Resolve dynamic theme values (like $theme-dark)
|
|
209
|
+
const value = resolveDynamicValue(rawValue, isDark);
|
|
210
|
+
if (value === undefined)
|
|
211
|
+
continue;
|
|
212
|
+
if (!onlyAnimateKeys[key] ||
|
|
213
|
+
value === 'auto' ||
|
|
214
|
+
(typeof value === 'string' && value.startsWith('calc')) ||
|
|
215
|
+
(animateOnly && !animateOnly.includes(key))) {
|
|
216
|
+
dontAnimate[key] = value;
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
animate[key] = value;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
// if we don't do this moti seems to flicker a frame before applying animation
|
|
224
|
+
if (componentState.unmounted === 'should-enter') {
|
|
225
|
+
// Resolve dynamic objects based on current theme
|
|
226
|
+
for (const key in style) {
|
|
227
|
+
const rawValue = style[key];
|
|
228
|
+
const value = resolveDynamicValue(rawValue, isDark);
|
|
229
|
+
if (value === undefined)
|
|
230
|
+
continue;
|
|
231
|
+
dontAnimate[key] = value;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const styles = animate;
|
|
235
|
+
const isExiting = Boolean(presence?.[1]);
|
|
236
|
+
const usePresenceValue = (presence || undefined);
|
|
237
|
+
// TODO moti is giving us type troubles, but this should work
|
|
238
|
+
let transition = isHydrating
|
|
239
|
+
? { type: 'transition', duration: 0 }
|
|
240
|
+
: animations[animationKey];
|
|
241
|
+
let hasClonedTransition = false;
|
|
242
|
+
if (Array.isArray(props.transition)) {
|
|
243
|
+
const config = props.transition[1];
|
|
244
|
+
if (config && typeof config === 'object') {
|
|
245
|
+
for (const key in config) {
|
|
246
|
+
const val = config[key];
|
|
247
|
+
// performance - this seems to have (strangely) huge performance effect in uniswap
|
|
248
|
+
// so instead of cloning up front, we clone only when we absolutely have to
|
|
249
|
+
if (!hasClonedTransition) {
|
|
250
|
+
transition = Object.assign({}, transition);
|
|
251
|
+
hasClonedTransition = true;
|
|
252
|
+
}
|
|
253
|
+
// referencing a pre-defined config
|
|
254
|
+
if (typeof val === 'string') {
|
|
255
|
+
transition[key] = animations[val];
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
transition[key] = val;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
dontAnimate,
|
|
265
|
+
motiProps: {
|
|
266
|
+
animate: isExiting || componentState.unmounted === true ? {} : styles,
|
|
267
|
+
transition: componentState.unmounted ? { duration: 0 } : transition,
|
|
268
|
+
usePresenceValue,
|
|
269
|
+
presenceContext,
|
|
270
|
+
exit: isExiting ? styles : undefined,
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
}, [
|
|
274
|
+
presenceContext,
|
|
275
|
+
presence,
|
|
276
|
+
animationKey,
|
|
277
|
+
componentState.unmounted,
|
|
278
|
+
JSON.stringify(style),
|
|
279
|
+
presenceContext,
|
|
280
|
+
isDark,
|
|
281
|
+
]);
|
|
282
|
+
const moti = useMotify(motiProps);
|
|
283
|
+
if (process.env.NODE_ENV === 'development' &&
|
|
284
|
+
props['debug'] &&
|
|
285
|
+
props['debug'] !== 'profile') {
|
|
286
|
+
console.info(`useMotify(`, JSON.stringify(motiProps, null, 2) + ')', {
|
|
287
|
+
'componentState.unmounted': componentState.unmounted,
|
|
288
|
+
animationProps,
|
|
289
|
+
motiProps,
|
|
290
|
+
moti,
|
|
291
|
+
style: [dontAnimate, moti.style],
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
style: [dontAnimate, moti.style],
|
|
296
|
+
};
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
//# sourceMappingURL=createAnimations.js.map
|