15

I have hit a strange issue. The onPress handler in my button does not fire when I run my app in debug mode. When I stop running the app in debug mode, the buttons work as expected.

Debugging works on my emulator, but fails on a real device.

Details:

OS: Mac
react: "16.11.0"
react-native: "0.62.2"

Code

/**
 * 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;

Anyone else run into the same issue?

Thanks,

Update: I tried creating a new project, added a simple button and then tried debugging. The issue is reproducible.

Mithun Raman
  • 309
  • 4
  • 13

6 Answers6

11

Make sure there is no time difference between the host and device by running this command: adb shell "date" && date.

To fix it go to the Settings (device) -> Date & Time, disable automatic time setting, and then re-enabling it.

fadly kayo
  • 650
  • 7
  • 14
2

it also happens with me so to fix the issue in real device while debugging just go to your real-device setting => time & Data => and turn off(toggle) Automatic date & time (which uses network-provided time) and leave it to the manual and then restart the app and in windows press CTRL + D for debug work and it will work like in emulator NOTE => it works on emulator because it takes data and time from our system . it hope it helps

S Shikhar
  • 21
  • 4
1

time on device and your PC not synchronized go to PC and device time settings and re-enable automatic time setting

haiflive
  • 1,411
  • 13
  • 13
1

@fadly's steps did work for me but not AS IS, so listing down

  1. Check the Date/Time difference between the host and device by running this command:

adb shell "date" && date.

  1. To fix it go to the Settings (device) -> Date & Time, disable automatic time setting, and then re-enabling it.

  2. Try adb shell "date" && date. There should be no time difference.

Note: If still there is a difference, then the date/time is not getting synched. Try Resetting wifi/mobile data. Repeat the above steps again. It should work.

Amit
  • 2,389
  • 22
  • 29
1

For me this: adb shell "date" && date. this resulted in times where the device clock was ~1sec ahead. Disabling/enabling time synchronization did not work. So I disabled the synchronization on the device and then opened the dialog to edit the time and just saved it. This made my device a few seconds behind. That solved my issue.


Edit: the fix broke timers, i.e. setInterval doesn't get callbacks...

Well, I guess I need onPress more than I need setInterval...

Paulius Liekis
  • 1,676
  • 3
  • 18
  • 26
1

In my case:

your OS time should be after your phone time. The minute should be identical but OS second should be after your phone time.

on Windows run this:

adb shell "date" && echo %TIME%
AliTN
  • 96
  • 5