Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 无法理解如何更新和访问ValueXY对象和PanResponder对象的值_React Native_Expo - Fatal编程技术网

React native 无法理解如何更新和访问ValueXY对象和PanResponder对象的值

React native 无法理解如何更新和访问ValueXY对象和PanResponder对象的值,react-native,expo,React Native,Expo,我希望最终创建一个元素,我可以用我的手指四处移动,根据它是否已被移动,并在释放手势时返回其起始位置,以不同的方式渲染。 以下是我的ValueXY和Pan响应程序的代码: this.pan = new Animated.ValueXY(); this.panResponder = PanResponder.create({ onMoveShouldSetPanResponder: () => true, onPanResponderGrant:

我希望最终创建一个元素,我可以用我的手指四处移动,根据它是否已被移动,并在释放手势时返回其起始位置,以不同的方式渲染。 以下是我的ValueXY和Pan响应程序的代码:

    this.pan = new Animated.ValueXY();
    this.panResponder = PanResponder.create({
        onMoveShouldSetPanResponder: () => true,
        onPanResponderGrant: () => {
            this.pan.setValue({
              x: this.pan.x._value,
              y: this.pan.y._value
            });
          },
        onPanResponderMove: Animated.event([
        null,
        { dx: this.pan.x, dy: this.pan.y }
        ]),
        onPanResponderRelease: () => {
        this.pan.setValue({
            x : 0,
            y : 0
        });
        }
下面是我要为元素渲染的内容:

          <Animated.View style={[{
            transform: [{ translateX: this.pan.x }, { translateY: this.pan.y }]
          },styles.ProfileMain]}
          {...this.panResponder.panHandlers}>
            {
            this.pan.x._value == 0 && this.pan.y._value == 0 ?  
            <View><Text>first thing</Text></View>
            :
            <View><Text>Second thing</Text></View>
            }
        </Animated.View> 

{
this.pan.x._值==0和this.pan.y._值==0?
第一件事
:
第二件事
}
我希望我可以简单地检查ValueXY的x和y,如果其中一个从0移动,则以不同的方式渲染。但这似乎不起作用。第一次渲染始终发生。当我打印出这些值时,只有执行过的打印显示x和y为0。我不认为我这样做是正确的,但老实说,文档是有点稀疏。比如,当我打印出值XY时,偏移量的概念有什么意义?它只是一个对象,其中包含x的值和y的值。它甚至在哪里存储偏移量以备将来使用?文档甚至没有我可以引用的字段列表\n

我的建议是否可行和有效?我可以有条件地在置换时渲染吗?我是在用螺丝刀钉钉子吗