React native 为什么赢了';我的动画API组件是否在React Native中显示?
我正在尝试在动画Api中使用插值函数,当我使用图像组件时,它可以工作,但当我使用动画.Image时,不会显示任何内容,或者如果我使用值硬编码旋转,它也不会工作或引发错误React native 为什么赢了';我的动画API组件是否在React Native中显示?,react-native,react-animated,React Native,React Animated,我正在尝试在动画Api中使用插值函数,当我使用图像组件时,它可以工作,但当我使用动画.Image时,不会显示任何内容,或者如果我使用值硬编码旋转,它也不会工作或引发错误 import React from 'react'; import { StyleSheet, Text, View, Animated, Easing, Image} from 'react-native'; export default class App extends React.Component { stat
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',
},
});
从“React”导入React;
从“react native”导入{样式表、文本、视图、动画、图像};
导出默认类App扩展React.Component{
状态={spinValue:新的动画.Value(0)}
componentDidMount(){
时间(
这个.state.spinValue,
{
toValue:1,
时长:3000,
放松:放松。线性
}
).start()
}
spin=this.state.spinValue.interpolate({
输入范围:[0,1],
输出范围:['0deg','360deg']
})
render(){
返回(
测试
);
}
}
const styles=StyleSheet.create({
容器:{
弹性:1,
背景颜色:“#fff”,
对齐项目:“居中”,
为内容辩护:“中心”,
},
});
来自React本机文档:
请注意,对于网络图像和数据图像,您需要手动指定图像的尺寸
您需要在样式道具中添加宽度和高度