首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法添加属性_tracking,对象不可扩展

无法添加属性_tracking,对象不可扩展
EN

Stack Overflow用户
提问于 2016-05-03 22:05:44
回答 1查看 13.8K关注 0票数 30

用例

我有一个卡片列表,并试图创建一个刷左/右火绒风格的功能。我已经开始使用panResponder,但是我遇到了动画backgroundColor的问题。

设置

代码语言:javascript
复制
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的内插分配,我不会得到错误,但显然会失去颜色的动画效果。

代码语言:javascript
复制
const bgColor = s.bgColor._value === 0 ? colors.gray.one : colors.primary.light;

问题

关于为什么会抛出错误以及如何解决它的想法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-04 02:04:02

要使用动画,您需要一个特殊的“可动画”组件( Animated.ViewAnimated.TextAnimated.Image,它们是内置的,或者使用Animated.createAnimatedComponent()制作一个新的组件)。这会是你的问题吗?

票数 79
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37015189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档