motion-on-native 1.2.6 → 1.2.8
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/lib/index.d.ts +5 -0
- package/lib/index.js +41 -39
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -92,6 +92,11 @@ export declare const NativeMotion: {
|
|
|
92
92
|
View: (props: MotionComponentProps & import("react-native").ViewProps) => React.ReactElement<import("react-native-reanimated").AnimateProps<any>, string | React.JSXElementConstructor<any>> | null;
|
|
93
93
|
Text: (props: MotionComponentProps & import("react-native").TextProps) => React.ReactElement<import("react-native-reanimated").AnimateProps<any>, string | React.JSXElementConstructor<any>> | null;
|
|
94
94
|
Image: (props: MotionComponentProps & import("react-native").ImageProps) => React.ReactElement<import("react-native-reanimated").AnimateProps<any>, string | React.JSXElementConstructor<any>> | null;
|
|
95
|
+
ImageBackground: (props: MotionComponentProps & import("react-native").ImageBackgroundProps) => React.ReactElement<import("react-native-reanimated").AnimateProps<any>, string | React.JSXElementConstructor<any>> | null;
|
|
95
96
|
TextInput: (props: MotionComponentProps & import("react-native").TextInputProps) => React.ReactElement<import("react-native-reanimated").AnimateProps<any>, string | React.JSXElementConstructor<any>> | null;
|
|
96
97
|
TouchableOpacity: (props: MotionComponentProps & import("react-native").TouchableOpacityProps & React.RefAttributes<View>) => React.ReactElement<import("react-native-reanimated").AnimateProps<any>, string | React.JSXElementConstructor<any>> | null;
|
|
98
|
+
ScrollView: (props: MotionComponentProps & import("react-native").ScrollViewProps) => React.ReactElement<import("react-native-reanimated").AnimateProps<any>, string | React.JSXElementConstructor<any>> | null;
|
|
99
|
+
FlatList: (props: MotionComponentProps & import("react-native").FlatListProps<unknown>) => React.ReactElement<import("react-native-reanimated").AnimateProps<any>, string | React.JSXElementConstructor<any>> | null;
|
|
100
|
+
SectionList: (props: MotionComponentProps & import("react-native").SectionListProps<unknown, unknown>) => React.ReactElement<import("react-native-reanimated").AnimateProps<any>, string | React.JSXElementConstructor<any>> | null;
|
|
101
|
+
Pressable: (props: MotionComponentProps & import("react-native").PressableProps & React.RefAttributes<View>) => React.ReactElement<import("react-native-reanimated").AnimateProps<any>, string | React.JSXElementConstructor<any>> | null;
|
|
97
102
|
};
|
package/lib/index.js
CHANGED
|
@@ -250,18 +250,23 @@ function createMotionComponent(Component) {
|
|
|
250
250
|
default: return null;
|
|
251
251
|
}
|
|
252
252
|
};
|
|
253
|
+
// Memoize animate prop to prevent unnecessary re-animations
|
|
254
|
+
const animateString = JSON.stringify(animate);
|
|
255
|
+
const memoizedAnimate = (0, react_1.useMemo)(() => animate, [animateString]);
|
|
256
|
+
// Set initial values on mount
|
|
257
|
+
(0, react_1.useEffect)(() => {
|
|
258
|
+
if (initial !== false) {
|
|
259
|
+
Object.entries(initial).forEach(([key, value]) => {
|
|
260
|
+
const sharedValue = getSharedValue(key);
|
|
261
|
+
if (sharedValue && value !== undefined) {
|
|
262
|
+
sharedValue.value = value;
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}, []);
|
|
253
267
|
// Mount animation: initial -> animate
|
|
254
268
|
(0, react_1.useEffect)(() => {
|
|
255
269
|
if (!hasAnimated && !isExitingRef.current) {
|
|
256
|
-
// Set initial values immediately
|
|
257
|
-
if (initial !== false) {
|
|
258
|
-
Object.entries(initial).forEach(([key, value]) => {
|
|
259
|
-
const sharedValue = getSharedValue(key);
|
|
260
|
-
if (sharedValue && value !== undefined) {
|
|
261
|
-
sharedValue.value = value;
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
270
|
// Animate to target values
|
|
266
271
|
const timer = setTimeout(() => {
|
|
267
272
|
if (!isExitingRef.current) {
|
|
@@ -272,9 +277,7 @@ function createMotionComponent(Component) {
|
|
|
272
277
|
return () => clearTimeout(timer);
|
|
273
278
|
}
|
|
274
279
|
return undefined;
|
|
275
|
-
}, []);
|
|
276
|
-
// Memoize animate prop to prevent unnecessary re-animations
|
|
277
|
-
const memoizedAnimate = (0, react_1.useMemo)(() => animate, [JSON.stringify(animate)]);
|
|
280
|
+
}, [memoizedAnimate]);
|
|
278
281
|
// Handle animate prop changes (only animate if values actually changed)
|
|
279
282
|
const prevAnimateRef = (0, react_1.useRef)(memoizedAnimate);
|
|
280
283
|
(0, react_1.useEffect)(() => {
|
|
@@ -290,46 +293,40 @@ function createMotionComponent(Component) {
|
|
|
290
293
|
// Handle shouldExit
|
|
291
294
|
(0, react_1.useEffect)(() => {
|
|
292
295
|
var _a;
|
|
293
|
-
if (shouldExit && !isExitingRef.current) {
|
|
296
|
+
if (shouldExit && !isExitingRef.current && exit && Object.keys(exit).length > 0) {
|
|
294
297
|
isExitingRef.current = true;
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
setTimeout(() => {
|
|
299
|
-
setIsPresent(false);
|
|
300
|
-
if (onExitComplete) {
|
|
301
|
-
onExitComplete();
|
|
302
|
-
}
|
|
303
|
-
}, exitDuration);
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
298
|
+
animateToValues(exit, transition);
|
|
299
|
+
const exitDuration = (_a = transition.duration) !== null && _a !== void 0 ? _a : 300;
|
|
300
|
+
setTimeout(() => {
|
|
306
301
|
setIsPresent(false);
|
|
307
302
|
if (onExitComplete) {
|
|
308
303
|
onExitComplete();
|
|
309
304
|
}
|
|
310
|
-
}
|
|
305
|
+
}, exitDuration);
|
|
311
306
|
}
|
|
312
307
|
else if (!shouldExit && isExitingRef.current) {
|
|
313
308
|
// Re-entering: reset everything
|
|
314
309
|
isExitingRef.current = false;
|
|
315
310
|
setIsPresent(true);
|
|
316
311
|
setHasAnimated(false);
|
|
317
|
-
// Reset to initial values
|
|
318
|
-
if (initial !== false) {
|
|
319
|
-
Object.entries(initial).forEach(([key, value]) => {
|
|
320
|
-
const sharedValue = getSharedValue(key);
|
|
321
|
-
if (sharedValue && value !== undefined) {
|
|
322
|
-
sharedValue.value = value;
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
// Animate to target after a frame
|
|
312
|
+
// Reset to initial values and animate
|
|
327
313
|
setTimeout(() => {
|
|
328
|
-
if (
|
|
329
|
-
|
|
330
|
-
|
|
314
|
+
if (initial !== false) {
|
|
315
|
+
Object.entries(initial).forEach(([key, value]) => {
|
|
316
|
+
const sharedValue = getSharedValue(key);
|
|
317
|
+
if (sharedValue && value !== undefined) {
|
|
318
|
+
sharedValue.value = value;
|
|
319
|
+
}
|
|
320
|
+
});
|
|
331
321
|
}
|
|
332
|
-
|
|
322
|
+
// Animate to target after a frame
|
|
323
|
+
setTimeout(() => {
|
|
324
|
+
if (!isExitingRef.current) {
|
|
325
|
+
animateToValues(memoizedAnimate);
|
|
326
|
+
setHasAnimated(true);
|
|
327
|
+
}
|
|
328
|
+
}, 16);
|
|
329
|
+
}, 0);
|
|
333
330
|
}
|
|
334
331
|
}, [shouldExit]);
|
|
335
332
|
// Animated style
|
|
@@ -507,6 +504,11 @@ exports.NativeMotion = {
|
|
|
507
504
|
View: createMotionComponent(react_native_1.View),
|
|
508
505
|
Text: createMotionComponent(react_native_1.Text),
|
|
509
506
|
Image: createMotionComponent(react_native_1.Image),
|
|
507
|
+
ImageBackground: createMotionComponent(react_native_1.ImageBackground),
|
|
510
508
|
TextInput: createMotionComponent(react_native_1.TextInput),
|
|
511
509
|
TouchableOpacity: createMotionComponent(react_native_1.TouchableOpacity),
|
|
510
|
+
ScrollView: createMotionComponent(react_native_1.ScrollView),
|
|
511
|
+
FlatList: createMotionComponent(react_native_1.FlatList),
|
|
512
|
+
SectionList: createMotionComponent(react_native_1.SectionList),
|
|
513
|
+
Pressable: createMotionComponent(react_native_1.Pressable),
|
|
512
514
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "motion-on-native",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.8",
|
|
4
4
|
"description": "Framer Motion-inspired animation library for React Native with Reanimated. Easy spring animations, gestures, and transitions for mobile apps.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|