【发布时间】:2018-02-08 08:04:16
【问题描述】:
我正在研究如何在 React Native 中为颜色设置动画,并遵循本教程 https://codedaily.io/screencasts/8/Animate-Colors-with-React-Native-Interpolate
我所做的只是首先运行react-native init,然后用这个替换我的 App.js 中的代码
import { StyleSheet, View, Text, Animated } from 'react-native';
import React, { Component } from 'react';
export default class App extends Component {
componentDidMount() {
this.animatedValue = new Animated.Value(0);
}
componentDidMount() {
Animated.timing(this.animatedValue, {
toValue: 150,
duration: 1500
}).start();
}
render() {
const interpolateColor = this.animatedValue.interpolate({
inputRange: [0, 150],
outputRange: ['rgb(0,0,0)', 'rga(51,250,170)']
});
const animatedStyle = {
backgroundColor: interpolateColor
}
return (
<Animated.View style={[{ width: 50, height: 50 }, animatedStyle]} />
);
}
}
然后运行react-native run-android
现在我不断收到TypeError:undefined is not an object(evaluating 'this.animatedValue.interpolate')
【问题讨论】:
-
有一个'componentDidMount'重复。
标签: javascript react-native react-animated