React-native-router-flux: Dynamic changing title tabbar

Created on 18 Jan 2017  路  5Comments  路  Source: aksonov/react-native-router-flux

Version

Tell us which versions you are using:

  • react-native-router-flux v3.37?.?
  • react-native v0.40.0

I try to change the title of tabbar using props/state when click my button, but nothing happened. What should I do?

Most helpful comment

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!

All 5 comments

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GCour picture GCour  路  3Comments

fgrs picture fgrs  路  3Comments

sreejithr picture sreejithr  路  3Comments

jgibbons picture jgibbons  路  3Comments

wootwoot1234 picture wootwoot1234  路  3Comments