-
Notifications
You must be signed in to change notification settings - Fork 49
questions migrating from react-native-router #10
Comments
Hi @G3z! If I'm not mistaken: as you can see in |
thank you! and for the second part: do you have any idea on what is the best pattern to manage the navbar from in inside my components ? |
It can be interesting to handle these options in your 'parent' state, and then modify your navigation bar whenever this state changes imho. I'm not 100% about it, but I think it could be something like this: App extends Component {
state = {
title: 'Hello',
}
_onChangeTitle{
this.setState(() => ({ title: 'world!' }))
}
render() {
return (
<Navigation
navBarStyle={{ backgroundColor: 'purple' }}
titleStyle={{ color: 'white' }}
>
<Card
exact path="/home"
component={() => (
<NavBarModifier
onPress={() => this._onChangeTitle()}
/>
)}
title={this.state.title}
/>
</Navigation>
)
}
}
const NavBarModifier = (onPress) => (
<TouchableWithoutFeedback onPress={onPress}>
<View>
<Text>Change navbar title !</Text>
</View>
</TouchableWithoutFeedback>
) |
Hey @G3z, class App extends Component {
state = {
fooTitle: 'Foo',
barTitle: 'Bar',
}
setNavigationState = (key, value) => {
this.setState({
[key]: value,
})
}
render() {
return (
<Navigation>
<Card
path="/foo"
title={this.state.fooTitle}
render={(ownProps) => (
<Foo
{...ownProps}
setNavigationState={this.setNavigationState}
/>
)}
/>
<Card
path="/bar"
title={this.state.barTitle}
render={() => (
<Bar
{...ownProps}
setNavigationState={this.setNavigationState}
/>
)}
/>
</Navigation>
)
}
}
const Foo = (props) => (
<TouchableHighlight
onPress={() => props.setNavigationState('fooTitle', 'My new title')}
>
<Text>Change title</Text>
</TouchableHighlight>
)
const Bar = (props) => (
<TouchableHighlight
onPress={() => props.setNavigationState('barTitle', 'My new title')}
>
<Text>Change title</Text>
</TouchableHighlight>
) You just need to handle state ! 🚀 |
Thanks ! |
I found some limitations with this method, I'll fix it soon. |
@G3z Yes the documentation should be updated. PR's are welcomed ! |
I tried this apporach but it seems that the |
I'm quite busy currently by myself with lots of other stuff. I'll investigate this soon. |
This should be fixed in |
@LeoLeBras I'm following the pattern you laid out above, but it seems to have issues when you have multiple instances of a screen in the same stack. Example:
I have a minimal repo that shows the issue here: https://github.com/zachrnolan/react-router-navigation-demo This seems to be directly related to this issue, but let me know if you want me to create a new issue. Thanks! |
Hey @zachrnolan , |
@LeoLeBras Thanks for the reply! I'm happy to test the new version when it's ready. I have an app in production using Navigation Experimental and have been doing research on libraries to replace it. Your library is the best/easiest I've used so far, so I'm holding out for a v1 stable to start the replacement process. Consider me in for any QA/feedback you need. |
Great ! 😘 |
Hi @LeoLeBras! I'm also running into this issue now, was wondering if you've had a free moment to work on this bug at all? Thanks for the awesome library! 😄 |
I with react-router i had a routing component made like so
and i tried implementing RRN like so (is this correct ?)
in the first example the navbar is a plain view and so each component (
Dashboard
,Activity
,Detail
) has aNavBar
components and controls things like title, color, buttons with propsI was wandering how could I maintain the same level of control, if possible, i had before
The text was updated successfully, but these errors were encountered: