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

148 lines
3.8 KiB
JavaScript
Raw Normal View History

2019-05-07 14:50:57 +00:00
// @flow
import React, { PureComponent } from 'react';
import { Linking, View } from 'react-native';
2019-05-07 14:50:57 +00:00
import { WebView } from 'react-native-webview';
import { type Dispatch } from 'redux';
import { openDialog } from '../../../../base/dialog';
import { translate } from '../../../../base/i18n';
import JitsiScreen from '../../../../base/modal/components/JitsiScreen';
2020-04-06 15:25:30 +00:00
import { LoadingIndicator } from '../../../../base/react';
2019-05-07 14:50:57 +00:00
import { connect } from '../../../../base/redux';
import { getDialInfoPageURLForURIString } from '../../../functions';
import DialInSummaryErrorDialog from './DialInSummaryErrorDialog';
import styles, { INDICATOR_COLOR } from './styles';
2019-05-07 14:50:57 +00:00
type Props = {
dispatch: Dispatch<any>,
2019-05-07 14:50:57 +00:00
/**
* Default prop for navigating between screen components(React Navigation).
2019-05-07 14:50:57 +00:00
*/
navigation: Object,
2019-05-07 14:50:57 +00:00
/**
* Default prop for navigating between screen components(React Navigation).
*/
route: Object,
/**
* Translation function.
*/
t: Function
2019-05-07 14:50:57 +00:00
};
/**
* Implements a React native component that displays the dial in info page for a specific room.
*/
class DialInSummary extends PureComponent<Props> {
2019-05-07 14:50:57 +00:00
/**
* 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#componentDidMount()}. Invoked
* immediately after mounting occurs.
*
* @inheritdoc
* @returns {void}
*/
componentDidMount() {
const { navigation, t } = this.props;
navigation.setOptions({
headerTitle: t('dialIn.screenTitle')
});
}
2019-05-07 14:50:57 +00:00
/**
* Implements React's {@link Component#render()}.
*
* @inheritdoc
*/
render() {
const { route } = this.props;
const summaryUrl = route.params?.summaryUrl;
2019-05-07 14:50:57 +00:00
return (
<JitsiScreen
style = { styles.backDrop }>
2020-04-06 15:25:30 +00:00
<WebView
onError = { this._onError }
onShouldStartLoadWithRequest = { this._onNavigate }
renderLoading = { this._renderLoading }
setSupportMultipleWindows = { false }
source = {{ uri: getDialInfoPageURLForURIString(summaryUrl) }}
2020-04-06 15:25:30 +00:00
startInLoadingState = { true }
style = { styles.webView } />
</JitsiScreen>
2019-05-07 14:50:57 +00:00
);
}
_onError: () => void;
/**
* Callback to handle the error if the page fails to load.
*
* @returns {void}
*/
_onError() {
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;
const { route } = this.props;
const summaryUrl = route.params?.summaryUrl;
2019-05-07 14:50:57 +00:00
if (url.startsWith('tel:')) {
Linking.openURL(url);
}
return url === getDialInfoPageURLForURIString(summaryUrl);
2019-05-07 14:50:57 +00:00
}
_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>
);
}
}
export default translate(connect()(DialInSummary));