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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // @flow
  2. import React from 'react';
  3. import { Text, TouchableOpacity, View } from 'react-native';
  4. import { Icon } from '../../../base/font-icons';
  5. import { translate } from '../../../base/i18n';
  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. name = { 'close' }
  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. if (titleText) {
  61. return (
  62. <Text
  63. numberOfLines = { 1 }
  64. style = { styles.contentText } >
  65. { titleText }
  66. </Text>
  67. );
  68. }
  69. return this._getDescription().map((line, index) => (
  70. <Text
  71. key = { index }
  72. numberOfLines = { 1 }
  73. style = { styles.contentText }>
  74. { line }
  75. </Text>
  76. ));
  77. }
  78. _getDescription: () => Array<string>;
  79. _onDismissed: () => void;
  80. }
  81. export default translate(Notification);