Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using of Custom Tabs with StackNavigator?

I have list of users , each user has its display image in the list.

What I am trying is whenever user presses the display image , get redirected to his/her profile through stackNavigation .

CustomTabView:

    const CustomTabView = ({ router, navigation }) => {
  const { routes, index } = navigation.state;

  const ActiveScreen = router.getComponentForState(navigation.state);

  const routeNav = addNavigationHelpers({
    ...navigation,
    state: routes[index],
  });
  const routeOptions = router.getScreenOptions(routeNav, 'tabBar');
  return (
    <View style={styles.container}>
      <CustomTabBar
        navigation={navigation}
        activeRouteName={routes[index].routeName}
        icon={routeOptions.tabBarIcon}
      />
      <ActiveScreen
        navigation={addNavigationHelpers({
          ...navigation,
          state: routes[index]
        })}
      />
    </View>
  );
}; 

StackNavigator: // goToProfile.js // also tried placing in index.anndroid.js but didnt found a way to export

const goToProfile = StackNavigator({
  Profile: {
    screen: Profile,
    navigationOptions: ({ navigation }) => ({
      title: `${navigation.state.params.person.name.first} ${navigation.state.params.person.name.last}`
    })
  },
})

custom tabs: //index.android.js

const CustomTabRouter = TabRouter(
  {
    Chat: {
      screen: Chats,
      path: ""
    },
    Status: {
      screen: Contacts,
      path: "notifications"
    },
    Camera: {
      screen: Camera,
      path: "settings"
    }
  },
  {
    initialRouteName: "Chat",
  },


     );

    const CustomTabs = createNavigationContainer(
     createNavigator(CustomTabRouter)(CustomTabView)
    );

Also my component :

          <TouchableOpacity
            onPress = { () =>  this.props.navigation.navigate('Profile', { item } ) }  >
              <Avatar
                source={{ uri: item.picture.thumbnail }}
              />
          </TouchableOpacity>
like image 735
YaSh Chaudhary Avatar asked Jul 17 '17 13:07

YaSh Chaudhary


People also ask

How do you use stack Navigator and drawer navigation together?

Drawer navigator nested inside the initial screen of stack navigator with the initial screen's stack header hidden - The drawer can only be opened from the first screen of the stack. Stack navigators nested inside each screen of drawer navigator - The drawer appears over the header from the stack.


1 Answers

Your Stack Navigator will look like this:

    const ChatStack= StackNavigator({
      Chat:{screen: Chat,
      navigationOptions: {
       header: null,
     }},
     Profile: {
        screen: Profile,
        navigationOptions: ({ navigation }) => ({
          title: `${navigation.state.params.person.name.first} ${navigation.state.params.person.name.last}`,
          tabBarVisible: false
         // depending if you want to hide the tabBar on the profile page if not remove it.
        })
      },
    }) 

Then Your customTab will take this shape:

const CustomTabRouter = TabRouter(
  {
    Chat: {
      screen: ChatStack,
    },
    Status: {
      screen: Contacts,
      path: "notifications"
    },
    Camera: {
      screen: Camera,
      path: "settings"
    }
  },
.........

With those changes you should be able to navigate to Profile screen with your

this.props.navigation.navigate('Profile', { item } )
like image 167
Caleb Tolu Avatar answered Oct 14 '22 12:10

Caleb Tolu