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

Call action when pressing tab in TabNavigator #2804

Closed
mazing opened this issue Oct 22, 2017 · 4 comments
Closed

Call action when pressing tab in TabNavigator #2804

mazing opened this issue Oct 22, 2017 · 4 comments

Comments

@mazing
Copy link

mazing commented Oct 22, 2017

I have two tab navigators at different routes.

Is it possible to navigate to a route by pressing a tab?

I have tried

const TabNavigator1 = TabNavigator({
  Home: {
    screen: HomeScreen,
  },
  Exit: {
    screen: ({ navigation }) => {
      navigation.navigate('TabNavigator2')
      return Something // because it has to return something
    },
})

it actually does navigate as I wanted, but I receive a warning saying Functions are not valid as React child.

It also seems a bit hacky to do it like this. Could I replace screen: ({ navigation }) => ... with something like onPress: ({ navigation }) => ...

@carsonwah
Copy link

According to the doc, does customizing tabBarOnPress works for you? Though it only provides a jumpToIndex() exit method. I'm not sure.

@2ducanhpham
Copy link

import { StackNavigator, TabNavigator, TabBarBottom } from 'react-navigation';

//config 
tabBarComponent: (props) => {
    return (
      <TabBarBottom
          {...props}
          jumpToIndex={(index) => {
            //code here
            //ex: props.screenProps.rootNavigation.dispatch(jumpToTabYourPost(index));
        }}
      />
    )
  },
  initialRouteName: 'DEMO',

@carsonwah
Copy link

@mazing You may also take a look on my implementation for scrollToTop function.

#2955

@satya164
Copy link
Member

satya164 commented Jan 4, 2018

Closing since tabBarOnPress option already exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants