Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Notification.js 2.9KB

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