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

AlertDialog.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import React from 'react';
  2. import Dialog from 'react-native-dialog';
  3. import { translate } from '../../../i18n';
  4. import { connect } from '../../../redux';
  5. import { _abstractMapStateToProps } from '../../functions';
  6. import AbstractDialog, { type Props as AbstractProps } from '../AbstractDialog';
  7. import { renderHTML } from '../functions.native';
  8. type Props = AbstractProps & {
  9. /**
  10. * Untranslated i18n key of the content to be displayed.
  11. *
  12. * NOTE: This dialog also adds support to Object type keys that will be
  13. * translated using the provided params. See i18n function
  14. * {@code translate(string, Object)} for more details.
  15. */
  16. contentKey: string | { key: string, params: Object},
  17. /**
  18. * Translation function.
  19. */
  20. t: Function
  21. };
  22. /**
  23. * Implements an alert dialog, to simply show an error or a message,
  24. * then disappear on dismiss.
  25. */
  26. class AlertDialog extends AbstractDialog<Props> {
  27. /**
  28. * Implements React's {@link Component#render}.
  29. *
  30. * @inheritdoc
  31. */
  32. render() {
  33. const { contentKey, t } = this.props;
  34. const content
  35. = typeof contentKey === 'string'
  36. ? t(contentKey)
  37. : renderHTML(t(contentKey.key, contentKey.params));
  38. return (
  39. <Dialog.Container
  40. coverScreen = { false }
  41. visible = { true }>
  42. <Dialog.Description>
  43. { content }
  44. </Dialog.Description>
  45. <Dialog.Button
  46. label = { t('dialog.Ok') }
  47. onPress = { this._onSubmit } />
  48. </Dialog.Container>
  49. );
  50. }
  51. _onSubmit: () => boolean;
  52. }
  53. export default translate(connect(_abstractMapStateToProps)(AlertDialog));