motion-on-native 1.2.4 → 1.2.6

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 CHANGED
@@ -5,6 +5,8 @@ export interface AnimationProps {
5
5
  x?: number;
6
6
  y?: number;
7
7
  z?: number;
8
+ translateX?: number;
9
+ translateY?: number;
8
10
  scale?: number;
9
11
  scaleX?: number;
10
12
  scaleY?: number;
package/lib/index.js CHANGED
@@ -67,6 +67,8 @@ function createMotionComponent(Component) {
67
67
  const x = (0, react_native_reanimated_1.useSharedValue)(getInitialValue('x', initial));
68
68
  const y = (0, react_native_reanimated_1.useSharedValue)(getInitialValue('y', initial));
69
69
  const z = (0, react_native_reanimated_1.useSharedValue)(getInitialValue('z', initial));
70
+ const translateX = (0, react_native_reanimated_1.useSharedValue)(getInitialValue('translateX', initial));
71
+ const translateY = (0, react_native_reanimated_1.useSharedValue)(getInitialValue('translateY', initial));
70
72
  const scale = (0, react_native_reanimated_1.useSharedValue)(getInitialValue('scale', initial));
71
73
  const scaleX = (0, react_native_reanimated_1.useSharedValue)(getInitialValue('scaleX', initial));
72
74
  const scaleY = (0, react_native_reanimated_1.useSharedValue)(getInitialValue('scaleY', initial));
@@ -183,6 +185,8 @@ function createMotionComponent(Component) {
183
185
  case 'x': return x;
184
186
  case 'y': return y;
185
187
  case 'z': return z;
188
+ case 'translateX': return translateX;
189
+ case 'translateY': return translateY;
186
190
  case 'scale': return scale;
187
191
  case 'scaleX': return scaleX;
188
192
  case 'scaleY': return scaleY;
@@ -261,7 +265,7 @@ function createMotionComponent(Component) {
261
265
  // Animate to target values
262
266
  const timer = setTimeout(() => {
263
267
  if (!isExitingRef.current) {
264
- animateToValues(animate);
268
+ animateToValues(memoizedAnimate);
265
269
  setHasAnimated(true);
266
270
  }
267
271
  }, 16);
@@ -269,20 +273,20 @@ function createMotionComponent(Component) {
269
273
  }
270
274
  return undefined;
271
275
  }, []);
276
+ // Memoize animate prop to prevent unnecessary re-animations
277
+ const memoizedAnimate = (0, react_1.useMemo)(() => animate, [JSON.stringify(animate)]);
272
278
  // Handle animate prop changes (only animate if values actually changed)
273
- const prevAnimateRef = (0, react_1.useRef)(animate);
274
- const animateStringRef = (0, react_1.useRef)(JSON.stringify(animate));
279
+ const prevAnimateRef = (0, react_1.useRef)(memoizedAnimate);
275
280
  (0, react_1.useEffect)(() => {
276
281
  if (hasAnimated && !isExitingRef.current) {
277
282
  // Only animate if animate prop actually changed
278
- const currentAnimateString = JSON.stringify(animate);
279
- if (animateStringRef.current !== currentAnimateString) {
280
- animateToValues(animate);
281
- prevAnimateRef.current = animate;
282
- animateStringRef.current = currentAnimateString;
283
+ const hasChanged = JSON.stringify(prevAnimateRef.current) !== JSON.stringify(memoizedAnimate);
284
+ if (hasChanged) {
285
+ animateToValues(memoizedAnimate);
286
+ prevAnimateRef.current = memoizedAnimate;
283
287
  }
284
288
  }
285
- }, [animate]);
289
+ }, [memoizedAnimate]);
286
290
  // Handle shouldExit
287
291
  (0, react_1.useEffect)(() => {
288
292
  var _a;
@@ -322,7 +326,7 @@ function createMotionComponent(Component) {
322
326
  // Animate to target after a frame
323
327
  setTimeout(() => {
324
328
  if (!isExitingRef.current) {
325
- animateToValues(animate);
329
+ animateToValues(memoizedAnimate);
326
330
  setHasAnimated(true);
327
331
  }
328
332
  }, 16);
@@ -340,6 +344,10 @@ function createMotionComponent(Component) {
340
344
  transform.push({ translateY: y.value });
341
345
  if (z.value !== 0)
342
346
  transform.push({ translateZ: z.value });
347
+ if (translateX.value !== 0)
348
+ transform.push({ translateX: translateX.value });
349
+ if (translateY.value !== 0)
350
+ transform.push({ translateY: translateY.value });
343
351
  if (scale.value !== 1)
344
352
  transform.push({ scale: scale.value });
345
353
  if (scaleX.value !== 1)
@@ -481,6 +489,8 @@ function getDefaultValue(key) {
481
489
  case 'x':
482
490
  case 'y':
483
491
  case 'z':
492
+ case 'translateX':
493
+ case 'translateY':
484
494
  return 0;
485
495
  case 'rotate':
486
496
  case 'rotateX':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "motion-on-native",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
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",