当应用程序在调试模式下运行时,本机按钮 OnPress 不会触发

Mit*_*man 13 reactjs react-native react-native-debugger

我遇到了一个奇怪的问题。当我在调试模式下运行我的应用程序时,我的按钮中的 onPress 处理程序不会触发。当我停止在调试模式下运行应用程序时,按钮按预期工作。

调试在我的模拟器上工作,但在真实设备上失败。

细节:

OS: Mac
react: "16.11.0"
react-native: "0.62.2"
Run Code Online (Sandbox Code Playgroud)

代码

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow strict-local
 */

import React from 'react';
import {
  Button,
  SafeAreaView,
  StyleSheet,
  ScrollView,
  View,
  Text,
  StatusBar,
} from 'react-native';

import {
  Header,
  LearnMoreLinks,
  Colors,
  DebugInstructions,
  ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';

const App = () => {
  return (
    <>
      <StatusBar barStyle="dark-content" />
      <SafeAreaView>
        <ScrollView
          contentInsetAdjustmentBehavior="automatic"
          style={styles.scrollView}>
          <Header />
          {global.HermesInternal == null ? null : (
            <View style={styles.engine}>
              <Text style={styles.footer}>Engine: Hermes</Text>
            </View>
          )}
          <View style={styles.body}>
            <Button
              onPress={() => alert('Does not fire in debug mode')}
              title="Learn More"
              color="#841584"
              accessibilityLabel="Learn more about this purple button"
            />
            <View style={styles.sectionContainer}>
              <Text style={styles.sectionTitle}>Step One</Text>
              <Text style={styles.sectionDescription}>
                Edit <Text style={styles.highlight}>App.js</Text> to change this
                screen and then come back to see your edits.
              </Text>
            </View>
            <View style={styles.sectionContainer}>
              <Text style={styles.sectionTitle}>See Your Changes</Text>
              <Text style={styles.sectionDescription}>
                <ReloadInstructions />
              </Text>
            </View>
            <View style={styles.sectionContainer}>
              <Text style={styles.sectionTitle}>Debug</Text>
              <Text style={styles.sectionDescription}>
                <DebugInstructions />
              </Text>
            </View>
            <View style={styles.sectionContainer}>
              <Text style={styles.sectionTitle}>Learn More</Text>
              <Text style={styles.sectionDescription}>
                Read the docs to discover what to do next:
              </Text>
            </View>
            <LearnMoreLinks />
          </View>
        </ScrollView>
      </SafeAreaView>
    </>
  );
};

const styles = StyleSheet.create({
  scrollView: {
    backgroundColor: Colors.lighter,
  },
  engine: {
    position: 'absolute',
    right: 0,
  },
  body: {
    backgroundColor: Colors.white,
  },
  sectionContainer: {
    marginTop: 32,
    paddingHorizontal: 24,
  },
  sectionTitle: {
    fontSize: 24,
    fontWeight: '600',
    color: Colors.black,
  },
  sectionDescription: {
    marginTop: 8,
    fontSize: 18,
    fontWeight: '400',
    color: Colors.dark,
  },
  highlight: {
    fontWeight: '700',
  },
  footer: {
    color: Colors.dark,
    fontSize: 12,
    fontWeight: '600',
    padding: 4,
    paddingRight: 12,
    textAlign: 'right',
  },
});

export default App;

Run Code Online (Sandbox Code Playgroud)

还有其他人遇到同样的问题吗?

谢谢,

更新:我尝试创建一个新项目,添加一个简单的按钮,然后尝试调试。该问题是可重现的。

fad*_*ayo 7

确保有是运行此命令的主机和设备之间不存在时间差:adb shell "date" && date

要修复它,请转到设置(设备)-> 日期和时间,禁用自动时间设置,然后重新启用它。


小智 2

它也发生在我身上,所以要在调试时解决真实设备中的问题,只需转到真实设备设置 => 时间和数据 => 并关闭(切换)自动日期和时间(使用网络提供的时间)并离开将其添加到手册中,然后重新启动应用程序,并在 Windows 中按 CTRL + D 进行调试工作,它将像在模拟器中一样工作注意=>它可以在模拟器上工作,因为它需要来自我们系统的数据和时间。希望有帮助