You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rootNavigationContainerRef.ts 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { NavigationContainerRef } from '@react-navigation/native';
  2. import React from 'react';
  3. import { IStore } from '../../app/types';
  4. import { IStateful } from '../../base/app/types';
  5. import { toState } from '../../base/redux/functions';
  6. import { isWelcomePageEnabled } from '../../welcome/functions';
  7. import { _sendReadyToClose } from '../external-api/functions';
  8. import { screen } from './routes';
  9. export const rootNavigationRef = React.createRef<NavigationContainerRef<any>>();
  10. /**
  11. * User defined navigation action included inside the reference to the container.
  12. *
  13. * @param {string} name - Destination name of the route that has been defined somewhere.
  14. * @param {Object} params - Params to pass to the destination route.
  15. * @returns {Function}
  16. */
  17. export function navigateRoot(name: string, params?: Object) {
  18. return rootNavigationRef.current?.navigate(name, params);
  19. }
  20. /**
  21. * User defined navigation action included inside the reference to the container.
  22. *
  23. * @returns {Function}
  24. */
  25. export function goBack() {
  26. return rootNavigationRef.current?.goBack();
  27. }
  28. /**
  29. * Navigates back to Welcome page, if it's available.
  30. *
  31. * @param {Object|Function} stateful - Either the whole Redux state object or the Redux store's {@code getState} method.
  32. * @param {Function} dispatch - Redux dispatch function.
  33. * @returns {void}
  34. */
  35. export function goBackToRoot(stateful: IStateful, dispatch: IStore['dispatch']) {
  36. const state = toState(stateful);
  37. if (isWelcomePageEnabled(state)) {
  38. navigateRoot(screen.welcome.main);
  39. } else {
  40. // For JitsiSDK, WelcomePage is not available
  41. _sendReadyToClose(dispatch);
  42. }
  43. }