Skip to content
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

App closes when pressing hardware back button #2323

Closed
pvroosendaal opened this issue Sep 1, 2017 · 6 comments
Closed

App closes when pressing hardware back button #2323

pvroosendaal opened this issue Sep 1, 2017 · 6 comments

Comments

@pvroosendaal
Copy link

Version

"react-native-router-flux": "^4.0.0-beta.20",
"react-native": "0.44.0",

Expected behaviour

App doesn't close, but only goes back in navigation stack

Actual behaviour

App closes, but when I reopen it, it has gone back a step in navigation stack

Any help is welcome, thanks!

@pvroosendaal
Copy link
Author

Fixed it by overriding 'hardwareBackPress':

componentDidMount() {
	BackAndroid.addEventListener('hardwareBackPress', this.handleBackButton)
}

componentWillUnmount() {
	BackAndroid.removeEventListener('hardwareBackPress', this.handleBackButton)
}

handleBackButton() {
	return true
}

@Salman18
Copy link

Salman18 commented Feb 2, 2018

Where we have to override this.

In code ?

Any Dependencies need to be installed

@Blapi
Copy link
Collaborator

Blapi commented Feb 2, 2018

It's from react-native, not react-native-router-flux, check the doc : https://facebook.github.io/react-native/docs/backhandler.html

And of course, this is only for Android.

@Salman18
Copy link

Salman18 commented Feb 2, 2018

yeah. I am using android only.

But I am using react-native router flux for navigation.

my application gets closed if I press back button on Android.

any Suggestions?

@Blapi
Copy link
Collaborator

Blapi commented Feb 2, 2018

If you read the doc carefully, you'll see this foe the Router component :

Property Type Default Description
children   required Scene root element
wrapBy Function   function to wrap each Scene component and nav bar buttons - allows easy MobX integration (by passing observer)
sceneStyle Style   Style applied to all scenes (optional)
backAndroidHandler Function   Allows custom control of hardwareBackPress in Android (optional). For more info check BackHandler.
uriPrefix string   A uri prefix to strip from incoming urls for deep linking. For example, if you wanted to support deep linking from www.example.com/user/1234/, then you could pass example.com to only match paths against /user/1234/

Use the backAndroidHandler property, there's already a lot of examples of how to do it on GitHub and SO

@Salman18
Copy link

Salman18 commented Feb 2, 2018

okay thanks
will look on this,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants