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.

SharedDocument.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { View } from 'react-native';
  4. import { WebView } from 'react-native-webview';
  5. import { ColorSchemeRegistry } from '../../../base/color-scheme';
  6. import { translate } from '../../../base/i18n';
  7. import { IconArrowBack } from '../../../base/icons';
  8. import JitsiScreen from '../../../base/modal/components/JitsiScreen';
  9. import { LoadingIndicator } from '../../../base/react';
  10. import { connect } from '../../../base/redux';
  11. import { goBack } from '../../../conference/components/native/ConferenceNavigationContainerRef';
  12. import HeaderNavigationButton
  13. from '../../../conference/components/native/HeaderNavigationButton';
  14. import { getSharedDocumentUrl } from '../../functions';
  15. import styles, { INDICATOR_COLOR } from './styles';
  16. /**
  17. * The type of the React {@code Component} props of {@code ShareDocument}.
  18. */
  19. type Props = {
  20. /**
  21. * URL for the shared document.
  22. */
  23. _documentUrl: string,
  24. /**
  25. * Color schemed style of the header component.
  26. */
  27. _headerStyles: Object,
  28. /**
  29. * Default prop for navigation between screen components(React Navigation)
  30. */
  31. navigation: Object,
  32. /**
  33. * Function to be used to translate i18n labels.
  34. */
  35. t: Function
  36. };
  37. /**
  38. * Implements a React native component that renders the shared document window.
  39. */
  40. class SharedDocument extends PureComponent<Props> {
  41. /**
  42. * Instantiates a new instance.
  43. *
  44. * @inheritdoc
  45. */
  46. constructor(props: Props) {
  47. super(props);
  48. this._renderLoading = this._renderLoading.bind(this);
  49. }
  50. /**
  51. * Implements React's {@link Component#componentDidMount()}. Invoked
  52. * immediately after this component is mounted.
  53. *
  54. * @inheritdoc
  55. * @returns {void}
  56. */
  57. componentDidMount() {
  58. const { navigation } = this.props;
  59. navigation.setOptions({
  60. headerLeft: () => (
  61. <HeaderNavigationButton
  62. onPress = { goBack }
  63. src = { IconArrowBack }
  64. style = { styles.headerArrowBack } />
  65. )
  66. });
  67. }
  68. /**
  69. * Implements React's {@link Component#render()}.
  70. *
  71. * @inheritdoc
  72. */
  73. render() {
  74. const { _documentUrl } = this.props;
  75. return (
  76. <JitsiScreen
  77. addHeaderHeightValue = { true }
  78. hasTabNavigator = { false }
  79. style = { styles.sharedDocContainer }>
  80. <WebView
  81. renderLoading = { this._renderLoading }
  82. source = {{ uri: _documentUrl }}
  83. startInLoadingState = { true } />
  84. </JitsiScreen>
  85. );
  86. }
  87. _renderLoading: () => React$Component<any>;
  88. /**
  89. * Renders the loading indicator.
  90. *
  91. * @returns {React$Component<any>}
  92. */
  93. _renderLoading() {
  94. return (
  95. <View style = { styles.indicatorWrapper }>
  96. <LoadingIndicator
  97. color = { INDICATOR_COLOR }
  98. size = 'large' />
  99. </View>
  100. );
  101. }
  102. }
  103. /**
  104. * Maps (parts of) the redux state to {@link SharedDocument} React {@code Component} props.
  105. *
  106. * @param {Object} state - The redux store/state.
  107. * @private
  108. * @returns {Object}
  109. */
  110. export function _mapStateToProps(state: Object) {
  111. const documentUrl = getSharedDocumentUrl(state);
  112. return {
  113. _documentUrl: documentUrl,
  114. _headerStyles: ColorSchemeRegistry.get(state, 'Header')
  115. };
  116. }
  117. export default translate(connect(_mapStateToProps)(SharedDocument));