jiti-meet/react/features/base/dialog/components/native/BaseDialog.js

148 lines
4.1 KiB
JavaScript
Raw Normal View History

2018-10-18 08:28:08 +00:00
// @flow
import React from 'react';
import {
KeyboardAvoidingView,
2018-10-18 08:28:08 +00:00
Text,
TouchableOpacity,
2019-07-10 12:39:05 +00:00
TouchableWithoutFeedback,
2018-10-18 08:28:08 +00:00
View
} from 'react-native';
2019-08-30 16:39:06 +00:00
import { Icon, IconClose } from '../../../icons';
import { StyleType } from '../../../styles';
2018-10-18 08:28:08 +00:00
import AbstractDialog, {
type Props as AbstractProps,
type State
} from '../AbstractDialog';
2020-05-20 10:57:03 +00:00
2018-10-18 08:28:08 +00:00
import { brandedDialog as styles } from './styles';
2019-03-19 15:42:25 +00:00
export type Props = AbstractProps & {
2018-10-18 08:28:08 +00:00
/**
* The color-schemed stylesheet of the feature.
*/
_dialogStyles: StyleType,
2018-10-18 08:28:08 +00:00
t: Function
}
/**
* Component to render a custom dialog.
*/
class BaseDialog<P: Props, S: State> extends AbstractDialog<P, S> {
/**
* Initializes a new {@code FeedbackDialog} instance.
*
* @inheritdoc
*/
constructor(props: P) {
super(props);
this._onSubmit = this._onSubmit.bind(this);
}
/**
* Implements React's {@link Component#render()}.
*
* @inheritdoc
* @returns {ReactElement}
*/
render() {
const { _dialogStyles, style } = this.props;
2018-10-18 08:28:08 +00:00
return (
2019-07-10 12:39:05 +00:00
<TouchableWithoutFeedback>
<KeyboardAvoidingView
behavior = 'height'
2018-10-18 08:28:08 +00:00
style = { [
styles.overlay
2018-10-18 08:28:08 +00:00
] }>
2019-07-10 12:39:05 +00:00
<View
pointerEvents = 'box-none'
style = { [
_dialogStyles.dialog,
style
2019-07-10 12:39:05 +00:00
] }>
<TouchableOpacity
onPress = { this._onCancel }
style = { styles.closeWrapper }>
<Icon
2019-08-30 16:39:06 +00:00
src = { IconClose }
2019-07-10 12:39:05 +00:00
style = { _dialogStyles.closeStyle } />
</TouchableOpacity>
{ this._renderContent() }
</View>
</KeyboardAvoidingView>
2019-07-10 12:39:05 +00:00
</TouchableWithoutFeedback>
2018-10-18 08:28:08 +00:00
);
}
_onCancel: () => void;
2019-01-10 14:41:54 +00:00
_onSubmit: ?string => boolean;
2018-10-18 08:28:08 +00:00
/**
* Renders the content of the dialog.
*
* @returns {ReactElement}
*/
_renderContent: () => Object
/**
* Renders a specific {@code string} which may contain HTML.
*
* @param {string|undefined} html - The {@code string} which may
* contain HTML to render.
* @returns {ReactElement[]|string}
*/
_renderHTML(html: ?string) {
if (typeof html === 'string') {
// At the time of this writing, the specified HTML contains a couple
// of spaces one after the other. They do not cause a visible
// problem on Web, because the specified HTML is rendered as, well,
// HTML. However, we're not rendering HTML here.
// eslint-disable-next-line no-param-reassign
html = html.replace(/\s{2,}/gi, ' ');
// Render text in <b>text</b> in bold.
const opening = /<\s*b\s*>/gi;
const closing = /<\s*\/\s*b\s*>/gi;
let o;
let c;
let prevClosingLastIndex = 0;
const r = [];
// eslint-disable-next-line no-cond-assign
while (o = opening.exec(html)) {
closing.lastIndex = opening.lastIndex;
// eslint-disable-next-line no-cond-assign
if (c = closing.exec(html)) {
r.push(html.substring(prevClosingLastIndex, o.index));
r.push(
<Text style = { styles.boldDialogText }>
{ html.substring(opening.lastIndex, c.index) }
</Text>);
opening.lastIndex
= prevClosingLastIndex
= closing.lastIndex;
} else {
break;
}
}
if (prevClosingLastIndex < html.length) {
r.push(html.substring(prevClosingLastIndex));
}
return r;
}
return html;
}
}
export default BaseDialog;