react-native: Error when using rotation transform and "useNativeDriver: true" in Android

Description

Animation do not work on Android when useNativeDriver is true and using a rotation transform setting the its angle as a String value. But it works as expected when setting it in radians using a double value. I usually set the rotation using a String as it is specified in the documentation, but in this case it crashes as it is expecting a double value.

The error I am getting is the following:

error screenshot

Reproduction Steps and Sample Code

The following code sample would work either changing useNativeDriver to false or setting the rotation in radians.

  animateOpacity() {
    console.log('animation')
    Animated.timing(
      this.state.opacity_anim,
      {toValue: 1, duration: 600, useNativeDriver: true}
    ).start()
  }
  
  render() {
    return (
      <View style={styles.container}>
        {/* If the rotate transform is set in radians it works, but it doesn't when setting it in degrees with a string value. */}
        <Animated.View style={[
            styles.block,
            {
              transform: [{rotate: '90deg'}],
              opacity: this.state.opacity_anim
            }
        ]}>
          <Text style={styles.message}>Some text</Text>
        </Animated.View>
      </View>
    );
  }

I wrote an example in Expo as well: https://snack.expo.io/SJGbutsl-

Additional Information

  • React Native version: v0.44.0, v0.43.0
  • Platform: Android
  • Development Operating System: macOS 10.12.5
  • Dev tools: Android SDK 25.2.5, Android 7.0

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 8
  • Comments: 19 (5 by maintainers)

Commits related to this issue

Most upvoted comments

@janicduplessis I opened a PR for this here: https://github.com/facebook/react-native/pull/18872

The error that appears is java.lang.String cannot be cast to java.lang.Double which, when searched didn’t bring this issue up, so I’m just writing it here.

I noticed this bug too and none of the “fixes” in this thread are not working. Using RN 0.48.4

I can confirm this is still a bug in RN 0.48 and narrowed down to the line ...transform: [{rotate: '90deg'}],... . Using Android 8.0. Please re-open.

@janicduplessis @hramos what is the process for getting this merged? Currently forces people to setNativeDriver to false.

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we’re automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.