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.

DialInSummary.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { Linking, Platform, View } from 'react-native';
  4. import { WebView } from 'react-native-webview';
  5. import { type Dispatch } from 'redux';
  6. import { openDialog } from '../../../../base/dialog';
  7. import { translate } from '../../../../base/i18n';
  8. import { IconClose } from '../../../../base/icons';
  9. import JitsiScreen from '../../../../base/modal/components/JitsiScreen';
  10. import { LoadingIndicator } from '../../../../base/react';
  11. import { connect } from '../../../../base/redux';
  12. import HeaderNavigationButton
  13. from '../../../../mobile/navigation/components/HeaderNavigationButton';
  14. import { navigateRoot } from '../../../../mobile/navigation/rootNavigationContainerRef';
  15. import { screen } from '../../../../mobile/navigation/routes';
  16. import { getDialInfoPageURLForURIString } from '../../../functions';
  17. import DialInSummaryErrorDialog from './DialInSummaryErrorDialog';
  18. import styles, { INDICATOR_COLOR } from './styles';
  19. type Props = {
  20. dispatch: Dispatch<any>,
  21. /**
  22. * Default prop for navigating between screen components(React Navigation).
  23. */
  24. navigation: Object,
  25. /**
  26. * Default prop for navigating between screen components(React Navigation).
  27. */
  28. route: Object,
  29. /**
  30. * Translation function.
  31. */
  32. t: Function
  33. };
  34. /**
  35. * Implements a React native component that displays the dial in info page for a specific room.
  36. */
  37. class DialInSummary extends Component<Props> {
  38. /**
  39. * Initializes a new instance.
  40. *
  41. * @inheritdoc
  42. */
  43. constructor(props: Props) {
  44. super(props);
  45. this._onNavigateToRoot = this._onNavigateToRoot.bind(this);
  46. this._onError = this._onError.bind(this);
  47. this._onNavigate = this._onNavigate.bind(this);
  48. this._renderLoading = this._renderLoading.bind(this);
  49. }
  50. /**
  51. * Implements React's {@link Component#componentDidMount()}. Invoked
  52. * immediately after mounting occurs.
  53. *
  54. * @inheritdoc
  55. * @returns {void}
  56. */
  57. componentDidMount() {
  58. const { navigation, t } = this.props;
  59. navigation.setOptions({
  60. headerLeft: () => {
  61. if (Platform.OS === 'ios') {
  62. return (
  63. <HeaderNavigationButton
  64. label = { t('dialog.close') }
  65. onPress = { this._onNavigateToRoot } />
  66. );
  67. }
  68. return (
  69. <HeaderNavigationButton
  70. onPress = { this._onNavigateToRoot }
  71. src = { IconClose } />
  72. );
  73. }
  74. });
  75. }
  76. /**
  77. * Implements React's {@link Component#render()}.
  78. *
  79. * @inheritdoc
  80. */
  81. render() {
  82. const { route } = this.props;
  83. const summaryUrl = route.params?.summaryUrl;
  84. return (
  85. <JitsiScreen
  86. style = { styles.backDrop }>
  87. <WebView
  88. onError = { this._onError }
  89. onShouldStartLoadWithRequest = { this._onNavigate }
  90. renderLoading = { this._renderLoading }
  91. setSupportMultipleWindows = { false }
  92. source = {{ uri: getDialInfoPageURLForURIString(summaryUrl) }}
  93. startInLoadingState = { true }
  94. style = { styles.webView } />
  95. </JitsiScreen>
  96. );
  97. }
  98. _onNavigateToRoot: () => void;
  99. /**
  100. * Callback to handle navigation back to root.
  101. *
  102. * @returns {void}
  103. */
  104. _onNavigateToRoot() {
  105. navigateRoot(screen.root);
  106. }
  107. _onError: () => void;
  108. /**
  109. * Callback to handle the error if the page fails to load.
  110. *
  111. * @returns {void}
  112. */
  113. _onError() {
  114. this.props.dispatch(openDialog(DialInSummaryErrorDialog));
  115. }
  116. _onNavigate: Object => Boolean;
  117. /**
  118. * Callback to intercept navigation inside the webview and make the native app handle the dial requests.
  119. *
  120. * NOTE: We don't navigate to anywhere else form that view.
  121. *
  122. * @param {any} request - The request object.
  123. * @returns {boolean}
  124. */
  125. _onNavigate(request) {
  126. const { url } = request;
  127. const { route } = this.props;
  128. const summaryUrl = route.params?.summaryUrl;
  129. if (url.startsWith('tel:')) {
  130. Linking.openURL(url);
  131. }
  132. return url === getDialInfoPageURLForURIString(summaryUrl);
  133. }
  134. _renderLoading: () => React$Component<any>;
  135. /**
  136. * Renders the loading indicator.
  137. *
  138. * @returns {React$Component<any>}
  139. */
  140. _renderLoading() {
  141. return (
  142. <View style = { styles.indicatorWrapper }>
  143. <LoadingIndicator
  144. color = { INDICATOR_COLOR }
  145. size = 'large' />
  146. </View>
  147. );
  148. }
  149. }
  150. export default translate(connect()(DialInSummary));