[英]Can't add property _tracking, object is not extensible
USE CASE 使用案例
I have a list of cards and am trying to create a swipe left/right tinder style functionality. 我有一张卡片列表,我正在尝试创建左/右滑块式滑动功能。 I have gotten the swiping to work with panResponder, but am running into issues animating the backgroundColor 我已经使用panResponder进行了滑动,但遇到了动画backgroundColor的问题
SETUP 建立
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>
)
}
ERROR 错误
As soon as I start to drag the card I get 一旦我开始拖动卡片,我就会得到
"Can't add property _tracking, object is not extensible" “无法添加属性_tracking,对象不可扩展”
ADDITIONAL NOTES 补充说明
If I replace the interpolation assignment to bgColor
with the code below I do not get the error, but obviously lose out on the animating of the color. 如果我用下面的代码将插值赋值替换为bgColor
,我不会得到错误,但显然会失去颜色的动画效果。
const bgColor = s.bgColor._value === 0 ? colors.gray.one : colors.primary.light;
QUESTION 题
And ideas on why the error is being thrown and how to resolve it? 关于为什么会抛出错误以及如何解决错误的想法?
To use Animated, you need a special, "animatable" component (either Animated.View
, Animated.Text
or Animated.Image
, which are built in, or make a new one using Animated.createAnimatedComponent()
). 要使用Animated,您需要一个特殊的“可动画”组件( Animated.View
, Animated.Text
或Animated.Image
,它们是内置的,或者使用Animated.createAnimatedComponent()
创建一个新组件)。 Could that be your problem? 这可能是你的问题吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.