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

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