rn: add generic alert dialog
This commit is contained in:
parent
3eca67e1ad
commit
7e9df74e60
|
@ -0,0 +1,52 @@
|
||||||
|
// @flow
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
import { Text } from 'react-native';
|
||||||
|
|
||||||
|
import { translate } from '../../../i18n';
|
||||||
|
import { connect } from '../../../redux';
|
||||||
|
|
||||||
|
import { _abstractMapStateToProps } from '../../functions';
|
||||||
|
|
||||||
|
import { type Props as AbstractProps } from './BaseDialog';
|
||||||
|
import BaseSubmitDialog from './BaseSubmitDialog';
|
||||||
|
|
||||||
|
type Props = AbstractProps & {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Untranslated i18n key of the content to be displayed.
|
||||||
|
*
|
||||||
|
* NOTE: This dialog also adds support to Object type keys that will be
|
||||||
|
* translated using the provided params. See i18n function
|
||||||
|
* {@code translate(string, Object)} for more details.
|
||||||
|
*/
|
||||||
|
contentKey: string | { key: string, params: Object},
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements an alert dialog, to simply show an error or a message, then disappear on dismiss.
|
||||||
|
*/
|
||||||
|
class AlertDialog extends BaseSubmitDialog<Props, *> {
|
||||||
|
/**
|
||||||
|
* Implements {@code BaseSubmitDialog._renderSubmittable}.
|
||||||
|
*
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
_renderSubmittable() {
|
||||||
|
const { _dialogStyles, contentKey, t } = this.props;
|
||||||
|
const content
|
||||||
|
= typeof contentKey === 'string'
|
||||||
|
? t(contentKey)
|
||||||
|
: this._renderHTML(t(contentKey.key, contentKey.params));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Text style = { _dialogStyles.text }>
|
||||||
|
{ content }
|
||||||
|
</Text>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_renderHTML: string => Object | string
|
||||||
|
}
|
||||||
|
|
||||||
|
export default translate(connect(_abstractMapStateToProps)(AlertDialog));
|
|
@ -4,6 +4,7 @@ export { default as BottomSheet } from './BottomSheet';
|
||||||
export { default as ConfirmDialog } from './ConfirmDialog';
|
export { default as ConfirmDialog } from './ConfirmDialog';
|
||||||
export { default as CustomDialog } from './CustomDialog';
|
export { default as CustomDialog } from './CustomDialog';
|
||||||
export { default as DialogContainer } from './DialogContainer';
|
export { default as DialogContainer } from './DialogContainer';
|
||||||
|
export { default as AlertDialog } from './AlertDialog';
|
||||||
export { default as InputDialog } from './InputDialog';
|
export { default as InputDialog } from './InputDialog';
|
||||||
export { default as CustomSubmitDialog } from './CustomSubmitDialog';
|
export { default as CustomSubmitDialog } from './CustomSubmitDialog';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue