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.
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With