Onpress handler for drawer items
PR already exists but probably needs to be rebased at this point: https://github.com/react-navigation/react-navigation/pull/10060
Currently there is no way to pass an
Drawer.Screen. There are many reasons why someone would want to do this, and I've found several people looking for this functionality on stackoverflow. For me personally, some of my
Stack.Navigators, and I want to be able to reset the stack when the drawer item is pressed.
I am aware of the ability to pass your drawer navigator a custom
drawerContentwhere you can then pass it
onPresshandlers, and I am already doing that for some things like my logout button. Trying to use that for screens seems pretty cumbersome though, since it seems like then you have to implement all of the navigation and focused logic as well as drawer open/close state. Additionally, you can only place them before or after all of your regular
Drawer.Screens that are rendered via
I solved this by adding an optional
onPressthat gets passed the normal
onPresshandler. That way the user can do what they want, and call the default
onPressbefore or after (or not at all?)
My best guess as for why this functionality does not currently exist is that it can allow the user to do things that conflict with what react-navigation is doing internally when you tap on a drawer item, which could lead to bugs. If this is the case, maybe it could be called
dangerousOnPress? That said, I have been using this without any issues.
marked this post as