Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

RootNavigationContainer.tsx 4.6KB

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