简体   繁体   English

Android TouchableOpacity 间歇性“错误”

[英]Android TouchableOpacity Intermittent "error"

I'm having an intermittent problem with the TouchableOpacity component in react-native.我在 react-native 中的 TouchableOpacity 组件出现间歇性问题。

I basically click on the element, it performs the opacity animation normally, but my console.log runs randomly.我基本上点击元素,它正常执行不透明度 animation,但我的 console.log 随机运行。 In iOS works correctly.在 iOS 中工作正常。

My code:我的代码:

<TouchableOpacity style={{backgroundColor:'red'}} onPress={async () => {
  console.log('Button '+item.tag+' pressed.');
}}>

NOTE: I've tried calling this function without async.注意:我试过在没有异步的情况下调用这个 function。

I found the solution!我找到了解决方案!

PanResponder was detecting micro movements on simple touch. PanResponder 通过简单的触摸检测微动。 In the onMoveShouldSetPanResponder parameter I defined the following function:onMoveShouldSetPanResponder参数中,我定义了以下 function:

    panResponder = PanResponder.create({
        onMoveShouldSetPanResponder: (e, g) => {
            return Math.abs(g.dx) > 2 || Math.abs(g.dy) > 2;
        },
        ...
    });

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM