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.

RootNavigationContainer.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { NavigationContainer } from '@react-navigation/native';
  2. import { createNativeStackNavigator } from '@react-navigation/native-stack';
  3. import React, { useCallback } from 'react';
  4. import { connect } from '../../../base/redux';
  5. import { DialInSummary } from '../../../invite';
  6. import Prejoin from '../../../prejoin/components/Prejoin.native';
  7. import { isWelcomePageEnabled } from '../../../welcome/functions';
  8. import { _ROOT_NAVIGATION_READY } from '../actionTypes';
  9. import { rootNavigationRef } from '../rootNavigationContainerRef';
  10. import { screen } from '../routes';
  11. import {
  12. conferenceNavigationContainerScreenOptions,
  13. connectingScreenOptions,
  14. dialInSummaryScreenOptions,
  15. drawerNavigatorScreenOptions,
  16. navigationContainerTheme,
  17. preJoinScreenOptions
  18. } from '../screenOptions';
  19. import ConnectingPage from './ConnectingPage';
  20. import ConferenceNavigationContainer
  21. from './conference/components/ConferenceNavigationContainer';
  22. import WelcomePageNavigationContainer
  23. from './welcome/components/WelcomePageNavigationContainer';
  24. const RootStack = createNativeStackNavigator();
  25. type Props = {
  26. /**
  27. * Redux dispatch function.
  28. */
  29. dispatch: Function,
  30. /**
  31. * Is welcome page available?
  32. */
  33. isWelcomePageAvailable: boolean
  34. }
  35. const RootNavigationContainer = ({ dispatch, isWelcomePageAvailable }: Props) => {
  36. const initialRouteName = isWelcomePageAvailable
  37. ? screen.root : screen.connecting;
  38. const onReady = useCallback(() => {
  39. dispatch({
  40. type: _ROOT_NAVIGATION_READY,
  41. ready: true
  42. });
  43. }, [ dispatch ]);
  44. return (
  45. <NavigationContainer
  46. independent = { true }
  47. onReady = { onReady }
  48. ref = { rootNavigationRef }
  49. theme = { navigationContainerTheme }>
  50. <RootStack.Navigator
  51. initialRouteName = { initialRouteName }>
  52. {
  53. isWelcomePageAvailable
  54. && <>
  55. <RootStack.Screen
  56. component = { WelcomePageNavigationContainer }
  57. name = { screen.root }
  58. options = { drawerNavigatorScreenOptions } />
  59. <RootStack.Screen
  60. component = { DialInSummary }
  61. name = { screen.dialInSummary }
  62. options = { dialInSummaryScreenOptions } />
  63. </>
  64. }
  65. <RootStack.Screen
  66. component = { ConnectingPage }
  67. name = { screen.connecting }
  68. options = { connectingScreenOptions } />
  69. <RootStack.Screen
  70. component = { Prejoin }
  71. name = { screen.preJoin }
  72. options = { preJoinScreenOptions } />
  73. <RootStack.Screen
  74. component = { ConferenceNavigationContainer }
  75. name = { screen.conference.root }
  76. options = { conferenceNavigationContainerScreenOptions } />
  77. </RootStack.Navigator>
  78. </NavigationContainer>
  79. );
  80. };
  81. /**
  82. * Maps part of the Redux store to the props of this component.
  83. *
  84. * @param {Object} state - The Redux state.
  85. * @returns {Props}
  86. */
  87. function mapStateToProps(state: Object) {
  88. return {
  89. isWelcomePageAvailable: isWelcomePageEnabled(state)
  90. };
  91. }
  92. export default connect(mapStateToProps)(RootNavigationContainer);