gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 13:54:31 25 4
gpt4 key购买 nike

我正在创建一个可拖动的框。我可以将其拖动到屏幕上的任何位置,但我收到此错误,其中显示“您试图在一个不可变且已被卡住的对象上设置键 _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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com