Tell us which versions you are using:
I try to change the title of tabbar using props/state when click my button, but nothing happened. What should I do?
Try calling Actions.refresh() after you set new title
I'm using the following code to set a dynamic title of my navbar:
ComponentOne.js
<TouchableNativeFeedback
background={TouchableNativeFeedback.SelectableBackground()}
onPress={() => Actions.componenttwo({title: 'Food'})}
>
<View>
.......
</View>
</TouchableNativeFeedback>
In my Router.js where I have my Scenes
<Scene
key="componenttwo"
component={ComponentTwo}
backTitle={'Component One'}
getTitle={props.title} //this is the one
/>
Hope it helps!
@SoldierCorp Thanks for your great example. But how can I do if I want to use react-native-router-flux with redux? I stored the titles of tabs in my reducers.
I'm using redux too and in my case the rightTitle is a username that is stored in the global redux state. There are several ways this username can change - a user action, a API call, redux-persist dehydrating the store (i.e. changing from null to a value).
In all cases the router should refresh the title in the navbar, but it doesn't and I could not figure out the correct way to hook in the Actions.refresh() too.
BTW, by using Reactotron, I can see that my React component NavigationRouter does receive the props, so I tried even this:
componentWillReceiveProps (newProps) {
console.tron.display({preview: "Received new props", value: newProps})
Actions.refresh()
}
But that only messed with the navigation flow when the user changed the username, but did not refresh the right title.
How can I make the navbar more reactive on the props?
Most helpful comment
I'm using the following code to set a dynamic title of my navbar:
ComponentOne.jsIn my
Router.jswhere I have my ScenesHope it helps!