【问题标题】:React Native <TouchableOpacity> callback not called on Android when debug mode is on调试模式打开时,未在 Android 上调用 React Native <TouchableOpacity> 回调
【发布时间】:2020-10-12 16:25:57
【问题描述】:

我的 React Native 应用程序中有 &lt;TouchableOpacity&gt; 组件,它们都有关联的回调。如果我没有将设备设置为debug,这些在 iOS 上运行良好,在 Android 上运行良好。但是当我确实将其设置为调试时,元素在单击时确实会改变不透明度,但不会调用回调。

有人知道我该如何处理吗?

备注

  • 当我使用React Native Debugger 时会出现这种情况,并且当我只使用在开发人员选项中单击debug 时出现在Chrome 中的默认调试器时。
  • 模拟器不会出现此问题。我正在测试的 Galaxy A30 正在发生这种情况。
  • 我正在使用react-native@0.62.0

【问题讨论】:

  • 如果您在 TouchableOpacity 中使用,请移除 position:'absolute' 样式
  • @vignesh 我确实在其他地方读过,它们中的任何一个都没有绝对定位。
  • 像这样尝试 zIndex:11111

标签: reactjs react-native touchableopacity react-native-debugger


【解决方案1】:

我可以确认这个错误存在,你甚至可以用这个非常简单的例子来重现它:

import React from "react";
import { TouchableOpacity, View, Text } from "react-native";

class App extends React.Component {
  render() {
    console.log("Logged in debugger.");
    return <TouchableOpacity 
      onPress={() => console.log("No log in debugger.")}>
        <View style={{height: 200, width: 200, backgroundColor: 'blue'}}>
          <Text>Test</Text>
        </View>
    </TouchableOpacity>;
  }
}

export default App;

这是我的配置:

  • 反应原生0.62.2
  • 反应原生 cli 4.10.1
  • 反应 16.13.1
  • 在装有 Android 10 的 OnePlus 6T 上运行

github 上找到可能的解决方案。问题似乎与调试器主机时间和您的设备时间之间的不同步有关。它至少对我有用(禁用自动时间同步并启用它)但对同事不起作用(他的手机是 P40 lite)。

【讨论】:

    猜你喜欢
    • 2022-01-21
    • 2021-09-12
    • 2023-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-31
    • 1970-01-01
    • 2019-03-07
    相关资源
    最近更新 更多