Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

DialInSummary.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { Linking, 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 {
  9. HeaderWithNavigation,
  10. LoadingIndicator,
  11. SlidingView
  12. } from '../../../../base/react';
  13. import { connect } from '../../../../base/redux';
  14. import { hideDialInSummary } from '../../../actions';
  15. import { getDialInfoPageURLForURIString } from '../../../functions';
  16. import DialInSummaryErrorDialog from './DialInSummaryErrorDialog';
  17. import styles, { INDICATOR_COLOR } from './styles';
  18. type Props = {
  19. /**
  20. * The URL to display the summary for.
  21. */
  22. _summaryUrl: ?string,
  23. dispatch: Dispatch<any>
  24. };
  25. /**
  26. * Implements a React native component that displays the dial in info page for a specific room.
  27. */
  28. class DialInSummary extends Component<Props> {
  29. /**
  30. * Initializes a new instance.
  31. *
  32. * @inheritdoc
  33. */
  34. constructor(props: Props) {
  35. super(props);
  36. this._onCloseView = this._onCloseView.bind(this);
  37. this._onError = this._onError.bind(this);
  38. this._onNavigate = this._onNavigate.bind(this);
  39. this._renderLoading = this._renderLoading.bind(this);
  40. }
  41. /**
  42. * Implements React's {@link Component#render()}.
  43. *
  44. * @inheritdoc
  45. */
  46. render() {
  47. const { _summaryUrl } = this.props;
  48. return (
  49. <SlidingView
  50. position = 'bottom'
  51. show = { Boolean(_summaryUrl) } >
  52. <View style = { styles.webViewWrapper }>
  53. <HeaderWithNavigation
  54. headerLabelKey = 'info.label'
  55. onPressBack = { this._onCloseView } />
  56. <WebView
  57. onError = { this._onError }
  58. onShouldStartLoadWithRequest = { this._onNavigate }
  59. renderLoading = { this._renderLoading }
  60. source = {{ uri: getDialInfoPageURLForURIString(_summaryUrl) }}
  61. startInLoadingState = { true }
  62. style = { styles.webView } />
  63. </View>
  64. </SlidingView>
  65. );
  66. }
  67. _onCloseView: () => void;
  68. /**
  69. * Closes the view.
  70. *
  71. * @returns {void}
  72. */
  73. _onCloseView() {
  74. this.props.dispatch(hideDialInSummary());
  75. }
  76. _onError: () => void;
  77. /**
  78. * Callback to handle the error if the page fails to load.
  79. *
  80. * @returns {void}
  81. */
  82. _onError() {
  83. this.props.dispatch(hideDialInSummary());
  84. this.props.dispatch(openDialog(DialInSummaryErrorDialog));
  85. }
  86. _onNavigate: Object => Boolean;
  87. /**
  88. * Callback to intercept navigation inside the webview and make the native app handle the dial requests.
  89. *
  90. * NOTE: We don't navigate to anywhere else form that view.
  91. *
  92. * @param {any} request - The request object.
  93. * @returns {boolean}
  94. */
  95. _onNavigate(request) {
  96. const { url } = request;
  97. if (url.startsWith('tel:')) {
  98. Linking.openURL(url);
  99. this.props.dispatch(hideDialInSummary());
  100. }
  101. return url === getDialInfoPageURLForURIString(this.props._summaryUrl);
  102. }
  103. _renderLoading: () => React$Component<any>;
  104. /**
  105. * Renders the loading indicator.
  106. *
  107. * @returns {React$Component<any>}
  108. */
  109. _renderLoading() {
  110. return (
  111. <View style = { styles.indicatorWrapper }>
  112. <LoadingIndicator
  113. color = { INDICATOR_COLOR }
  114. size = 'large' />
  115. </View>
  116. );
  117. }
  118. }
  119. /**
  120. * Maps part of the Redux state to the props of this component.
  121. *
  122. * @param {Object} state - The Redux state.
  123. * @returns {{
  124. * _summaryUrl: ?string
  125. * }}
  126. */
  127. function _mapStateToProps(state) {
  128. return {
  129. _summaryUrl: state['features/invite'].summaryUrl
  130. };
  131. }
  132. export default translate(connect(_mapStateToProps)(DialInSummary));