Skip to content

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

Closed

Description

@Aashu-Dubey

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!

Activity

  1. added this to the 0.19.x milestone on May 31, 2023
  2. changed the title [-][Animation] Cannot animate string transform properties (v0.19)[/-] [+][Animated] Cannot animate string transform properties (v0.19)[/+] on May 31, 2023
  3. chrispader commented on Jun 7, 2023

    @chrispader
  4. necolas commented on Jun 27, 2023

    @necolas
    Owner

    This is a bug in React Native too 34425

  5. added a commit that references this issue on Jun 27, 2023
    ed83baa
  6. dan-doyon-endear commented on Jun 28, 2023

    @dan-doyon-endear

    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 => {
    
    
  7. necolas commented on Jun 28, 2023

    @necolas
    Owner

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

  8. dan-doyon-endear commented on Jun 28, 2023

    @dan-doyon-endear

    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.

  9. dan-doyon-endear commented on Jun 28, 2023

    @dan-doyon-endear
  10. necolas commented on Jun 28, 2023

    @necolas
    Owner

    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 }
    
  11. added a commit that references this issue on Jun 28, 2023
    869c416
  12. dan-doyon-endear commented on Jun 28, 2023

    @dan-doyon-endear
  13. getusha commented on Aug 26, 2023

    @getusha

    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>
  14. Gregoirevda commented on Dec 14, 2023

    @Gregoirevda

    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)'],
      });
  15. kevtronkrueger commented on Jan 22, 2024

    @kevtronkrueger

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions