jiti-meet/react/features/notifications/components/native/Notification.js

100 lines
2.8 KiB
JavaScript
Raw Normal View History

// @flow
import React from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
2019-03-27 14:00:10 +00:00
import { translate } from '../../../base/i18n';
2019-08-30 16:39:06 +00:00
import { Icon, IconClose } from '../../../base/icons';
import { replaceNonUnicodeEmojis } from '../../../chat/functions';
import AbstractNotification, {
type Props
2019-03-27 14:00:10 +00:00
} from '../AbstractNotification';
import styles from './styles';
2020-05-28 22:42:02 +00:00
/**
* Default value for the maxLines prop.
*
* @type {number}
*/
const DEFAULT_MAX_LINES = 2;
2020-05-28 22:42:02 +00:00
/**
* Implements a React {@link Component} to display a notification.
*
2021-11-04 21:10:43 +00:00
* @augments Component
*/
class Notification extends AbstractNotification<Props> {
/**
* Implements React's {@link Component#render()}.
*
* @inheritdoc
* @returns {ReactElement}
*/
render() {
return (
<View
pointerEvents = 'box-none'
style = { styles.notification }>
<View style = { styles.contentColumn }>
<View
pointerEvents = 'box-none'
style = { styles.notificationContent }>
{
this._renderContent()
}
</View>
</View>
<TouchableOpacity onPress = { this._onDismissed }>
<Icon
src = { IconClose }
style = { styles.dismissIcon } />
</TouchableOpacity>
</View>
);
}
/**
* Renders the notification's content. If the title or title key is present
* it will be just the title. Otherwise it will fallback to description.
*
* @returns {Array<ReactElement>}
* @private
*/
_renderContent() {
const { maxLines = DEFAULT_MAX_LINES, t, title, titleArguments, titleKey, concatText } = this.props;
const titleText = title || (titleKey && t(titleKey, titleArguments));
const description = this._getDescription();
const titleConcat = [];
if (concatText) {
titleConcat.push(titleText);
}
if (description && description.length) {
return [ ...titleConcat, ...description ].map((line, index) => (
<Text
key = { index }
2020-05-28 22:42:02 +00:00
numberOfLines = { maxLines }
style = { styles.contentText }>
{ replaceNonUnicodeEmojis(line) }
</Text>
));
}
return (
<Text
2020-05-28 22:42:02 +00:00
numberOfLines = { maxLines }
style = { styles.contentText } >
{ titleText }
</Text>
);
}
_getDescription: () => Array<string>;
_onDismissed: () => void;
}
export default translate(Notification);