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

Error when using rotation transform and "useNativeDriver: true" in Android #14161

Closed
raulgg opened this issue May 24, 2017 · 19 comments
Closed
Assignees
Labels
Platform: Android Android applications. Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@raulgg
Copy link

raulgg commented May 24, 2017

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
@brentvatne
Copy link
Collaborator

cc @janicduplessis

@hrubilov
Copy link

I have the same issue. RN version: v0.45.1

doomsower added a commit to doomsower/react-native-modal-popover that referenced this issue Jun 18, 2017
@hramos hramos added the Icebox label Aug 16, 2017
@hramos
Copy link
Contributor

hramos commented Aug 16, 2017

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.

@hramos hramos closed this as completed Aug 16, 2017
@syardumi
Copy link

syardumi commented Sep 8, 2017

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 janicduplessis reopened this Sep 9, 2017
@ghentzi
Copy link

ghentzi commented Oct 6, 2017

Hi,

On iOS, rotate value in string format work properly but on Android, you have to use a double value like that : transform: [{rotate: 4.71}].

You can use the Platform module to detect if you are on iOS or Android : transform:[{rotate:(Platform.OS==='ios') ? '-90deg' : 4.71}].

@mkpietrzyk
Copy link

mkpietrzyk commented Oct 15, 2017

Hello, I have the same issue, RN 0.49.2,

When trying @WemagineGuillaume soulution, it throws an error, that Transform can only accept String with 'deg' or 'rad' values. When using double value with Platform.select for android (f.ex. 4.71), the same error as from OP throws up.

Note that I use it to 'static' permanent rotate. Not Animated whatsoever.

@henrikra
Copy link

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

@rdy
Copy link
Contributor

rdy commented Nov 18, 2017

Animating without {useNativeDriver: true} is the only fix I've noted. It will animate correctly but it doesn't work natively. Non-native animations don't throw this same string double error. I tried using doubles (assuming radians) but react-native complains that it wants the rotation as a string. This is under RN 0.49.5.

wli added a commit to wli/react-native-modal-popover that referenced this issue Nov 29, 2017
This fixes an issue with useNativeDriver and Android.
facebook/react-native#14161
wli added a commit to wli/react-native-modal-popover that referenced this issue Nov 29, 2017
This fixes an issue with useNativeDriver and Android.
facebook/react-native#14161
wli added a commit to wli/react-native-modal-popover that referenced this issue Nov 29, 2017
This is due to an underlying react-native bug where strings aren't
evaluated properly when using native drivers.
facebook/react-native#14161
@stale
Copy link

stale bot commented Jan 17, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jan 17, 2018
@wli
Copy link
Contributor

wli commented Jan 17, 2018

This is still a problem on RN 0.51

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Jan 17, 2018
@lvmtam
Copy link

lvmtam commented Jan 31, 2018

I have the same issue with RN 0.49 :(
It will be nice if have someone PR for it

@Noitidart
Copy link

Noitidart commented Mar 3, 2018

I didn't test with "rotate", but "rotateX" and "rotateY" work fine for me.

Stick it into a interpolation but keep it constant. It works fine for me:

        const styleFace = {
            opacity: anim.interpolate({ inputRange:[0,.5,.5,1], outputRange:[1,1,0,0] }),
            transform: [
                { rotateY:anim.interpolate({ inputRange:[0,1], outputRange:['0deg', '180deg'] }) }
            ]
        };

Here I go from 0deg to 180deg. But you can keep it constant.

@hramos hramos removed the Icebox label Mar 8, 2018
@react-native-bot react-native-bot added Android Ran Commands One of our bots successfully processed a command. labels Mar 18, 2018
@react-native-bot react-native-bot added Platform: Android Android applications. Ran Commands One of our bots successfully processed a command. labels Mar 18, 2018
@scisci
Copy link
Contributor

scisci commented Apr 16, 2018

@janicduplessis I opened a PR for this here: #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.

@scisci
Copy link
Contributor

scisci commented Apr 27, 2018

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

@keeleycarrigan
Copy link

Yea I'm getting this too only when using useNativeDriver with Animated.timing. Except for me it animating opacity.

@VitorLuizC
Copy link

@scisci our error seems related to #19931.

I've replace TouchableOpacity to TouchableHighlight on my component and fixed it.

@scalactic
Copy link

Ouw, I could use it. It's code block like that
state={
ViewRotation: new Animated.Value(0),
}
componentDidMount() {
Animated.timing(this.state.ViewRotation, {
toValue: 1,
duration: 5000,
useNativeDriver: true,
easing: Easing.linear
}).start();
}
<Animated.View
style={{
...this.props.style,
transform: [
{
rotateY: this.state.ViewRotation.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '180deg']
})
},
]
}}

