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.native.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. this._getDescription().map((line, index) => (
  72. <Text
  73. key = { index }
  74. style = { styles.contentText }>
  75. { line }
  76. </Text>
  77. ))
  78. }
  79. </View>
  80. </View>
  81. {
  82. isDismissAllowed
  83. && <View style = { styles.actionColumn }>
  84. <TouchableOpacity onPress = { this._onDismissed }>
  85. <Icon
  86. name = { 'close' }
  87. style = { styles.dismissIcon } />
  88. </TouchableOpacity>
  89. </View>
  90. }
  91. </View>
  92. );
  93. }
  94. _getDescription: () => Array<string>;
  95. _onDismissed: () => void;
  96. }
  97. export default translate(Notification);