You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Notification.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // @flow
  2. import React from 'react';
  3. import { Text, TouchableOpacity, View } from 'react-native';
  4. import { translate } from '../../../base/i18n';
  5. import { Icon, IconClose } from '../../../base/icons';
  6. import AbstractNotification, {
  7. type Props
  8. } from '../AbstractNotification';
  9. import styles from './styles';
  10. /**
  11. * Implements a React {@link Component} to display a notification.
  12. *
  13. * @extends Component
  14. */
  15. class Notification extends AbstractNotification<Props> {
  16. /**
  17. * Implements React's {@link Component#render()}.
  18. *
  19. * @inheritdoc
  20. * @returns {ReactElement}
  21. */
  22. render() {
  23. const {
  24. isDismissAllowed
  25. } = this.props;
  26. return (
  27. <View
  28. pointerEvents = 'box-none'
  29. style = { styles.notification }>
  30. <View style = { styles.contentColumn }>
  31. <View
  32. pointerEvents = 'box-none'
  33. style = { styles.notificationContent }>
  34. {
  35. this._renderContent()
  36. }
  37. </View>
  38. </View>
  39. {
  40. isDismissAllowed
  41. && <TouchableOpacity onPress = { this._onDismissed }>
  42. <Icon
  43. src = { IconClose }
  44. style = { styles.dismissIcon } />
  45. </TouchableOpacity>
  46. }
  47. </View>
  48. );
  49. }
  50. /**
  51. * Renders the notification's content. If the title or title key is present
  52. * it will be just the title. Otherwise it will fallback to description.
  53. *
  54. * @returns {Array<ReactElement>}
  55. * @private
  56. */
  57. _renderContent() {
  58. const { t, title, titleArguments, titleKey } = this.props;
  59. const titleText = title || (titleKey && t(titleKey, titleArguments));
  60. const description = this._getDescription();
  61. if (description && description.length) {
  62. return description.map((line, index) => (
  63. <Text
  64. key = { index }
  65. numberOfLines = { 1 }
  66. style = { styles.contentText }>
  67. { line }
  68. </Text>
  69. ));
  70. }
  71. return (
  72. <Text
  73. numberOfLines = { 1 }
  74. style = { styles.contentText } >
  75. { titleText }
  76. </Text>
  77. );
  78. }
  79. _getDescription: () => Array<string>;
  80. _onDismissed: () => void;
  81. }
  82. export default translate(Notification);