我正在尝试在 Animated Api 中使用 interpolate 函数,当我使用 Image 组件时,这是可行的,但是当我使用 Animated.Image 时,什么也没有出现,或者如果我用一个值硬编码旋转它也不起作用或抛出错误.
import React from 'react';
import { StyleSheet, Text, View, Animated, Easing, Image} from 'react-native';
export default class App extends React.Component {
state = {spinValue : new Animated.Value(0)}
componentDidMount(){
Animated.timing(
this.state.spinValue,
{
toValue: 1,
duration: 3000,
easing: Easing.linear
}
).start()
}
spin = this.state.spinValue.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '360deg']
})
render() {
return (
<View style={styles.container}>
<Animated.Image
style={{transform: [{rotate: "90deg"}] }}
source={{uri: 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Square_-_black_simple.svg/1200px-Square_-_black_simple.svg.png'}} />
<Text>Testing</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});