2019-03-20 20:09:23 +00:00
|
|
|
// @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';
|
2022-11-08 10:24:32 +00:00
|
|
|
import { Icon, IconCloseLarge } from '../../../base/icons';
|
2021-12-17 12:39:15 +00:00
|
|
|
import { replaceNonUnicodeEmojis } from '../../../chat/functions';
|
2019-03-20 20:09:23 +00:00
|
|
|
import AbstractNotification, {
|
|
|
|
type Props
|
2019-03-27 14:00:10 +00:00
|
|
|
} from '../AbstractNotification';
|
|
|
|
|
2019-03-20 20:09:23 +00:00
|
|
|
import styles from './styles';
|
|
|
|
|
2020-05-28 22:42:02 +00:00
|
|
|
/**
|
|
|
|
* Default value for the maxLines prop.
|
|
|
|
*
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2022-05-16 12:12:33 +00:00
|
|
|
const DEFAULT_MAX_LINES = 2;
|
2020-05-28 22:42:02 +00:00
|
|
|
|
2019-03-20 20:09:23 +00:00
|
|
|
/**
|
|
|
|
* Implements a React {@link Component} to display a notification.
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @augments Component
|
2019-03-20 20:09:23 +00:00
|
|
|
*/
|
|
|
|
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>
|
2022-05-06 10:43:27 +00:00
|
|
|
<TouchableOpacity onPress = { this._onDismissed }>
|
|
|
|
<Icon
|
2022-11-08 10:24:32 +00:00
|
|
|
src = { IconCloseLarge }
|
2022-05-06 10:43:27 +00:00
|
|
|
style = { styles.dismissIcon } />
|
|
|
|
</TouchableOpacity>
|
2019-03-20 20:09:23 +00:00
|
|
|
</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() {
|
2021-09-22 14:05:42 +00:00
|
|
|
const { maxLines = DEFAULT_MAX_LINES, t, title, titleArguments, titleKey, concatText } = this.props;
|
2019-03-20 20:09:23 +00:00
|
|
|
const titleText = title || (titleKey && t(titleKey, titleArguments));
|
2019-08-02 12:30:38 +00:00
|
|
|
const description = this._getDescription();
|
2021-09-22 14:05:42 +00:00
|
|
|
const titleConcat = [];
|
|
|
|
|
|
|
|
if (concatText) {
|
|
|
|
titleConcat.push(titleText);
|
|
|
|
}
|
2019-03-20 20:09:23 +00:00
|
|
|
|
2019-08-02 12:30:38 +00:00
|
|
|
if (description && description.length) {
|
2021-09-22 14:05:42 +00:00
|
|
|
return [ ...titleConcat, ...description ].map((line, index) => (
|
2019-03-20 20:09:23 +00:00
|
|
|
<Text
|
2019-08-02 12:30:38 +00:00
|
|
|
key = { index }
|
2020-05-28 22:42:02 +00:00
|
|
|
numberOfLines = { maxLines }
|
2019-08-02 12:30:38 +00:00
|
|
|
style = { styles.contentText }>
|
2021-12-17 12:39:15 +00:00
|
|
|
{ replaceNonUnicodeEmojis(line) }
|
2019-03-20 20:09:23 +00:00
|
|
|
</Text>
|
2019-08-02 12:30:38 +00:00
|
|
|
));
|
2019-03-20 20:09:23 +00:00
|
|
|
}
|
|
|
|
|
2019-08-02 12:30:38 +00:00
|
|
|
return (
|
2019-03-20 20:09:23 +00:00
|
|
|
<Text
|
2020-05-28 22:42:02 +00:00
|
|
|
numberOfLines = { maxLines }
|
2019-08-02 12:30:38 +00:00
|
|
|
style = { styles.contentText } >
|
|
|
|
{ titleText }
|
2019-03-20 20:09:23 +00:00
|
|
|
</Text>
|
2019-08-02 12:30:38 +00:00
|
|
|
);
|
2019-03-20 20:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_getDescription: () => Array<string>;
|
|
|
|
|
|
|
|
_onDismissed: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(Notification);
|