javascript - native react "attempt to set value to an immutable object"

标签 javascript android reactjs react-native react-animated

我正在创建一个可拖动的框。我可以将其拖动到屏幕上的任何位置,但我收到此错误,其中显示“您试图在一个不可变且已被卡住的对象上设置键 _value”。谁能告诉我我做错了什么。

我的代码:

import React, { Component } from 'react'
import {
  AppRegistry,
  StyleSheet,
  Text,
  Button,
  ScrollView,
  Dimensions,
  PanResponder,
  Animated,
  View
} from 'react-native'

import { StackNavigator } from 'react-navigation'




export default class Home extends Component{

componentWillMount(){

  this.animatedValue = new Animated.ValueXY();

this.panResponder = PanResponder.create({

 onStartShouldSetPanResponder: (evt, gestureState) => true,
  onMoveShouldSetPanResponder: (evt, gestureState) => true,
  onPanResponderGrant: (e, gestureState) => {



      },

  onPanResponderMove:Animated.event([


null,{dx: this.animatedValue.x , dy:this.animatedValue.y}

    ]),  
  onPanResponderRelease: (e, gestureState) => { 
      },       
})
}

  render(){

    const animatedStyle = {

      transform:this.animatedValue.getTranslateTransform()
    }

    return(

        <View style={styles.container}>

        <Animated.View style={[styles.box ,animatedStyle]} {...this.panResponder.panHandlers}>


        <Text>Home</Text>


        </Animated.View>
        </View>
      )
  }
}


var styles = StyleSheet.create({
  container: {
    flex: 1,
    marginLeft: 10,
    marginRight: 10,
    alignItems: 'stretch',
    justifyContent: 'center',
  },

  box:{

height:90,
width:90,
textAlign:'center'



  }
});

最佳答案

就我而言,我收到此错误是因为我忘记将 View 更改为 Animated.View

关于javascript - native react "attempt to set value to an immutable object",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44685328/

相关文章:

android - Android 中如何在按下 Enter 时触发按钮?

java - Android 计算百分比

javascript - 对如何获取 req.body 感到困惑

javascript - 如何使用 Redux 过滤数据但保持旧状态?

css - 在 React 的 CSS 模块中组合 CSS 类

javascript - 基于窗口宽度和高度应用 CSS3 转换

javascript - 带有 JQuery 事件的条码阅读器

javascript - 从源代码构建 WysiHat?

javascript - Appgyver 类固醇,Web View 中的更新对象不会显示

android - 我需要使用我们自己的图像而不是 Canvas 的 android 粒子动画