用例
我有一个卡片列表,并试图创建一个刷左/右火绒风格的功能。我已经开始使用panResponder,但是我遇到了动画backgroundColor的问题。
设置
constructor() {
super();
this.state = {
bgColor: new Animated.Value(0),
};
}
onPanResponderMove: (evt, gestureState) => {
Animated.timing(this.state.bgColor, {
toValue: 1,
duration: 100,
}).start();
}
render() {
const s = this.state;
const p = this.props;
const bgColor = s.bgColor.interpolate({
inputRange: [0, 1],
outputRange: [colors.gray.one, colors.primary.light]
})
return(
<View style={ [styles.wrapper, pushLeft(s.dx)] }>
<View {...this._panResponder.panHandlers} style={ styles.content } onLayout={ this.onLayout }>
{ this.props.children }
<View style={ [styles.overlay, { backgroundColor: bgColor } ]}/>
</View>
</View>
)
}误差
一旦我开始拖动卡片,我就会得到
“无法添加属性_tracking,对象不可扩展”
附加备注
如果我用下面的代码替换对bgColor的内插分配,我不会得到错误,但显然会失去颜色的动画效果。
const bgColor = s.bgColor._value === 0 ? colors.gray.one : colors.primary.light;问题
关于为什么会抛出错误以及如何解决它的想法?
发布于 2016-05-04 02:04:02
要使用动画,您需要一个特殊的“可动画”组件( Animated.View、Animated.Text或Animated.Image,它们是内置的,或者使用Animated.createAnimatedComponent()制作一个新的组件)。这会是你的问题吗?
https://stackoverflow.com/questions/37015189
复制相似问题