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.

AlertDialog.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // @flow
  2. import React from 'react';
  3. import { Text } from 'react-native';
  4. import { translate } from '../../../i18n';
  5. import { connect } from '../../../redux';
  6. import { _abstractMapStateToProps } from '../../functions';
  7. import { type Props as AbstractProps } from './BaseDialog';
  8. import BaseSubmitDialog from './BaseSubmitDialog';
  9. type Props = AbstractProps & {
  10. /**
  11. * Untranslated i18n key of the content to be displayed.
  12. *
  13. * NOTE: This dialog also adds support to Object type keys that will be
  14. * translated using the provided params. See i18n function
  15. * {@code translate(string, Object)} for more details.
  16. */
  17. contentKey: string | { key: string, params: Object},
  18. };
  19. /**
  20. * Implements an alert dialog, to simply show an error or a message, then disappear on dismiss.
  21. */
  22. class AlertDialog extends BaseSubmitDialog<Props, *> {
  23. /**
  24. * Implements {@code BaseSubmitDialog._renderSubmittable}.
  25. *
  26. * @inheritdoc
  27. */
  28. _renderSubmittable() {
  29. const { _dialogStyles, contentKey, t } = this.props;
  30. const content
  31. = typeof contentKey === 'string'
  32. ? t(contentKey)
  33. : this._renderHTML(t(contentKey.key, contentKey.params));
  34. return (
  35. <Text style = { _dialogStyles.text }>
  36. { content }
  37. </Text>
  38. );
  39. }
  40. _renderHTML: string => Object | string
  41. }
  42. export default translate(connect(_abstractMapStateToProps)(AlertDialog));