Kevin Amiranoff
Kevin Amiranoff

Reputation: 14468

Dismiss modal and change tab with Wix React Native Navigation

Is it possible to dismiss a modal and automatically change tab with Wix react-native-navigation 4.2.0.

This is what I have unsuccessfully tried:

  Navigation.dismissModal(componentId, {
      options: {
        bottomTabs: {
          currentTabIndex: 1,
        },
      },
    });

Upvotes: 0

Views: 1089

Answers (1)

Kevin Amiranoff
Kevin Amiranoff

Reputation: 14468

The way I managed to solve this is by using events and eventEmitter3 library

in events.js

import EventEmitter from 'eventemitter3';

export const events = new EventEmitter();

in Modal.js

  redirectToMyTab = () => {
    const { componentId } = this.props;
    events.emit('RedirectToMyTab');
    Navigation.dismissModal(componentId);
  };

And inside of one of tabs (as they are all mounted)

Tab0.js

  componentDidMount() {
    events.on('RedirectToMyTab', this.redirectToMyTab);
  }

  redirectToMyTab = () => {
    const { componentId } = this.props;
    Navigation.mergeOptions(componentId, {
      bottomTabs: {
        currentTabIndex: 1,
      },
    });
  };

Upvotes: 1

Related Questions