Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Animated] Cannot animate string transform properties (v0.19) #2528

Closed
1 task done
Aashu-Dubey opened this issue May 29, 2023 · 11 comments
Closed
1 task done

[Animated] Cannot animate string transform properties (v0.19) #2528

Aashu-Dubey opened this issue May 29, 2023 · 11 comments
Labels
Milestone

Comments

@Aashu-Dubey
Copy link

Aashu-Dubey commented May 29, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the issue

It seems that after rn-web v0.19, it is recommended to use space-separated string functions on web instead of array, as we get these deprecation warnings

image

though they work fine on web, but we can't apply animations using them as of now, as I'm getting this error even when using the styles without animation on any Animated component
image

Expected behavior

animation on these new string functions should work fine, as it is working in case of array transform right now.

Steps to reproduce

You can clearly see the issue in the attached sandbox.

For a bigger example, I had the issue when I was recently trying to fix these warning on this sample app (Web Demo), there are few places where I'm using these styles and they are working fine, but can't use them where animations are needed.

Test case

https://codesandbox.io/s/rn-web-string-transform-bug-g1eqvy

Additional comments

Currently I'm using ...Platform.select({ web : { transform: 'rotate(45deg)' } }) approach to apply these styles, as they don't yet seems to be cross compatible with native platforms.

Do let me know if there's any particular approach to apply animations here or if this is something to be fix in future version of the package.

Thanks!

@necolas necolas added this to the 0.19.x milestone May 31, 2023
@necolas necolas changed the title [Animation] Cannot animate string transform properties (v0.19) [Animated] Cannot animate string transform properties (v0.19) May 31, 2023
@chrispader

This comment was marked as duplicate.

@necolas
Copy link
Owner

necolas commented Jun 27, 2023

This is a bug in React Native too 34425

@dan-doyon-endear
Copy link

Here is patch that works for us in interim

diff --git a/node_modules/react-native-web/dist/vendor/react-native/Animated/nodes/AnimatedTransform.js b/node_modules/react-native-web/dist/vendor/react-native/Animated/nodes/AnimatedTransform.js
index 66072d9..b92ada1 100644
--- a/node_modules/react-native-web/dist/vendor/react-native/Animated/nodes/AnimatedTransform.js
+++ b/node_modules/react-native-web/dist/vendor/react-native/Animated/nodes/AnimatedTransform.js
@@ -16,7 +16,7 @@ import NativeAnimatedHelper from '../NativeAnimatedHelper';
 class AnimatedTransform extends AnimatedWithChildren {
   constructor(transforms) {
     super();
-    this._transforms = transforms;
+    this._transforms = transforms || [];
   }
   __makeNative() {
     this._transforms.forEach(transform => {

@necolas
Copy link
Owner

necolas commented Jun 28, 2023

That doesn't "work", it just skips over the issue

@dan-doyon-endear
Copy link

dan-doyon-endear commented Jun 28, 2023

That doesn't "work", it just skips over the issue

Fair enough, we're not doing a lot with transforms and it enabled us to migrate to latest version.

@dan-doyon-endear

This comment was marked as off-topic.

@necolas
Copy link
Owner

necolas commented Jun 28, 2023

Aashu-Dubey in the test case, you're trying to stringify an animated object:

web: { transform: `rotate(${rotate})` }

That will never work.

What you can do is interpolate the whole string value (which will work in RN), or animate only therotate property (which will work only on web for now)

   const rotate = anim.current.interpolate({
     inputRange: [0, 1],
     outputRange: ["rotate(0deg)", "rotate(45deg)"]
   });

// ...

{ transform: rotate }

Or

   const rotate = anim.current.interpolate({
     inputRange: [0, 1],
     outputRange: ["0deg", "45deg"]
   });

// ...

web: { rotate: rotate }

@dan-doyon-endear

This comment was marked as off-topic.

@getusha
Copy link

getusha commented Aug 26, 2023

What you can do is interpolate the whole string value (which will work in RN)

@necolas it is not working on Animated.View

Screenshot 2023-08-26 at 1 28 34 PM

It appears to be functioning correctly with the View component; however, it seems that it is not supported within the Animation.View

<Animated.View style={ {transform: 'scale(2)'}} >
    ....
</Animated.View>

@Gregoirevda
Copy link

Is there a way to combine 2+ animated values into a single transform string?

  const translateX = Animated.divide(Animated.multiply(progress, progressBarWidth), 2).interpolate({
    inputRange: [0, 1],
    outputRange: ['translateX(0)', 'translateX(1)'],
  });

  const scaleX = Animated.multiply(progress, progressBarWidth).interpolate({
    inputRange: [0, 1],
    outputRange: ['scaleX(0)', 'scaleX(1)'],
  });

@kevtronkrueger
Copy link

I'll second the question from @Gregoirevda
I do not understand what the intended future-friendly implementation is for 2+ animated objects on a single Animated.View.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants