您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Notification.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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, concatText } = this.props;
  63. const titleText = title || (titleKey && t(titleKey, titleArguments));
  64. const description = this._getDescription();
  65. const titleConcat = [];
  66. if (concatText) {
  67. titleConcat.push(titleText);
  68. }
  69. if (description && description.length) {
  70. return [ ...titleConcat, ...description ].map((line, index) => (
  71. <Text
  72. key = { index }
  73. numberOfLines = { maxLines }
  74. style = { styles.contentText }>
  75. { line }
  76. </Text>
  77. ));
  78. }
  79. return (
  80. <Text
  81. numberOfLines = { maxLines }
  82. style = { styles.contentText } >
  83. { titleText }
  84. </Text>
  85. );
  86. }
  87. _getDescription: () => Array<string>;
  88. _onDismissed: () => void;
  89. }
  90. export default translate(Notification);