rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

API for overriding back button handling

Open brentvatne opened this issue 7 years ago • 4 comments

  • Should let you inject a back handler that runs before the current screen
  • Need to only run this handler when the screen is active maybe?
  • Need to be able to disable the back button for any given screen

brentvatne avatar Jan 26 '18 23:01 brentvatne

Is the intention here just to override handling for the Android back button, or to also override handling the up button in a stack navigator on both platforms?

mmarvick avatar Feb 17 '18 19:02 mmarvick

Should let you inject a back handler that runs before the current screen

What do you mean by injecting a back handler before the current screen? Do you mean before the current screen's back handler is attached? Won't that make it the previous one to be never called since the screen's handler will override that?

Need to be able to disable the back button for any given screen

Do you mean preventing navigating away from the screen or it's only about the hardware back button? I think ability to prevent navigating away is useful, but not sure about only disabling the hardware back button. Though could do that by returning this.props.navigation.isFocused() from a back handler if such a method existed :)

satya164 avatar Feb 17 '18 19:02 satya164

@mmarvick - that's a good point, we probably want a generic way to handle any kind of back action and override.

@satya164 - isFocused() would be great! let's do that :)

brentvatne avatar Feb 17 '18 21:02 brentvatne

Some related issues:

https://github.com/react-navigation/react-navigation/issues/779 https://github.com/react-navigation/react-navigation/issues/1743 https://github.com/react-navigation/react-navigation/issues/207

In addition to the header back button and the Android hardware back button, goBacks can also be triggered programatically. Any generic solution may want to get callbacks for those as well. I'm not sure how useful that'd be though ¯\_(ツ)_/¯

For what it's worth, being able to use the exported HeaderBackButton as the headerLeft satisfies my main use case for a callback -- a callback would still be a nicer API, but it seems less urgent. It took a bit of digging to find that information though. It might be nice to note with the headerLeft documentation.

mmarvick avatar May 30 '18 06:05 mmarvick