motion-on-native 1.2.3 → 1.2.5

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 +9 -7
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -261,7 +261,7 @@ function createMotionComponent(Component) {
261
261
  // Animate to target values
262
262
  const timer = setTimeout(() => {
263
263
  if (!isExitingRef.current) {
264
- animateToValues(animate);
264
+ animateToValues(memoizedAnimate);
265
265
  setHasAnimated(true);
266
266
  }
267
267
  }, 16);
@@ -269,18 +269,20 @@ function createMotionComponent(Component) {
269
269
  }
270
270
  return undefined;
271
271
  }, []);
272
+ // Memoize animate prop to prevent unnecessary re-animations
273
+ const memoizedAnimate = (0, react_1.useMemo)(() => animate, [JSON.stringify(animate)]);
272
274
  // Handle animate prop changes (only animate if values actually changed)
273
- const prevAnimateRef = (0, react_1.useRef)(animate);
275
+ const prevAnimateRef = (0, react_1.useRef)(memoizedAnimate);
274
276
  (0, react_1.useEffect)(() => {
275
277
  if (hasAnimated && !isExitingRef.current) {
276
278
  // Only animate if animate prop actually changed
277
- const hasChanged = JSON.stringify(prevAnimateRef.current) !== JSON.stringify(animate);
279
+ const hasChanged = JSON.stringify(prevAnimateRef.current) !== JSON.stringify(memoizedAnimate);
278
280
  if (hasChanged) {
279
- animateToValues(animate);
280
- prevAnimateRef.current = animate;
281
+ animateToValues(memoizedAnimate);
282
+ prevAnimateRef.current = memoizedAnimate;
281
283
  }
282
284
  }
283
- }, [animate]);
285
+ }, [memoizedAnimate]);
284
286
  // Handle shouldExit
285
287
  (0, react_1.useEffect)(() => {
286
288
  var _a;
@@ -320,7 +322,7 @@ function createMotionComponent(Component) {
320
322
  // Animate to target after a frame
321
323
  setTimeout(() => {
322
324
  if (!isExitingRef.current) {
323
- animateToValues(animate);
325
+ animateToValues(memoizedAnimate);
324
326
  setHasAnimated(true);
325
327
  }
326
328
  }, 16);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "motion-on-native",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
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",