You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error when using rotation transform and "useNativeDriver: true" in Android #14161
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:
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>
);
}
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.
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.
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.
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.
Reacted by Henrik Raitasola, dblachut-adb, Calin Tamas, scalactic and Maen
Reacted by Henrik Raitasola, zaiz91, scalactic and Rory Pickering
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.
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.
Activity
brentvatne commentedon May 26, 2017
cc @janicduplessis
hrubilov commentedon Jun 11, 2017
I have the same issue. RN version: v0.45.1
Make useNativeDriver work on Android too
hramos commentedon 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:
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.
syardumi commentedon 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.ghentzi commentedon 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 commentedon 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 commentedon Oct 17, 2017
I noticed this bug too and none of the "fixes" in this thread are not working. Using RN 0.48.4
rdy commentedon 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.16 remaining items
scisci commentedon 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.Doublewhich, when searched didn't bring this issue up, so I'm just writing it here.scisci commentedon Apr 27, 2018
@janicduplessis @hramos what is the process for getting this merged? Currently forces people to setNativeDriver to false.
keeleycarrigan commentedon May 2, 2018
Yea I'm getting this too only when using
useNativeDriverwithAnimated.timing. Except for me it animating opacity.VitorLuizC commentedon Jul 24, 2018
@scisci our error seems related to #19931.
I've replace
TouchableOpacitytoTouchableHighlighton my component and fixed it.scalactic commentedon Aug 1, 2018
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 commentedon 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 commentedon 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.
Fix Native Rotation Android (#18872)
Fix Native Rotation Android (#18872)
Fix Native Rotation Android (react#18872)