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';
|
2019-08-30 16:39:06 +00:00
|
|
|
import { Icon, IconClose } from '../../../base/icons';
|
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';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a React {@link Component} to display a notification.
|
|
|
|
*
|
|
|
|
* @extends Component
|
|
|
|
*/
|
|
|
|
class Notification extends AbstractNotification<Props> {
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
isDismissAllowed
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View
|
|
|
|
pointerEvents = 'box-none'
|
|
|
|
style = { styles.notification }>
|
|
|
|
<View style = { styles.contentColumn }>
|
|
|
|
<View
|
|
|
|
pointerEvents = 'box-none'
|
|
|
|
style = { styles.notificationContent }>
|
|
|
|
{
|
|
|
|
this._renderContent()
|
|
|
|
}
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
{
|
|
|
|
isDismissAllowed
|
|
|
|
&& <TouchableOpacity onPress = { this._onDismissed }>
|
|
|
|
<Icon
|
2019-08-30 16:39:06 +00:00
|
|
|
src = { IconClose }
|
2019-03-20 20:09:23 +00:00
|
|
|
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 { t, title, titleArguments, titleKey } = this.props;
|
|
|
|
const titleText = title || (titleKey && t(titleKey, titleArguments));
|
2019-08-02 12:30:38 +00:00
|
|
|
const description = this._getDescription();
|
2019-03-20 20:09:23 +00:00
|
|
|
|
2019-08-02 12:30:38 +00:00
|
|
|
if (description && description.length) {
|
|
|
|
return description.map((line, index) => (
|
2019-03-20 20:09:23 +00:00
|
|
|
<Text
|
2019-08-02 12:30:38 +00:00
|
|
|
key = { index }
|
2019-03-20 20:09:23 +00:00
|
|
|
numberOfLines = { 1 }
|
2019-08-02 12:30:38 +00:00
|
|
|
style = { styles.contentText }>
|
|
|
|
{ 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
|
|
|
|
numberOfLines = { 1 }
|
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);
|