Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ConfirmDialog.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // @flow
  2. import React from 'react';
  3. import { Text, TouchableOpacity } from 'react-native';
  4. import { connect } from 'react-redux';
  5. import { translate } from '../../../i18n';
  6. import { type Props as BaseProps } from './BaseDialog';
  7. import BaseSubmitDialog from './BaseSubmitDialog';
  8. import { brandedDialog } from './styles';
  9. type Props = {
  10. ...BaseProps,
  11. /**
  12. * Untranslated i18n key of the content to be displayed.
  13. *
  14. * NOTE: This dialog also adds support to Object type keys that will be
  15. * translated using the provided params. See i18n function
  16. * {@code translate(string, Object)} for more details.
  17. */
  18. contentKey: string | { key: string, params: Object},
  19. t: Function
  20. }
  21. /**
  22. * Implements a confirm dialog component.
  23. */
  24. class ConfirmDialog extends BaseSubmitDialog<Props, *> {
  25. /**
  26. * Returns the title key of the submit button.
  27. *
  28. * @returns {string}
  29. */
  30. _getSubmitButtonKey() {
  31. return 'dialog.confirmYes';
  32. }
  33. _onCancel: () => void;
  34. /**
  35. * Renders the 'No' button.
  36. *
  37. * NOTE: The {@code ConfirmDialog} is the only dialog right now that
  38. * renders 2 buttons, mainly for clarity.
  39. *
  40. * @inheritdoc
  41. */
  42. _renderAdditionalButtons() {
  43. const { t } = this.props;
  44. return (
  45. <TouchableOpacity
  46. onPress = { this._onCancel }
  47. style = { [
  48. brandedDialog.button,
  49. brandedDialog.buttonFarLeft,
  50. brandedDialog.buttonSeparator
  51. ] }>
  52. <Text style = { brandedDialog.text }>
  53. { t('dialog.confirmNo') }
  54. </Text>
  55. </TouchableOpacity>
  56. );
  57. }
  58. /**
  59. * Implements {@code BaseSubmitDialog._renderSubmittable}.
  60. *
  61. * @inheritdoc
  62. */
  63. _renderSubmittable() {
  64. const { contentKey, t } = this.props;
  65. const content
  66. = typeof contentKey === 'string'
  67. ? t(contentKey)
  68. : this._renderHTML(t(contentKey.key, contentKey.params));
  69. return (
  70. <Text style = { brandedDialog.text }>
  71. { content }
  72. </Text>
  73. );
  74. }
  75. _renderHTML: string => Object | string
  76. }
  77. export default translate(connect()(ConfirmDialog));