motion-on-native 1.2.6 → 1.2.7

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.
Files changed (2) hide show
  1. package/lib/index.js +31 -26
  2. package/package.json +1 -1
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)(() => {
@@ -314,22 +317,24 @@ function createMotionComponent(Component) {
314
317
  isExitingRef.current = false;
315
318
  setIsPresent(true);
316
319
  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
320
+ // Reset to initial values and animate
327
321
  setTimeout(() => {
328
- if (!isExitingRef.current) {
329
- animateToValues(memoizedAnimate);
330
- setHasAnimated(true);
322
+ if (initial !== false) {
323
+ Object.entries(initial).forEach(([key, value]) => {
324
+ const sharedValue = getSharedValue(key);
325
+ if (sharedValue && value !== undefined) {
326
+ sharedValue.value = value;
327
+ }
328
+ });
331
329
  }
332
- }, 16);
330
+ // Animate to target after a frame
331
+ setTimeout(() => {
332
+ if (!isExitingRef.current) {
333
+ animateToValues(memoizedAnimate);
334
+ setHasAnimated(true);
335
+ }
336
+ }, 16);
337
+ }, 0);
333
338
  }
334
339
  }, [shouldExit]);
335
340
  // Animated style
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "motion-on-native",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
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",