How do you rotate and translate at the same time? In the sample below I was expecting the square to move to right and rotate about its own axis maintaining the same central y axis. If you can imagine a wheel travelling along a road
Instead, it flys off wildly
Any help would be appreciated
import React, { Component } from "react";
import {
AppRegistry,
StyleSheet,
Text,
View,
Animated
} from "react-native";
class App extends Component {
componentWillMount () {
this._animatedValue = new Animated.Value(0);
}
componentDidMount () {
Animated.timing(this._animatedValue, {
toValue: 100,
duration: 3000
}).start();
}
render () {
const interpolatedRotateAnimation = this._animatedValue.interpolate({
inputRange: [0, 100],
outputRange: ['0deg', '360deg']
});
const interpolatedRotateX = this._animatedValue.interpolate({
inputRange: [0, 100],
outputRange: [0, 200]
});
return (
<View style={styles.container}>
<Animated.View
style={[styles.box, {transform: [
{rotate: interpolatedRotateAnimation},
{translateX:interpolatedRotateX}
]}
]}
/>
</View>
);
}
};
const styles = StyleSheet.create({
container: {
flex: 1
},
box: {
backgroundColor: 'red',
position: 'absolute',
top: 100,
left: 100,
width: 100,
height: 100
}
});
export default App