【发布时间】:2017-08-08 11:38:50
【问题描述】:
我正在关注以下 React Native 教程: https://facebook.github.io/react-native/docs/animated.html
但是,我在运行代码时收到以下警告:
失败的道具类型:提供给RCTView的object类型的无效道具opacity
当调用 fade() 时,组件会在没有动画的情况下消失。
这是一个示例代码:
import React, { Component } from 'react';
import {
AppRegistry,
Text,
View,
Animated,
StyleSheet
} from 'react-native';
import Icon from 'react-native-vector-icon/FontAwesome'
export default class Sample extends Component {
state = {
fadeAnim: new Animated.Value(0),
}
fade() {
Animated.timing( // Animate over time
this.state.fadeAnim, // The animated value to drive
{
toValue: 1, // Animate to opacity: 1 (opaque)
duration: 10000, // Make it take a while
}
).start(); // Starts the animation
}
render() {
let { fadeAnim } = this.state;
return (
<View style={styles.container}>
<TouchableHighlight onPress={() => {this.fade()}}>
<Icon name="circle" size={30} color="#fff" style={{opacity: fadeAnim}}
>
</TouchableHighlight>
</View>
);
}
......
}
【问题讨论】:
标签: reactjs react-native