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.tsx 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { NavigationContainer, Theme } from '@react-navigation/native';
  2. import { createStackNavigator } from '@react-navigation/stack';
  3. import React, { useCallback } from 'react';
  4. import { StatusBar } from 'react-native';
  5. import { connect } from 'react-redux';
  6. import { IReduxState, IStore } from '../../../app/types';
  7. import DialInSummary from '../../../invite/components/dial-in-summary/native/DialInSummary';
  8. import Prejoin from '../../../prejoin/components/native/Prejoin';
  9. import UnsafeRoomWarning from '../../../prejoin/components/native/UnsafeRoomWarning';
  10. import { isUnsafeRoomWarningEnabled } from '../../../prejoin/functions';
  11. import VisitorsQueue from '../../../visitors/components/native/VisitorsQueue';
  12. // eslint-disable-next-line
  13. // @ts-ignore
  14. import WelcomePage from '../../../welcome/components/WelcomePage';
  15. import { isWelcomePageEnabled } from '../../../welcome/functions';
  16. import { _ROOT_NAVIGATION_READY } from '../actionTypes';
  17. import { rootNavigationRef } from '../rootNavigationContainerRef';
  18. import { screen } from '../routes';
  19. import {
  20. conferenceNavigationContainerScreenOptions,
  21. connectingScreenOptions,
  22. dialInSummaryScreenOptions,
  23. navigationContainerTheme,
  24. preJoinScreenOptions,
  25. unsafeMeetingScreenOptions,
  26. visitorsScreenOptions,
  27. welcomeScreenOptions
  28. } from '../screenOptions';
  29. import ConnectingPage from './ConnectingPage';
  30. import ConferenceNavigationContainer
  31. from './conference/components/ConferenceNavigationContainer';
  32. const RootStack = createStackNavigator();
  33. interface IProps {
  34. /**
  35. * Redux dispatch function.
  36. */
  37. dispatch: IStore['dispatch'];
  38. /**
  39. * Is unsafe room warning available?
  40. */
  41. isUnsafeRoomWarningAvailable: boolean;
  42. /**
  43. * Is welcome page available?
  44. */
  45. isWelcomePageAvailable: boolean;
  46. }
  47. const RootNavigationContainer = ({ dispatch, isUnsafeRoomWarningAvailable, isWelcomePageAvailable }: IProps) => {
  48. const initialRouteName = isWelcomePageAvailable
  49. ? screen.welcome.main : screen.connecting;
  50. const onReady = useCallback(() => {
  51. dispatch({
  52. type: _ROOT_NAVIGATION_READY,
  53. ready: true
  54. });
  55. }, [ dispatch ]);
  56. return (
  57. <NavigationContainer
  58. independent = { true }
  59. onReady = { onReady }
  60. ref = { rootNavigationRef }
  61. theme = { navigationContainerTheme as Theme }>
  62. <StatusBar
  63. animated = { true }
  64. backgroundColor = 'transparent'
  65. barStyle = { 'light-content' }
  66. translucent = { true } />
  67. <RootStack.Navigator
  68. initialRouteName = { initialRouteName }>
  69. {
  70. isWelcomePageAvailable
  71. && <>
  72. <RootStack.Screen // @ts-ignore
  73. component = { WelcomePage }
  74. name = { screen.welcome.main }
  75. options = { welcomeScreenOptions } />
  76. <RootStack.Screen
  77. // @ts-ignore
  78. component = { DialInSummary }
  79. name = { screen.dialInSummary }
  80. options = { dialInSummaryScreenOptions } />
  81. </>
  82. }
  83. <RootStack.Screen
  84. component = { ConnectingPage }
  85. name = { screen.connecting }
  86. options = { connectingScreenOptions } />
  87. <RootStack.Screen
  88. component = { Prejoin }
  89. name = { screen.preJoin }
  90. options = { preJoinScreenOptions } />
  91. {
  92. isUnsafeRoomWarningAvailable
  93. && <RootStack.Screen
  94. component = { UnsafeRoomWarning }
  95. name = { screen.unsafeRoomWarning }
  96. options = { unsafeMeetingScreenOptions } />
  97. }
  98. <RootStack.Screen
  99. component = { VisitorsQueue }
  100. name = { screen.visitorsQueue }
  101. options = { visitorsScreenOptions } />
  102. <RootStack.Screen
  103. component = { ConferenceNavigationContainer }
  104. name = { screen.conference.root }
  105. options = { conferenceNavigationContainerScreenOptions } />
  106. </RootStack.Navigator>
  107. </NavigationContainer>
  108. );
  109. };
  110. /**
  111. * Maps part of the Redux store to the props of this component.
  112. *
  113. * @param {Object} state - The Redux state.
  114. * @returns {IProps}
  115. */
  116. function mapStateToProps(state: IReduxState) {
  117. return {
  118. isUnsafeRoomWarningAvailable: isUnsafeRoomWarningEnabled(state),
  119. isWelcomePageAvailable: isWelcomePageEnabled(state)
  120. };
  121. }
  122. export default connect(mapStateToProps)(RootNavigationContainer);