React native buttons OnPress does not fire when app running in debug mode
Asked Answered
O

6

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.

Opah answered 13/4, 2020 at 13:48 Comment(4)
share your codeGatefold
Added code snippetOpah
@MithunRaman are you using flipper? I am getting the same thing on Android and iOS since upgrading to 0.62.2 and using flipperLedoux
I am using RN debugger. It looks like many are already facing this issue. I have temporarily fixed this by following the comment here: github.com/facebook/react-native/issues/…Opah
E
12

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.

Esquimau answered 24/7, 2020 at 9:22 Comment(1)
same issues in iOSFriede
U
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

Urethra answered 25/6, 2020 at 11:23 Comment(0)
S
1

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

Sympathy answered 29/9, 2020 at 7:9 Comment(0)
S
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.

Sublett answered 10/1, 2021 at 15:15 Comment(0)
H
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...

Herlindaherm answered 3/2, 2021 at 10:28 Comment(0)
S
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%
Sontag answered 17/8, 2022 at 14:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.