title: Passing props to a dynamic TabNavigator
body: <p>(also asked in <a href="https://github.com/react-navigation/react-navigation/issues/4059#issuecomment-453100740" rel="nofollow noreferrer">https://github.com/react-navigation/react-navigation/issues/4059#issuecomment-453100740</a>)</p>
  
  <p>I have replaced a static TabNavigator with a dynamic one, and things seem to work.<br>
  However, props that have been passed as expected are not passed any more the same way.<br>
  Any idea how to fix this? Either by having the props passed as in the static solution, or by passing the required props (this.props.navigation).</p>
  
  <h3>This is my top navigator:</h3>
  
  <pre><code>export default createDrawerNavigator({
      Drawer: MainDrawerNavigator,
      Main: MainTabNavigator
  }, {
    contentComponent: props =&gt; &lt;Drawer {...props} /&gt;,
  });
  </code></pre>
  
  <h3>This the static Tab Navigator and one of the Stacks:</h3>
  
  <pre><code>const ProfileStack = createStackNavigator({
    Profile: {
      screen: Profile,
      navigationOptions: () =&gt; ({
          title: 'Profile'
      })
    }
  }, {
    initialRouteName: 'Profile'
  });
  
  ProfileStack.navigationOptions = {
    tabBarLabel: 'Profile',
    tabBarIcon: ({ focused }) =&gt; (
      &lt;TabBarIcon
        focused={focused}
        name= 'md-person' /&gt;
    )};
  
  const MainTabNavigator = createBottomTabNavigator({
    RequestStack,
    ProfileStack
  }, {
      headerMode: 'none',
      initialRouteName: ProfileStack
  });
  </code></pre>
  
  <h3>And the <code>Profile</code> screen:</h3>
  
  <pre><code>import React from 'react';
  import { View, TouchableOpacity } from 'react-native';
  import { Container, Header, Content, Text
  } from 'native-base';
  
  export default class Profile extends React.Component {
    static navigationOptions = {
      header: null
    };
  
    constructor(props) {
      super(props);
    }
  
    render() {
      console.log('in Profile. this.props:');
      console.log(this.props);
      return (
          &lt;Container style={styles.container}&gt;
            &lt;Header&gt;
                &lt;TouchableOpacity
                  onPress={() =&gt; this.props.navigation.openDrawer()}&gt;
                   &lt;Icon name="md-more" /&gt;
                &lt;/TouchableOpacity&gt;
            &lt;/Header&gt;
            &lt;Content&gt;
  
             &lt;Text&gt;aaa&lt;/Text&gt;
            &lt;/Content&gt;
          &lt;/Container&gt;
      );
    }
  }
  </code></pre>
  
  <h3>A click on the "md-more" icon opens the drawer (this.props.navigation.openDrawer).</h3>
  
  <h3>Using a dynamic tab navigator - openDrawer is not passed any more to 'Profile'.</h3>
  
  <p>when I replace the above static Tab Navigator with the following Dynamic one, this.props.navigation.openDrawer is not passed and therefore not defined in 'Profile' (Profile doesn't change, the change is only in the bottom tab navigator). </p>
  
  <h3>Here is the dynamic Tab Navigator:</h3>
  
  <pre><code>export default class DynamicTabNavigator extends React.Component {
  
    constructor(props) {
      super(props);
    }
  
    _tabNavigator() {
      let tabs = {};
      const a = 2; 
      if (a &gt; 1) {   // the actual line is obviously different, I am trying to simplify the example
        tabs = { RequestStack, ManageStack, MessagesStack, ProfileStack };
      } else {
        tabs = { WorkStack, ManageStack, MessagesStack, ProfileStack };
      }
  
      console.log('in _tabNavigator. this.props.navigation:');
      console.log(this.props.navigation);
      return createBottomTabNavigator(tabs, {
          headerMode: 'none',
      });
    }
  
    render() {
      const Tabs = this._tabNavigator.bind(this)();
      return (
        &lt;Tabs/&gt;
      );
    }
  }
  
  </code></pre>
  
  <h3>This is the output of console.log() from DynamicTabNavigator:</h3>
  
  <pre><code>in _tabNavigator. this.props.navigation:
   Object {
     "actions": Object {
       "closeDrawer": [Function closeDrawer],
       "goBack": [Function goBack],
       "navigate": [Function navigate],
       "openDrawer": [Function openDrawer],
       "setParams": [Function setParams],
       "toggleDrawer": [Function toggleDrawer],
     },
     "addListener": [Function addListener],
     "closeDrawer": [Function anonymous],
     "dangerouslyGetParent": [Function anonymous],
     "dispatch": [Function anonymous],
     "getChildNavigation": [Function getChildNavigation],
     "getParam": [Function anonymous],
     "getScreenProps": [Function anonymous],
     "goBack": [Function anonymous],
     "isFocused": [Function isFocused],
     "navigate": [Function anonymous],
     "openDrawer": [Function anonymous],
     "router": undefined,
     "setParams": [Function anonymous],
     "state": Object {
       "key": "Main",
       "params": undefined,
       "routeName": "Main",
     },
     "toggleDrawer": [Function anonymous],
   }
  </code></pre>
  
  <h3>This is the output of console.log() from Profile, when DynamicTabNavigator is in place:</h3>
  
  <p>(I expected all props, like for instance, openDrawer, to be the same as for DynamicTabNavigator, and I don't understand why they aren't)</p>
  
  <pre><code> in Profile. this.props:
   Object {
     "appMode": "WORK_MODE",
     "dispatch": [Function anonymous],
     "navigation": Object {
       "actions": Object {
         "dismiss": [Function dismiss],
         "goBack": [Function goBack],
         "navigate": [Function navigate],
         "pop": [Function pop],
         "popToTop": [Function popToTop],
         "push": [Function push],
         "replace": [Function replace],
         "reset": [Function reset],
         "setParams": [Function setParams],
       },
       "addListener": [Function addListener],
       "dangerouslyGetParent": [Function anonymous],
       "dismiss": [Function anonymous],
       "dispatch": [Function anonymous],
       "getChildNavigation": [Function getChildNavigation],
       "getParam": [Function anonymous],
       "getScreenProps": [Function anonymous],
       "goBack": [Function anonymous],
       "isFocused": [Function isFocused],
       "navigate": [Function anonymous],
       "pop": [Function anonymous],
       "popToTop": [Function anonymous],
       "push": [Function anonymous],
       "replace": [Function anonymous],
       "reset": [Function anonymous],
       "router": undefined,
       "setParams": [Function anonymous],
       "state": Object {
         "key": "id-1547113035295-8",
         "routeName": "Profile",
       },
     },
     "screenProps": undefined,
   }
  </code></pre>
  
  <h3>Questions regarding @dentemm's solution:</h3>
  
  <p>I a not sure how to implement your solution...</p>
  
  <ul>
  <li>Lets say that I have in my <code>TabRoutes</code> the three screens that you specified in your example</li>
  <li>In my redux state I have a variable called 'appState'. If it is true I want to display first &amp; second, if false first &amp; third.</li>
  <li><p>Here is the code that I wrote based on your example. I am not sure, however, which component is included in <code>CustomTabBar</code>. Can you elaborate?</p>
  
  <pre><code>import React from 'react';
  class CustomTabBar extends React.Component {
  
  render() {
  // a tab bar component has a routes object in the navigation state
  const { navigation } = this.props;
  
    // appState is extracted from redux state, see below
    if (this.props.appState) {
      return (
        &lt;View&gt;
          &lt;???
            name='First'
            onPress={this.navigationHandler}
            focused={navigation.state.index === index}
          /&gt;
          &lt;???
            name='Second'
            onPress={this.navigationHandler}
            focused={navigation.state.index === index}
          /&gt;
        &lt;/View&gt;
      );
    } else {
      return (
        &lt;View&gt;
          &lt;???
            name='First'
            onPress={this.navigationHandler}
            focused={navigation.state.index === index}
          /&gt;
          &lt;???
            name='Third'
            onPress={this.navigationHandler}
            focused={navigation.state.index === index}
          /&gt;
        &lt;/View&gt;
        );
      }
    }
  
    navigationHandler = (name) =&gt; {
      const {navigation} = this.props;
      navigation.navigate(name);
    }
  }
  
  const mapStateToProps = state =&gt; {
   const { appState } = state.app;
   return { appState };
  };
  
  export default connect(mapStateToProps)(CustomTabBar);
  </code></pre></li>
  </ul>