Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 837
Mithun Raman Avatar asked Apr 13 '20 13:04

Mithun Raman


People also ask

How do I run debug mode in react native?

For Android: Ctrl + M (emulator) or Shake the phone (In Device) to reveal menu. Make sure you have chrome. On the revealed menu select Debug JS Remotely Option. Chrome will be opened automatically at localhost:8081/debugger-ui.

How do I enable remote debugging in react native?

In App Developer MenuOn Android emulator, you need to press command + M. Debug JS Remotely − Used for activating debugging inside browser developer console. Enable Live Reload − Used for enabling live reloading whenever your code is saved. The debugger will open at localhost:8081/debugger-ui.

How do I turn off debug mode in react native?

You are using on MS : ctrl + m , MAC OS : cmd + m , iPhone/android: shake your device then look for the "disable Remote Debug JS" and click it. Save this answer.


2 Answers

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.

like image 87
fadly kayo Avatar answered Oct 13 '22 07:10

fadly kayo


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

like image 20
S Shikhar Avatar answered Oct 13 '22 07:10

S Shikhar