简体   繁体   English

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

[英]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.ViewAnimated.TextAnimated.Image ,它们是内置的,或者使用Animated.createAnimatedComponent()创建一个新组件)。 Could that be your problem? 这可能是你的问题吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的TypeError:无法添加属性12,对象不可扩展 - Uncaught TypeError: Can't add property 12, object is not extensible React Error(TypeError):无法添加属性上下文,对象不可扩展 - React Error (TypeError): Can't add property context, object is not extensible 无法在react中分配新属性,得到了“无法添加属性xxx,对象不可扩展” - Can not assign new property in react , got ` Can't add property xxx, object is not extensible` Node.js React:无法添加属性上下文,对象不可扩展 - Node.js React: Can't add property context, object is not extensible 无法添加属性 2,对象不可扩展 Array.push - Can not add property 2, object is not extensible Array.push 如何在React-VR中使用Animated with Shape原语(例如Box)? 错误:“无法添加_tracking属性,对象不可扩展” - How to use Animated with Shape primitives such as Box in React-VR? Error: “Cannot add property _tracking, object is not extensible” 未捕获的类型错误:无法定义属性“x”:对象不可扩展 - Uncaught TypeError: can't define property "x": Object is not extensible 类型错误:无法定义属性“当前”:Object 不可扩展 - TypeError: can't define property “current”: Object is not extensible React:无法添加属性“X”,对象不可扩展 - React : cannot add property 'X', object is not extensible 无法添加属性“X”,对象不可扩展 angular 9 - Cannot add property "X", object is not extensible angular 9
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM