Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

screenProps are not available in navigationOptions.tabBar #240

Closed
davidruisinger opened this issue Feb 8, 2017 · 3 comments
Closed

screenProps are not available in navigationOptions.tabBar #240

davidruisinger opened this issue Feb 8, 2017 · 3 comments

Comments

@davidruisinger
Copy link

I'm trying to display some badgeCounts from my redux state in a Tabbbar

I have the following Component structure:
RootComponent (is connected to redux state which contains e.g. badgeCounbts for my Tabbar)
renders:

<Tabs screenProps={{
      badgeCount,
    }}
/>

Tabs component
is just a js file that export:

const Tabs = TabNavigator({
  Home: {
    screen: props => {
      console.log(props)  // {badgeCount: 0, navigation: Object}
      return <TabHome screenProps={{
        badgeCount: props.badgeCount,
      }} />
    },
    path: 'home',
    navigationOptions: {
      tabBar: navigation => {
        console.log(navigation.props) // undefined
        return {
          icon: ({ tintColor, focused }) => {
            return <TabIcon badgeCount={ navigation.props.badgeCount } />
          },
        }
      }
    },
  },
...
}, {
  swipeEnabled: false,
  animationEnabled: true,
  backBehavior: 'none',
  tabBarOptions: {
    style: styles.tabBar,
    activeTintColor: DXColors.secondary,
    inactiveTintColor: DXColors.text_important_light_bg,
    showLabel: false,
  },
})

Is there any way to access the screenPropswithin my navigationsOptions.tabBar function?
I think I could just move the render function to the screen component (?) but I'd like to keep the tabbar stuff centralized in one file.

@SpaceK33z
Copy link

SpaceK33z commented Feb 8, 2017

This is kinda related to / a dupe of #210 and #145 I think.

@DaveCole
Copy link

I've found if you add screenProps to the navigationOptions method arguments, you get them:

navigationOptions: ({ navigation, screenProps }) => ({ tabBarLabel: 'screenProps.foo: '+screenProps.foo });

Unfortunately if these values change, the Tab Bar does not rerender currently.

@spencercarli
Copy link
Member

Closing in favor of linked issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants