jiti-meet/react/features/invite/components/dial-in-summary/native/DialInSummary.js

140 lines
3.7 KiB
JavaScript
Raw Normal View History

2019-05-07 14:50:57 +00:00
// @flow
import React, { Component } from 'react';
import { Linking, View } from 'react-native';
import { WebView } from 'react-native-webview';
import { type Dispatch } from 'redux';
import { openDialog } from '../../../../base/dialog';
import { translate } from '../../../../base/i18n';
2020-04-06 15:25:30 +00:00
import { JitsiModal, setActiveModalId } from '../../../../base/modal';
import { LoadingIndicator } from '../../../../base/react';
2019-05-07 14:50:57 +00:00
import { connect } from '../../../../base/redux';
2020-04-06 15:25:30 +00:00
import { DIAL_IN_SUMMARY_VIEW_ID } from '../../../constants';
2019-05-07 14:50:57 +00:00
import { getDialInfoPageURLForURIString } from '../../../functions';
import DialInSummaryErrorDialog from './DialInSummaryErrorDialog';
import styles, { INDICATOR_COLOR } from './styles';
type Props = {
/**
* The URL to display the summary for.
*/
_summaryUrl: ?string,
dispatch: Dispatch<any>
};
/**
* Implements a React native component that displays the dial in info page for a specific room.
*/
class DialInSummary extends Component<Props> {
/**
* Initializes a new instance.
*
* @inheritdoc
*/
constructor(props: Props) {
super(props);
this._onError = this._onError.bind(this);
this._onNavigate = this._onNavigate.bind(this);
this._renderLoading = this._renderLoading.bind(this);
}
/**
* Implements React's {@link Component#render()}.
*
* @inheritdoc
*/
render() {
const { _summaryUrl } = this.props;
return (
2020-04-06 15:25:30 +00:00
<JitsiModal
headerProps = {{
headerLabelKey: 'info.label'
}}
modalId = { DIAL_IN_SUMMARY_VIEW_ID }
style = { styles.backDrop } >
<WebView
onError = { this._onError }
onShouldStartLoadWithRequest = { this._onNavigate }
renderLoading = { this._renderLoading }
source = {{ uri: getDialInfoPageURLForURIString(_summaryUrl) }}
startInLoadingState = { true }
style = { styles.webView } />
</JitsiModal>
2019-05-07 14:50:57 +00:00
);
}
_onError: () => void;
/**
* Callback to handle the error if the page fails to load.
*
* @returns {void}
*/
_onError() {
2020-04-06 15:25:30 +00:00
this.props.dispatch(setActiveModalId());
2019-05-07 14:50:57 +00:00
this.props.dispatch(openDialog(DialInSummaryErrorDialog));
}
_onNavigate: Object => Boolean;
/**
* Callback to intercept navigation inside the webview and make the native app handle the dial requests.
*
* NOTE: We don't navigate to anywhere else form that view.
*
* @param {any} request - The request object.
* @returns {boolean}
*/
_onNavigate(request) {
const { url } = request;
if (url.startsWith('tel:')) {
Linking.openURL(url);
2020-04-06 15:25:30 +00:00
this.props.dispatch(setActiveModalId());
2019-05-07 14:50:57 +00:00
}
return url === getDialInfoPageURLForURIString(this.props._summaryUrl);
}
_renderLoading: () => React$Component<any>;
/**
* Renders the loading indicator.
*
* @returns {React$Component<any>}
*/
_renderLoading() {
return (
<View style = { styles.indicatorWrapper }>
<LoadingIndicator
color = { INDICATOR_COLOR }
size = 'large' />
</View>
);
}
}
/**
* Maps part of the Redux state to the props of this component.
*
* @param {Object} state - The Redux state.
* @returns {{
* _summaryUrl: ?string
* }}
*/
function _mapStateToProps(state) {
return {
2020-04-06 15:25:30 +00:00
_summaryUrl: (state['features/base/modal'].modalProps || {}).summaryUrl
2019-05-07 14:50:57 +00:00
};
}
export default translate(connect(_mapStateToProps)(DialInSummary));