我正在研究如何在本机反应中为颜色设置动画并遵循本教程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')