0
votes

I have set up Navigation with React Navigator 3.0 In order to successfully pass props from a parent component, I am calling my TabNavigator like this:

return (
        <View style={styles.container}>
          <TabNavigator screenProps={{deleteToken: this.deleteJWT }} />
        </View>
      );

My TabNavigator component then renders several screens. My previous method was to use the default code in the documentation (shown below for HomeScreen), but now since I'm passing props, I need to use the method shown below for ProfileScreen (arrow function).

My problem is that I don't know where to put the navigationOptions for the ProfileScreen when using the arrow function.

const TabNavigator = createBottomTabNavigator(
  {
  Profile: (props) => {
    return <ProfileScreen {...props.screenProps} />;
  },
  Home: { screen: HomeScreen,
          navigationOptions: {
            //tabBarLabel: 'Inicio',
            tabBarIcon: ({ tintColor, focused }) => (
          <Ionicons
            name={focused ? 'ios-home' : 'ios-home'}
            size={26}
            style={{ color: tintColor }}
          />
        ),
          //  tabBarIcon: () => {
          //                <Image
          //                style={{ width: 50, height: 50 }}
          //                source={{ uri: 'https://facebook.github.io/react/img/logo_og.png' }}
          //                />
        //},
        }
      },

Update: The obvious place would be to put the NavigationOptions object in the screen being returned, but it is being ignored:

export default class ProfileScreen extends React.Component {
  static navigationOptions = {

        tabBarLabel: 'Perfil',
        tabBarIcon: ({ tintColor, focused }) => (
      <Ionicons
        name={focused ? 'ios-person' : 'ios-person'} //TODO change to focused icon
        size={26}
        style={{ color: tintColor }}
      />
    )
  }
1

1 Answers

0
votes

This is the correct syntax:

const TabNavigator = createBottomTabNavigator(
  {
  Profile: {
    screen: props => <ProfileScreen {...props.screenProps} />,
    navigationOptions: {
        //tabBarLabel: 'Perfil',
        tabBarIcon: ({ tintColor, focused }) => (
      <Ionicons
        name={focused ? 'ios-person' : 'ios-person'} //TODO change to focused icon
        size={26}
        style={{ color: tintColor }}
      />
    ),