Browse Source

rn: add generic alert dialog

master
Bettenbuk Zoltan 6 years ago
parent
commit
7e9df74e60

+ 52
- 0
react/features/base/dialog/components/native/AlertDialog.js View File

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

+ 1
- 0
react/features/base/dialog/components/native/index.js View File

@@ -4,6 +4,7 @@ export { default as BottomSheet } from './BottomSheet';
4 4
 export { default as ConfirmDialog } from './ConfirmDialog';
5 5
 export { default as CustomDialog } from './CustomDialog';
6 6
 export { default as DialogContainer } from './DialogContainer';
7
+export { default as AlertDialog } from './AlertDialog';
7 8
 export { default as InputDialog } from './InputDialog';
8 9
 export { default as CustomSubmitDialog } from './CustomSubmitDialog';
9 10
 

Loading…
Cancel
Save