Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Notification.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // @flow
  2. import React from 'react';
  3. import { Text, TouchableOpacity, View } from 'react-native';
  4. import { translate } from '../../../base/i18n';
  5. import { Icon, IconCloseLarge } 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 = 2;
  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. 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. <TouchableOpacity onPress = { this._onDismissed }>
  44. <Icon
  45. src = { IconCloseLarge }
  46. style = { styles.dismissIcon } />
  47. </TouchableOpacity>
  48. </View>
  49. );
  50. }
  51. /**
  52. * Renders the notification's content. If the title or title key is present
  53. * it will be just the title. Otherwise it will fallback to description.
  54. *
  55. * @returns {Array<ReactElement>}
  56. * @private
  57. */
  58. _renderContent() {
  59. const { maxLines = DEFAULT_MAX_LINES, t, title, titleArguments, titleKey, concatText } = this.props;
  60. const titleText = title || (titleKey && t(titleKey, titleArguments));
  61. const description = this._getDescription();
  62. const titleConcat = [];
  63. if (concatText) {
  64. titleConcat.push(titleText);
  65. }
  66. if (description && description.length) {
  67. return [ ...titleConcat, ...description ].map((line, index) => (
  68. <Text
  69. key = { index }
  70. numberOfLines = { maxLines }
  71. style = { styles.contentText }>
  72. { replaceNonUnicodeEmojis(line) }
  73. </Text>
  74. ));
  75. }
  76. return (
  77. <Text
  78. numberOfLines = { maxLines }
  79. style = { styles.contentText } >
  80. { titleText }
  81. </Text>
  82. );
  83. }
  84. _getDescription: () => Array<string>;
  85. _onDismissed: () => void;
  86. }
  87. export default translate(Notification);