【问题标题】:Android TouchableOpacity Intermittent "error"Android TouchableOpacity 间歇性“错误”
【发布时间】:2021-06-09 17:08:24
【问题描述】:

我在 react-native 中遇到了 TouchableOpacity 组件的间歇性问题。

我基本上点击元素,它正常执行不透明动画,但我的 console.log 随机运行。在 iOS 中可以正常工作。

我的代码:

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

注意:我尝试在不使用异步的情况下调用此函数。

【问题讨论】:

  • 我注意到 PanResponder 正在干扰 TouchableOpacity 的功能,但我仍然不知道如何解决。

标签: android react-native react-native-flatlist touchableopacity


【解决方案1】:

我找到了解决办法!

PanResponder 正在检测简单触摸时的微动。在onMoveShouldSetPanResponder 参数中,我定义了以下函数:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-20
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 2012-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多