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

this.props.navigation.goBack() not working in DrawerNavigator #4474

Closed
theapache64 opened this issue Jun 11, 2018 · 9 comments
Closed

this.props.navigation.goBack() not working in DrawerNavigator #4474

theapache64 opened this issue Jun 11, 2018 · 9 comments

Comments

@theapache64
Copy link

Ok, let's make this straight. I am new in 'react-native'/'react-navigation'.

I've two screens, let's say A and B.It's wrapped under a DrawerNavigator. The screen A is the initialRoute, and when a button clicks from A, it navigates to B using this.props.navigation.navigate('B');, but when i try to goBack from B using this.props.navigation.goBack(). It doesn't work.

I've googled a lot, but couldn't find anything helpful. Why it's not working ? Am i missing something?

const HomeDrawerNavigator = createDrawerNavigator({
    A: A,
    B: B,
}, {
    initialRouteName : 'A'
});
@brentvatne
Copy link
Member

@ericvicenti - any idea what the justification is for isBackEligible?

const isBackEligible =
action.key == null || action.key === activeChildLastState.key;

@ericvicenti
Copy link
Contributor

If the action.key is specified, we should only let the matching router handle it. It sounds like the action key is incorrectly specified? If you want the deepest active router to handle the back action, it should have key set to null or undefined.

@yoler
Copy link

yoler commented Jun 14, 2018

Same question

and in contentComponent I can not get closeDrawer, is undefined

@brentvatne
Copy link
Member

@yoler - that is not at all the same question. that is fixed in 2.3.1

@xanderberkein
Copy link

Having the same problem here.

I made this snack based on the example in the docs

https://snack.expo.io/@x11n/drawernavigator-goback

@brentvatne
Copy link
Member

fixed in 2.4.1

@poptocrack
Copy link

Thanks for your work! My solution is related to react-navigation/react-navigation-drawer#4

@xanderberkein
Copy link

xanderberkein commented Jun 21, 2018

@brentvatne This doesn't seem to be completely fixed in 2.4.1. See my updated snack (https://snack.expo.io/@x11n/drawernavigator-goback).

When you go to "Another Screen", then browse to "Notifications" and press goBack, you get sent back to the HomeScreen, while you would expect to jump to the previous screen, "Another Screen", again.

Edit: This is because the goBack() listens to the backBehavior config prop. Is this intended behaviour?
If you set backBehavior: 'none', goBack doesn't work anymore, but the only other option backBehavior: 'initialRoute' makes it so goBack always points to the initial Route, no matter the current position in the Drawer

@brentvatne
Copy link
Member

those are the only two back behaviors available - none or initialRoute. this has always been the case. if you'd like to add more you can implement this rfc! react-navigation/rfcs#2

@react-navigation react-navigation locked and limited conversation to collaborators Jun 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants