React-Native: Bottom Tab Navigator: 'tabBarOptions' is deprecated. Migrate the options to 'screenOptions' instead
Asked Answered
S

1

7

I am developing a mobile app with React Native, and in it I use Tab.Navigator - Tab.Screen component. In the Navigator I use the initialRouteName , tabBarOptions , and screenOptions properties. Everything works fine in the other properties, until the javaScript finds screenOptions. Then it gives me the alert:

// Place the following in 'screenOptions' in your code to keep current behavior:

{
   "tabBarStyle": [
    {
      "display": "flex"
    },
    null
   ]
}

See https://reactnavigation.org/docs/bottom-tab-navigator#options for more details.

I already did it in my code:

const App = () => {
     return (
       <>
      <NavigationContainer>
        <Tab.Navigator
          initialRouteName='ExerciseScreensStack'
          tabBarOptions={{
            tabBarActiveTintColor: '#efb810',
            tabBarInactiveTintColor: 'black'
          }}
          screenOptions = {({ route }) =>({
            tabBarStyle: [
              {
                display: "flex"
              },
              null
            ],
        tabBarIcon: ({ color }) => 
        screenOptions(route, color),

      })}
      >

And this is the function that renders the color of my icons when I am on one of the screens:

const screenOptions = (route, color ) =>{
  let IconName;

  switch (route.name){
    case 'Home':
    IconName = "home-circle-outline"
    break;

    case "ExerciseScreensStack":
    IconName = "basketball"
    break;

    case 'RoutinesStack':
    IconName = "walk"
    break;

  }

  return(
    <Icon type='material-community' name={IconName} size={22} 
color={color}/>
); }

And I'm still having the same problem. What should I do to fix it? Should I ignore it since it doesn't circumstantially affect the app's performance? Why is this happening?

Story answered 30/6, 2022 at 21:51 Comment(3)
Please post the entire code snippet i.e your navigator setup and the relevant tab screen.Pepe
I just updated the post with everything that seemed relevant to me. Any idea why it happens?Story
Does this answer your question? Error passing tabBarOptions property of react navigationDialecticism
L
10

Place the options in tabBarOptions into screenOptions instead, like so:

     screenOptions = {({ route }) =>({
            tabBarActiveTintColor: '#efb810',
            tabBarInactiveTintColor: 'black',
            tabBarStyle: [
              {
                display: "flex"
              },
              null
            ],
        tabBarIcon: ({ color }) => 
        screenOptions(route, color),       
      })}

Its giving this warning because the tabBarOptions has been deprecated in React Navigation v6.x

Leprechaun answered 1/7, 2022 at 5:41 Comment(1)
Also why don't we come up with a different name for screenOptions function. Like screenIconColor = (route, color) => { ... } or something to avoid confusionPepe

© 2022 - 2024 — McMap. All rights reserved.