...
</Animated.View>

@stale
Copy link

stale bot commented Nov 12, 2018

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Nov 12, 2018
@stale
Copy link

stale bot commented Nov 19, 2018

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Nov 19, 2018
@facebook facebook locked as resolved and limited conversation to collaborators Nov 20, 2018
facebook-github-bot pushed a commit that referenced this issue Jan 31, 2019
Summary:
Fixes #14161
Android crashes in some cases if an animated transform config contains a string value, like a rotation.
This PR fixes that by ensuring all values sent to the native side are doubles. It adds `__transformDataType` to AnimatedTransform.js.

Added integration test `ReactAndroid/src/androidText/js/AnimatedTransformTestModule.js` This test fails with the following error `INSTRUMENTATION_RESULT: longMsg=java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Double`, if the changes to AnimatedTransform.js are reverted.

[Android] [Fixed] - Fixes Android crash on animated style with string rotation
Pull Request resolved: #18872

Differential Revision: D13894676

Pulled By: cpojer

fbshipit-source-id: 297e8132563460802e53f3ac551c3ba9ed943736
grabbou pushed a commit that referenced this issue Feb 4, 2019
Summary:
Fixes #14161
Android crashes in some cases if an animated transform config contains a string value, like a rotation.
This PR fixes that by ensuring all values sent to the native side are doubles. It adds `__transformDataType` to AnimatedTransform.js.

Added integration test `ReactAndroid/src/androidText/js/AnimatedTransformTestModule.js` This test fails with the following error `INSTRUMENTATION_RESULT: longMsg=java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Double`, if the changes to AnimatedTransform.js are reverted.

[Android] [Fixed] - Fixes Android crash on animated style with string rotation
Pull Request resolved: #18872

Differential Revision: D13894676

Pulled By: cpojer

fbshipit-source-id: 297e8132563460802e53f3ac551c3ba9ed943736
matt-oakes pushed a commit to matt-oakes/react-native that referenced this issue Feb 7, 2019
Summary:
Fixes facebook#14161
Android crashes in some cases if an animated transform config contains a string value, like a rotation.
This PR fixes that by ensuring all values sent to the native side are doubles. It adds `__transformDataType` to AnimatedTransform.js.

Added integration test `ReactAndroid/src/androidText/js/AnimatedTransformTestModule.js` This test fails with the following error `INSTRUMENTATION_RESULT: longMsg=java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Double`, if the changes to AnimatedTransform.js are reverted.

[Android] [Fixed] - Fixes Android crash on animated style with string rotation
Pull Request resolved: facebook#18872

Differential Revision: D13894676

Pulled By: cpojer

fbshipit-source-id: 297e8132563460802e53f3ac551c3ba9ed943736
t-nanava pushed a commit to microsoft/react-native-macos that referenced this issue Jun 17, 2019
Summary:
Fixes facebook#14161
Android crashes in some cases if an animated transform config contains a string value, like a rotation.
This PR fixes that by ensuring all values sent to the native side are doubles. It adds `__transformDataType` to AnimatedTransform.js.

Added integration test `ReactAndroid/src/androidText/js/AnimatedTransformTestModule.js` This test fails with the following error `INSTRUMENTATION_RESULT: longMsg=java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Double`, if the changes to AnimatedTransform.js are reverted.

[Android] [Fixed] - Fixes Android crash on animated style with string rotation
Pull Request resolved: facebook#18872

Differential Revision: D13894676

Pulled By: cpojer

fbshipit-source-id: 297e8132563460802e53f3ac551c3ba9ed943736
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Platform: Android Android applications. Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

Successfully merging a pull request may close this issue.