motion-on-native 1.2.5 → 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.
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;
@@ -246,18 +250,23 @@ function createMotionComponent(Component) {
246
250
  default: return null;
247
251
  }
248
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
+ }, []);
249
267
  // Mount animation: initial -> animate
250
268
  (0, react_1.useEffect)(() => {
251
269
  if (!hasAnimated && !isExitingRef.current) {
252
- // Set initial values immediately
253
- if (initial !== false) {
254
- Object.entries(initial).forEach(([key, value]) => {
255
- const sharedValue = getSharedValue(key);
256
- if (sharedValue && value !== undefined) {
257
- sharedValue.value = value;
258
- }
259
- });
260
- }
261
270
  // Animate to target values
262
271
  const timer = setTimeout(() => {
263
272
  if (!isExitingRef.current) {
@@ -268,9 +277,7 @@ function createMotionComponent(Component) {
268
277
  return () => clearTimeout(timer);
269
278
  }
270
279
  return undefined;
271
- }, []);
272
- // Memoize animate prop to prevent unnecessary re-animations
273
- const memoizedAnimate = (0, react_1.useMemo)(() => animate, [JSON.stringify(animate)]);
280
+ }, [memoizedAnimate]);
274
281
  // Handle animate prop changes (only animate if values actually changed)
275
282
  const prevAnimateRef = (0, react_1.useRef)(memoizedAnimate);
276
283
  (0, react_1.useEffect)(() => {
@@ -310,22 +317,24 @@ function createMotionComponent(Component) {
310
317
  isExitingRef.current = false;
311
318
  setIsPresent(true);
312
319
  setHasAnimated(false);
313
- // Reset to initial values
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
- });
321
- }
322
- // Animate to target after a frame
320
+ // Reset to initial values and animate
323
321
  setTimeout(() => {
324
- if (!isExitingRef.current) {
325
- animateToValues(memoizedAnimate);
326
- 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
+ });
327
329
  }
328
- }, 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);
329
338
  }
330
339
  }, [shouldExit]);
331
340
  // Animated style
@@ -340,6 +349,10 @@ function createMotionComponent(Component) {
340
349
  transform.push({ translateY: y.value });
341
350
  if (z.value !== 0)
342
351
  transform.push({ translateZ: z.value });
352
+ if (translateX.value !== 0)
353
+ transform.push({ translateX: translateX.value });
354
+ if (translateY.value !== 0)
355
+ transform.push({ translateY: translateY.value });
343
356
  if (scale.value !== 1)
344
357
  transform.push({ scale: scale.value });
345
358
  if (scaleX.value !== 1)
@@ -481,6 +494,8 @@ function getDefaultValue(key) {
481
494
  case 'x':
482
495
  case 'y':
483
496
  case 'z':
497
+ case 'translateX':
498
+ case 'translateY':
484
499
  return 0;
485
500
  case 'rotate':
486
501
  case 'rotateX':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "motion-on-native",
3
- "version": "1.2.5",
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",