-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android Hardware Back Button not Working #1603
Comments
What is your RN version? We need a little more info for help you |
same problem, my RN version is 0.44.0 |
Any workaround.? I've been struggling to handle android hardware back button. |
@Suresh-R-S Have you read this https://facebook.github.io/react-native/docs/backandroid.html? Maybe this is your problem |
@rigobcastro Yes i'am using backHandler, since backAndroid is deprecated from RN 0.44.0. |
@Suresh-R-S ok this is another problem, |
This is working in the most recent release! 😄 |
@spencercarli which version ?? |
What other packages are you using? In my case there was some weird conflict with react-native-video using react-windows. When I upgraded my react-native-video, BackHandler worked fine. |
@samdoj in dev mode work but on release mode back not working |
how to determine the hardware buttons in android devices are present or not in react native as there seem to be a lot of issues in styling various android devices please anyone could help me out in resolving that isuue |
I am on v0.46.0 of react-native and had the same issue. I tracked the issue down to this file in the react-native code base When running with the chrome debugger turned off the line
always returns an empty array for After more investigation, I think the issue was discovered and discussed in the following PR facebook/react-native#15182. Even after copy/pasting the PR change in an older version of RN it did not work most likely caused by the issue described in the PR. After some very slight modifications I got it working by changing to RCTDeviceEventEmitter.addListener(DEVICE_BACK_EVENT, function() {
var invokeDefault = true;
var subscriptions = []
_backPressSubscriptions.forEach(sub => subscriptions.push(sub))
for (var i = 0; i < subscriptions.reverse().length; ++i) {
if (subscriptions[i]()) {
invokeDefault = false;
break;
}
}
if (invokeDefault) {
BackHandler.exitApp();
}
}); Simply using a So you could fork react-native and use a modified version, submit a PR though I imagine that will take a little while to be approved and merged upstream, or you can do something similar to what I did which was to override the // other imports
import { BackHandler, DeviceEventEmitter } from 'react-native'
class MyApp extends Component {
constructor(props) {
super(props)
this.backPressSubscriptions = new Set()
}
componentDidMount = () => {
DeviceEventEmitter.removeAllListeners('hardwareBackPress')
DeviceEventEmitter.addListener('hardwareBackPress', () => {
let invokeDefault = true
const subscriptions = []
this.backPressSubscriptions.forEach(sub => subscriptions.push(sub))
for (let i = 0; i < subscriptions.reverse().length; i += 1) {
if (subscriptions[i]()) {
invokeDefault = false
break
}
}
if (invokeDefault) {
BackHandler.exitApp()
}
})
this.backPressSubscriptions.add(this.handleHardwareBack)
}
componentWillUnmount = () => {
DeviceEventEmitter.removeAllListeners('hardwareBackPress')
this.backPressSubscriptions.clear()
}
handleHardwareBack = () => { /* do your thing */ }
render() { return <YourApp /> }
} |
@austenLacy I use this code ,still not work. 😂 |
@haozes if you post the code that you have, I can try to help if you'd like |
@austenLacy I use this code, but it's still not working.
Here's some peace of my code in one js file:
I will be very happy if someone could help me with this BackButton on Android. I use |
@Pepincho is your |
@Pepincho I dont know whether this is actually a problem or not but when i comment firebase backhandler working for me. |
@Pepincho Hello, im having the same problem with back button. My problem is when i press the Device Back Button it Forces the app to close. I tried to create a new project and test each and every plugin i installed. Device Back Button seems to be working fine to every plugin except when i |
@maidanhcongtu DUUUUUUUUUUUUDE!!!!!!! You saved me. It worked now. I had to downgrade firebase to |
can someone here investigate what changed between firebase 4.13.1 and 5.0.4 that may somehow cause this? there must be some weird side effect of importing the lib that is causing this issue |
Just information that when I try firebase version 5.0.3 it's also working for me |
Downgraded Firebase from 5.0.4 to 5.0.3, works for me. Didn't expect an UI problem was related to Firebase, cost me 2 days... |
I have no idea what firebase is doing here :\ If someone who uses firebase and react-navigation could dig in and let me know what you find, it would be much appreciated |
@maidanhcongtu thnx a lot you saved me... |
Wow, I had also issues. Thank's @maidanhcongtu |
@austenLacy I spent 3 days and so I did not this, You save my nerves. Thanks |
oh my god, I tried so many things. I thought it was expo, I thought maybe it was my phone, maybe it was the way I was doing my routing in React Navigation. I created hello world solutions trying to isolate exactly why this was happening. And of all things, it was firebase... |
Guyz please do understand it might not only be the problem with react native. Be careful while integrating it with firebase. |
This is confounding. I can also repro with react-navigation + latest Firebase (5.5.2 as of writing). If I downgrade to [email protected] I see the react-navigation handler firing and everything runs as expected. And if I bump it up to [email protected] it fails. There isn't anything obviously intrusive about firebase's code. The release notes don't raise any red flags. And here is the diff between 5.0.3 and 5.0.4. Nothing jumps off the page there either... |
Firebase 5.5.5 still has the issue |
let them know on their issues @Dric0 |
Great work on this package. Pressing the back button in the nav header works, but if I press the back button on the device, nothing happens.
I looked in the source and found 'backPress' handled from BackAndroid: https://github.com/react-community/react-navigation/blob/master/src/createNavigationContainer.js#L157
There are two problems here. First, the
hardwareBackPress
needs to be handled and it should return true/false to prevent the app from exiting if indeed the user can navigate backwards.For now I've written this functionality into my app but since some work has been put in to handle Android, I would expect it to work for the phone's physical back button. I'd be happy to submit a PR if it will be taken seriously.
Thanks for your work and let me know if I can help.
The text was updated successfully, but these errors were encountered: