I want to exit my application when I pressed hardware back button, I was implemented BackHandler from react-native module, and I implement that in a modal. The event handler is worked only close active modal. How I can set to exit application when the event tirgerred?
componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
}
componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress);
}
handleBackPress() {
Alert.alert('Exit', 'Are you sure?', [
{
text: 'No',
style: 'cancel'
},
{
text: 'Yes',
onPress: () => BackHandler.exitApp()
}
], {
cancelable: false
});
return true;
}
Hi,
Have you solved this ?
Not yet @HRCJ7
Try this, to exit the app on exception.
onHardwareBackPress = async () => {
try {
const { componentId } = this.props;
await Navigation.pop(componentId);
return true;
} catch (e) {
BackHandler.exitApp();
return false;
}
};
had the same issue with LightBox
I change onBackhPressed() method.
@Override public void onBackPressed() {
if (cancelable) {
// hide();
}
}
in your case you should do the same for Modal class.
@Override
public void onBackPressed() {
if (!layout.onBackPressed()) {
// super.onBackPressed();
}
}
Any updates on how to override the back handling in a component?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.
The issue has been closed for inactivity.
any update on this?
any update ?
Most helpful comment
Any updates on how to override the back handling in a component?