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

Notification.native.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 { NOTIFICATION_TYPE } from '../constants';
  7. import AbstractNotification, {
  8. type Props
  9. } from './AbstractNotification';
  10. import styles from './styles';
  11. /**
  12. * Implements a React {@link Component} to display a notification.
  13. *
  14. * @extends Component
  15. */
  16. class Notification extends AbstractNotification<Props> {
  17. /**
  18. * Implements React's {@link Component#render()}.
  19. *
  20. * @inheritdoc
  21. * @returns {ReactElement}
  22. */
  23. render() {
  24. const {
  25. appearance,
  26. isDismissAllowed,
  27. t,
  28. title,
  29. titleArguments,
  30. titleKey
  31. } = this.props;
  32. let notificationStyle;
  33. switch (appearance) {
  34. case NOTIFICATION_TYPE.ERROR:
  35. notificationStyle = styles.notificationTypeError;
  36. break;
  37. case NOTIFICATION_TYPE.NORMAL:
  38. notificationStyle = styles.notificationTypeNormal;
  39. break;
  40. case NOTIFICATION_TYPE.SUCCESS:
  41. notificationStyle = styles.notificationTypeSuccess;
  42. break;
  43. case NOTIFICATION_TYPE.WARNING:
  44. notificationStyle = styles.notificationTypeWarning;
  45. break;
  46. case NOTIFICATION_TYPE.INFO:
  47. default:
  48. notificationStyle = styles.notificationTypeInfo;
  49. }
  50. return (
  51. <View
  52. pointerEvents = 'box-none'
  53. style = { [
  54. styles.notification,
  55. notificationStyle
  56. ] }>
  57. <View style = { styles.contentColumn }>
  58. <View
  59. pointerEvents = 'box-none'
  60. style = { styles.notificationTitle }>
  61. <Text style = { styles.titleText }>
  62. {
  63. title || t(titleKey, titleArguments)
  64. }
  65. </Text>
  66. </View>
  67. <View
  68. pointerEvents = 'box-none'
  69. style = { styles.notificationContent }>
  70. {
  71. // eslint-disable-next-line no-extra-parens
  72. this._getDescription().map((line, index) => (
  73. <Text
  74. key = { index }
  75. style = { styles.contentText }>
  76. { line }
  77. </Text>
  78. ))
  79. }
  80. </View>
  81. </View>
  82. {
  83. isDismissAllowed
  84. && <View style = { styles.actionColumn }>
  85. <TouchableOpacity onPress = { this._onDismissed }>
  86. <Icon
  87. name = { 'close' }
  88. style = { styles.dismissIcon } />
  89. </TouchableOpacity>
  90. </View>
  91. }
  92. </View>
  93. );
  94. }
  95. _getDescription: () => Array<string>;
  96. _onDismissed: () => void;
  97. }
  98. export default translate(Notification);