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

Tab icons do not render when defined as a function component #3170

Closed
lehresman opened this issue Dec 21, 2017 · 2 comments
Closed

Tab icons do not render when defined as a function component #3170

lehresman opened this issue Dec 21, 2017 · 2 comments

Comments

@lehresman
Copy link

I'm using create-react-native-app and their included vector icons.

When creating a TabNavigator, I can set the tabBarIcon to be a <Ionicons/> component just fine:

Code:

export const ScheduleNavigator = TabNavigator({
  ScheduleDetails: {
    screen: ScheduleDetailsScreen,
    navigationOptions: {
      title: "My Plan",
      tabBarIcon: <Ionicons name="ios-settings" size={24} />
    }
  },
  ScheduleUpcoming: {
    screen: ScheduleUpcomingScreen,
    navigationOptions: {
      title: "Upcoming",
      tabBarIcon: <Ionicons name="ios-calendar" size={24} />
    }
  },
  ScheduleCompleted: {
    screen: ScheduleCompletedScreen,
    navigationOptions: {
      title: "Completed",
      tabBarIcon: <Ionicons name="ios-checkmark-circle"  size={24} />
    }
  },
});

Screenshot:
iphone 6s - ios 11 1 2017-12-21 09-50-02

However, when I try to set the tabBarIcon to be a component function (so I can use the focused parameter), it renders nothing.

Code:

export const ScheduleNavigator = TabNavigator({
  ScheduleDetails: {
    screen: ScheduleDetailsScreen,
    navigationOptions: {
      title: "My Plan",
      tabBarIcon: ({focused}) => {
        <Ionicons name={focused ? "ios-settings" : 'ios-settings-outline'} size={24} />
      },
    }
  },
  ScheduleUpcoming: {
    screen: ScheduleUpcomingScreen,
    navigationOptions: {
      title: "Upcoming",
      tabBarIcon: ({focused}) => {
        <Ionicons name={focused ? "ios-calendar" : 'ios-calendar-outline'} size={24} />
      },
    }
  },
  ScheduleCompleted: {
    screen: ScheduleCompletedScreen,
    navigationOptions: {
      title: "Completed",
      tabBarIcon: ({focused}) => {
        <Ionicons name={focused ? "ios-checkmark-circle" : 'ios-checkmark-circle-outline'} size={24} />
      },
    }
  },
});

Screenshot:
iphone 6s - ios 11 1 2017-12-21 09-48-29

Am I doing something wrong, or is this a bug? I've seen other examples of people doing this just fine and as far as I can tell, I'm doing it the same way. That's what makes me think this might be some kind of bug.

software version
react-navigation 1.0.0-beta.22
react-native 0.50.3
@lehresman
Copy link
Author

Nevermind, I figured it out. It was just my own dumb fault and not using the right ES6 syntax for anonymous functions.

Should have been:

export const ScheduleNavigator = TabNavigator({
  ScheduleDetails: {
    screen: ScheduleDetailsScreen,
    navigationOptions: {
      title: "My Plan",
      tabBarIcon: ({focused}) =>
        <Ionicons name={focused ? "ios-settings" : 'ios-settings-outline'} size={24} />,
    }
  },
  ScheduleUpcoming: {
    screen: ScheduleUpcomingScreen,
    navigationOptions: {
      title: "Upcoming",
      tabBarIcon: ({focused}) =>
        <Ionicons name={focused ? "ios-calendar" : 'ios-calendar-outline'} size={24} />,
    }
  },
  ScheduleCompleted: {
    screen: ScheduleCompletedScreen,
    navigationOptions: {
      title: "Completed",
      tabBarIcon: ({focused}) =>
        <Ionicons name={focused ? "ios-checkmark-circle" : 'ios-checkmark-circle-outline'} size={24} />,
    }
  },
});

@pandumalik
Copy link

Thanks

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

2 participants