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

ConfirmDialog.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import React from 'react';
  2. import Dialog from 'react-native-dialog';
  3. import { translate } from '../../../i18n';
  4. import { connect } from '../../../redux';
  5. import AbstractDialog from '../AbstractDialog';
  6. import { renderHTML } from '../functions.native';
  7. import styles from './styles';
  8. /**
  9. * The type of the React {@code Component} props of
  10. * {@link ConfirmDialog}.
  11. */
  12. type Props = {
  13. /**
  14. * The i18n key of the text label for the cancel button.
  15. */
  16. cancelLabel: string,
  17. /**
  18. * The React {@code Component} children.
  19. */
  20. children?: Node,
  21. /**
  22. * The i18n key of the text label for the confirm button.
  23. */
  24. confirmLabel: string,
  25. /**
  26. * Dialog description key for translations.
  27. */
  28. descriptionKey?: string | Object,
  29. /**
  30. * Whether or not the nature of the confirm button is destructive.
  31. */
  32. isConfirmDestructive?: Boolean,
  33. /**
  34. * Invoked to obtain translated strings.
  35. */
  36. t: Function,
  37. /**
  38. * Dialog title.
  39. */
  40. title?: string
  41. };
  42. /**
  43. * React Component for getting confirmation to stop a file recording session in
  44. * progress.
  45. *
  46. * @augments Component
  47. */
  48. class ConfirmDialog extends AbstractDialog<Props> {
  49. /**
  50. * Default values for {@code ConfirmDialog} component's properties.
  51. *
  52. * @static
  53. */
  54. static defaultProps = {
  55. isConfirmDestructive: false
  56. };
  57. /**
  58. * Renders the dialog description.
  59. *
  60. * @returns {React$Component}
  61. */
  62. _renderDescription() {
  63. const { descriptionKey, t } = this.props;
  64. const description
  65. = typeof descriptionKey === 'string'
  66. ? t(descriptionKey)
  67. : renderHTML(
  68. t(descriptionKey?.key, descriptionKey?.params)
  69. );
  70. return (
  71. <Dialog.Description>
  72. { description }
  73. </Dialog.Description>
  74. );
  75. }
  76. /**
  77. * Implements {@code Component#render}.
  78. *
  79. * @inheritdoc
  80. */
  81. render() {
  82. const {
  83. cancelLabel,
  84. children,
  85. confirmLabel,
  86. isConfirmDestructive,
  87. t,
  88. title
  89. } = this.props;
  90. const dialogButtonStyle
  91. = isConfirmDestructive
  92. ? styles.destructiveDialogButton : styles.dialogButton;
  93. return (
  94. <Dialog.Container
  95. coverScreen = { false }
  96. visible = { true }>
  97. {
  98. title && <Dialog.Title>
  99. { t(title) }
  100. </Dialog.Title>
  101. }
  102. { this._renderDescription() }
  103. { children }
  104. <Dialog.Button
  105. label = { t(cancelLabel || 'dialog.confirmNo') }
  106. onPress = { this._onCancel }
  107. style = { styles.dialogButton } />
  108. <Dialog.Button
  109. label = { t(confirmLabel || 'dialog.confirmYes') }
  110. onPress = { this._onSubmit }
  111. style = { dialogButtonStyle } />
  112. </Dialog.Container>
  113. );
  114. }
  115. _onCancel: () => void;
  116. _onSubmit: (?string) => void;
  117. }
  118. export default translate(connect()(ConfirmDialog));