我试图制作指南针,但我不知道如何使用磁力计的数据.
这是我的班级指南针:
class Compass extends Component {
constructor(props) {
super(props);
}
componentWillMount(){
this._animeRotation = new Animated.Value(0);
}
componentDidMount() {
this.startAnimation();
}
startAnimation() {
Animated.timing(this._animeRotation, {
toValue: this.props.magn, //<-- What put here?
duration: 1000,
}).start(() => {
this.startAnimation();
});
}
render() {
var interpolatedRotateAnimation = this._animeRotation.interpolate({
inputRange: [0, 100],
outputRange: ['0deg', '360deg']
});
return (
<View>
<Animated.View style={[styles.box, {transform: [{rotate: interpolatedRotateAnimation}]}]}>
<Image style={styles.box} source={require('./arrow.png')}></Image>
</Animated.View>
</View>
);
}
}
Run Code Online (Sandbox Code Playgroud)
这是类App:
class App extends Component {
constructor(props) {
super(props);
this.state = { …
Run Code Online (Sandbox Code Playgroud)