react-router-navigation
react-router-navigation copied to clipboard
Allow to force left navbar button rendering
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?
- Also, whats the default onPress behaviour of the backButton? I'm guessing it is something like
history.goBack
Hey @TheMightyPenguin ,
-
Nop, it's not possible with the current
rc.3
☹️. You need to passrenderLeftButton
to force the rendering of the back button. The conditionscene.index === 0
can be replaced by thecanGo
func. I will investigate this for next release. -
Yes, the default
onPress
behavior ishistory.goBack
: https://github.com/LeoLeBras/react-router-navigation/blob/5db602b7e62a713592fe7a6957b2fdd8d719984a/modules/CardStack.js#L205
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!