Search code examples
react-nativenavigationtabview

How to move in next tab on text click in React Native using TabView?


I am new in React Native. I am using TabView [react-native-tab-view - npm] in my project. I declared one const for rendering screens like :

const renderScene = SceneMap({
      signin: Sign_in,
       signup: Sign_up,
  });

and when on text click i want to jump next tab and write code like below :

<Text style={style.signup_text} onPress={() => { this.props.jumpTo('signup') }}>Sing Up</Text>

Its working fine but when i change my code to pass navigation property to that tab's class than its not working .Code is like:

const renderScene = SceneMap({
        signin: () => <Sign_in navigation={navigation} />,
        signup: () => <Sign_up navigation={navigation}  />,
    });

Now how can i move to next tab .Using above code jumpTo is not working. I hope you will understand what i want to explain.


Solution

  • if you want to send custom props to components you have to chage the renderScene to

    const renderScene = (props) => {
        switch (props.route.key) {
          case 'signin':
            return <Sign_in {...props} {...{navigation}} />;
          case 'signup':
            return <Sign_un {...props} {...{navigation}}/>;
          default:
            return null;
        }
      }