react-router-navigation icon indicating copy to clipboard operation
react-router-navigation copied to clipboard

Allow to force left navbar button rendering

Open TheMightyPenguin opened this issue 7 years ago • 2 comments

Context

Is there any way to force left button to appear? My use case is something like the following

I have a set of Routes

// App.js
<NativeRouter>
  <Switch>
    <Route path="/app/wizard component={Wizard} />
    <Route exact path="/app" component={MainNavigation} />
  </Switch>
</NativeRouter>

And then inside my Wizard component file

// Wizard.js
import { HeaderBackButton } from 'react-navigation';

class Wizard extends React.Component<Props, State> {
  renderLeftButton = () => <HeaderBackButton onPress={this.props.history.goBack} />;

  render() {
    const { history } = this.props;
    return (
      <Navigation renderLeftButton={this.renderLeftButton}>
        <Card exact path="/app/wizard" component={Step1} />
        <Card path="/app/wizard/step-2" component={Step2} />
      </Navigation>
    );
  }
}

Notice that in my Wizard component, I have to pass a custom renderLeftButton function, and this is ok, but I was wondering if it's possible to force the rendering of the back button whitout doing something like this? I checked the code and I found this line, but the scene.index === 0 does not work for all use cases I think?

  1. Also, whats the default onPress behaviour of the backButton? I'm guessing it is something like history.goBack

TheMightyPenguin avatar Sep 06 '17 01:09 TheMightyPenguin

Hey @TheMightyPenguin ,

  1. Nop, it's not possible with the current rc.3 ☹️. You need to pass renderLeftButton to force the rendering of the back button. The condition scene.index === 0 can be replaced by the canGo func. I will investigate this for next release.

  2. Yes, the default onPress behavior is history.goBack: https://github.com/LeoLeBras/react-router-navigation/blob/5db602b7e62a713592fe7a6957b2fdd8d719984a/modules/CardStack.js#L205

LeoLeBras avatar Sep 06 '17 08:09 LeoLeBras

Alright, thanks a lot for answering @LeoLeBras 😄 This library is amazing btw, I'll be checking the code as I'll really like to contribute!

TheMightyPenguin avatar Sep 06 '17 13:09 TheMightyPenguin