closeOnHardwareBackPress not working (Android back button keeps closing alert)
See original GitHub issueI’m on a Samsung Galaxy S6 with Android 7.
<AwesomeAlert
show={!assistanceConfirmed}
showProgress
title="Esperando confirmación de asistencia"
closeOnHardwareBackPress={false}
closeOnTouchOutside={false}
overlayStyle={styles.overlay}
/>
Am I missing something?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Preventing hardware back button android for React Native
So I added code, but this does not work. Are there any solutions for this? The alert pop up is seen but "return...
Read more >Handling Android Back Button Press in React Native
How to handle Android back button press in React Native using React Navigation. We will use useFocusEffect for handling Android back button.
Read more >Android Back Button handling in React Native apps — 1x08
Method removeAndroidBackButtonHandler removes the previously added event listener in order to secure that we will not keep adding event listeners when we ...
Read more >Android Back Button causes crashing/closing - sometimes
Pressing the Back key will close/crash my app about 50% of the time. I ... (I was able to reduce the problem by...
Read more >Handling Android Back Button Press in React Native
In this tutorial we are going to discuss how to make the App Quit When Hardware Back Button is pressed in React Native...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The core issue has been fixed with new update, but the back button doesn’t allow me to use the previous/custom BackHandlers that I initially defined. After looking at your code and the documentation for BackHandlers I realized that your BackHandler returns true even if it’s not handling the springHide, which causes other listeners to break.
According to the docs https://facebook.github.io/react-native/docs/backhandler. The listeners are registered and called in reverse order and it stops when the first function returns true. This means you still have a listener active and returning true before it hits listeners that are defined before AwesomeAlert’s.
You could just change
to
I think you designed it like this so that it doesn’t exit the app when the Alert is the only registered hardware back event listener. I see another solution being wrapping the event listener in a closeHardwareBackPress condition
if(this.props.closeOnHardwareBackPress) HwBackHandler.addEventListener(HW_BACK_EVENT, this._handleHwBackEvent);
.I hope this helps 👍
Thanks for the awesome library @rishabhbhatia
Ok @jjercx , I’ll fix it tomorrow