Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

Allow to force left navbar button rendering #38

Open
TheMightyPenguin opened this issue Sep 6, 2017 · 2 comments
Open

Allow to force left navbar button rendering #38

TheMightyPenguin opened this issue Sep 6, 2017 · 2 comments
Assignees

Comments

@TheMightyPenguin
Copy link

TheMightyPenguin commented Sep 6, 2017

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
@LeoLeBras
Copy link
Member

LeoLeBras commented Sep 6, 2017

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 LeoLeBras added this to the 1.0.0-stable milestone Sep 6, 2017
@LeoLeBras LeoLeBras self-assigned this Sep 6, 2017
@TheMightyPenguin
Copy link
Author

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!

@LeoLeBras LeoLeBras removed this from the v1.0.0-stable milestone Dec 9, 2017
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

2 participants