소스 검색

ref: define state and property types (2)

master
Lyubo Marinov 7 년 전
부모
커밋
75bf7638b3

+ 51
- 28
react/features/always-on-top/AlwaysOnTop.js 파일 보기

@@ -1,3 +1,5 @@
1
+// @flow
2
+
1 3
 import React, { Component } from 'react';
2 4
 
3 5
 import StatelessToolbar from '../toolbox/components/StatelessToolbar';
@@ -6,15 +8,10 @@ import StatelessToolbarButton
6 8
 
7 9
 const { api } = window.alwaysOnTop;
8 10
 
9
-/**
10
- * The timeout in ms for hidding the toolbar.
11
- */
12
-const TOOLBAR_TIMEOUT = 4000;
13
-
14 11
 /**
15 12
  * Map with toolbar button descriptors.
16 13
  */
17
-const toolbarButtons = {
14
+const TOOLBAR_BUTTONS = {
18 15
     /**
19 16
      * The descriptor of the camera toolbar button.
20 17
      */
@@ -54,15 +51,20 @@ const toolbarButtons = {
54 51
 };
55 52
 
56 53
 /**
57
- * Defines the state for <tt>AlwaysOnTop</tt> component.
54
+ * The timeout in ms for hidding the toolbar.
55
+ */
56
+const TOOLBAR_TIMEOUT = 4000;
57
+
58
+/**
59
+ * The type of the React {@code Component} state of {@link FeedbackButton}.
58 60
  */
59
-type AlwaysOnTopState = {
60
-    visible: boolean,
61
+type State = {
62
+    audioAvailable: boolean,
61 63
     audioMuted: boolean,
64
+    videoAvailable: boolean,
62 65
     videoMuted: boolean,
63
-    audioAvailable: boolean,
64
-    videoAvailable: boolean
65
-}
66
+    visible: boolean
67
+};
66 68
 
67 69
 /**
68 70
  * Represents the always on top page.
@@ -70,14 +72,16 @@ type AlwaysOnTopState = {
70 72
  * @class AlwaysOnTop
71 73
  * @extends Component
72 74
  */
73
-export default class AlwaysOnTop extends Component<*, AlwaysOnTopState> {
75
+export default class AlwaysOnTop extends Component<*, State> {
76
+    _hovered: boolean;
77
+
74 78
     /**
75 79
      * Initializes new AlwaysOnTop instance.
76 80
      *
77
-     * @param {Object} props - The read-only properties with which the new
78
-     * instance is to be initialized.
81
+     * @param {*} props - The read-only properties with which the new instance
82
+     * is to be initialized.
79 83
      */
80
-    constructor(props) {
84
+    constructor(props: *) {
81 85
         super(props);
82 86
 
83 87
         this.state = {
@@ -88,19 +92,20 @@ export default class AlwaysOnTop extends Component<*, AlwaysOnTopState> {
88 92
             videoAvailable: false
89 93
         };
90 94
 
91
-        this._hovered = false;
92
-
95
+        // Bind event handlers so they are only bound once per instance.
93 96
         this._audioAvailabilityListener
94 97
             = this._audioAvailabilityListener.bind(this);
95 98
         this._audioMutedListener = this._audioMutedListener.bind(this);
96 99
         this._mouseMove = this._mouseMove.bind(this);
97
-        this._onMouseOver = this._onMouseOver.bind(this);
98 100
         this._onMouseOut = this._onMouseOut.bind(this);
101
+        this._onMouseOver = this._onMouseOver.bind(this);
99 102
         this._videoAvailabilityListener
100 103
             = this._videoAvailabilityListener.bind(this);
101 104
         this._videoMutedListener = this._videoMutedListener.bind(this);
102 105
     }
103 106
 
107
+    _audioAvailabilityListener: ({ available: boolean }) => void;
108
+
104 109
     /**
105 110
      * Handles audio available api events.
106 111
      *
@@ -111,6 +116,8 @@ export default class AlwaysOnTop extends Component<*, AlwaysOnTopState> {
111 116
         this.setState({ audioAvailable: available });
112 117
     }
113 118
 
119
+    _audioMutedListener: ({ muted: boolean }) => void;
120
+
114 121
     /**
115 122
      * Handles audio muted api events.
116 123
      *
@@ -137,6 +144,8 @@ export default class AlwaysOnTop extends Component<*, AlwaysOnTopState> {
137 144
         }, TOOLBAR_TIMEOUT);
138 145
     }
139 146
 
147
+    _mouseMove: () => void;
148
+
140 149
     /**
141 150
      * Handles mouse move events.
142 151
      *
@@ -148,24 +157,30 @@ export default class AlwaysOnTop extends Component<*, AlwaysOnTopState> {
148 157
         }
149 158
     }
150 159
 
160
+    _onMouseOut: () => void;
161
+
151 162
     /**
152
-     * Toolbar mouse over handler.
163
+     * Toolbar mouse out handler.
153 164
      *
154 165
      * @returns {void}
155 166
      */
156
-    _onMouseOver() {
157
-        this._hovered = true;
167
+    _onMouseOut() {
168
+        this._hovered = false;
158 169
     }
159 170
 
171
+    _onMouseOver: () => void;
172
+
160 173
     /**
161
-     * Toolbar mouse out handler.
174
+     * Toolbar mouse over handler.
162 175
      *
163 176
      * @returns {void}
164 177
      */
165
-    _onMouseOut() {
166
-        this._hovered = false;
178
+    _onMouseOver() {
179
+        this._hovered = true;
167 180
     }
168 181
 
182
+    _videoAvailabilityListener: ({ available: boolean }) => void;
183
+
169 184
     /**
170 185
      * Handles audio available api events.
171 186
      *
@@ -176,6 +191,8 @@ export default class AlwaysOnTop extends Component<*, AlwaysOnTopState> {
176 191
         this.setState({ videoAvailable: available });
177 192
     }
178 193
 
194
+    _videoMutedListener: ({ muted: boolean }) => void;
195
+
179 196
     /**
180 197
      * Handles video muted api events.
181 198
      *
@@ -248,7 +265,7 @@ export default class AlwaysOnTop extends Component<*, AlwaysOnTopState> {
248 265
      * @inheritdoc
249 266
      * @returns {void}
250 267
      */
251
-    componentWillUpdate(nextProps, nextState) {
268
+    componentWillUpdate(nextProps: *, nextState: State) {
252 269
         if (!this.state.visible && nextState.visible) {
253 270
             this._hideToolbarAfterTimeout();
254 271
         }
@@ -271,9 +288,15 @@ export default class AlwaysOnTop extends Component<*, AlwaysOnTopState> {
271 288
                 onMouseOut = { this._onMouseOut }
272 289
                 onMouseOver = { this._onMouseOver }>
273 290
                 {
274
-                    Object.entries(toolbarButtons).map(([ key, button ]) => {
291
+                    Object.entries(TOOLBAR_BUTTONS).map(([ key, button ]) => {
292
+                        // XXX The following silences a couple of flow errors:
293
+                        if (button === null || typeof button !== 'object') {
294
+                            return null;
295
+                        }
296
+
275 297
                         const { onClick } = button;
276
-                        let enabled = false, toggled = false;
298
+                        let enabled = false;
299
+                        let toggled = false;
277 300
 
278 301
                         switch (key) {
279 302
                         case 'microphone':

+ 3
- 0
react/features/authentication/actions.js 파일 보기

@@ -71,6 +71,9 @@ export function authenticateAndUpgradeRole(
71 71
  * }}
72 72
  */
73 73
 export function cancelLogin() {
74
+    // FIXME Like cancelWaitForOwner, dispatch conferenceLeft to notify the
75
+    // external-api.
76
+
74 77
     return {
75 78
         type: CANCEL_LOGIN
76 79
     };

+ 1
- 1
react/features/authentication/components/LoginDialog.native.js 파일 보기

@@ -226,7 +226,7 @@ class LoginDialog extends Component {
226 226
      */
227 227
     _onLogin() {
228 228
         const { _conference: conference, dispatch } = this.props;
229
-        const { username, password } = this.state;
229
+        const { password, username } = this.state;
230 230
         const jid = toJid(username, this.props._configHosts);
231 231
         let r;
232 232
 

+ 4
- 4
react/features/authentication/components/WaitForOwnerDialog.native.js 파일 보기

@@ -11,14 +11,14 @@ import { cancelWaitForOwner, _openLoginDialog } from '../actions';
11 11
 import styles from './styles';
12 12
 
13 13
 /**
14
- * WaitForOwnerDialog component's property types.
14
+ * The type of the React {@code Component} props of {@link WaitForOwnerDialog}.
15 15
  */
16
-type WaitForOwnerDialogPropTypes = {
16
+type Props = {
17 17
 
18 18
     /**
19 19
      * The name of the conference room (without the domain part).
20 20
      */
21
-    _room: String,
21
+    _room: string,
22 22
 
23 23
     /**
24 24
      * Redux store dispatch function.
@@ -37,7 +37,7 @@ type WaitForOwnerDialogPropTypes = {
37 37
  *
38 38
  * See {@link LoginDialog} description for more details.
39 39
  */
40
-class WaitForOwnerDialog extends Component<WaitForOwnerDialogPropTypes> {
40
+class WaitForOwnerDialog extends Component<Props> {
41 41
     /**
42 42
      * Initializes a new WaitForWonderDialog instance.
43 43
      *

+ 4
- 0
react/features/authentication/middleware.js 파일 보기

@@ -59,6 +59,10 @@ MiddlewareRegistry.register(store => next => action => {
59 59
 
60 60
             // Go back to the app's entry point.
61 61
             _hideLoginDialog(store);
62
+
63
+            // FIXME Like cancelWaitForOwner, dispatch conferenceLeft to notify
64
+            // the external-api.
65
+
62 66
             dispatch(appNavigate(undefined));
63 67
         }
64 68
         break;

+ 14
- 23
react/features/base/dialog/components/AbstractDialog.js 파일 보기

@@ -1,45 +1,36 @@
1 1
 // @flow
2 2
 
3
-import * as React from 'react';
3
+import { Component } from 'react';
4 4
 
5 5
 import { hideDialog } from '../actions';
6
-import { DialogPropTypes } from '../constants';
6
+import type { DialogProps } from '../constants';
7 7
 
8 8
 /**
9
- * Defines the property types for AbstractDialog.
9
+ * The type of the React {@code Component} props of {@link AbstractDialog}.
10 10
  */
11
-export type AbstractDialogPropTypes = {
12
-    ...DialogPropTypes,
13
-
14
-    /**
15
-     * The React {@code Component} children of {@code AbstractDialog}
16
-     * which represents the dialog's body.
17
-     */
18
-    children: React.Node,
11
+export type Props = {
12
+    ...DialogProps,
19 13
 
20 14
     /**
21 15
      * Used to show/hide the dialog on cancel.
22 16
      */
23 17
     dispatch: Dispatch<*>
24
-}
18
+};
25 19
 
26 20
 /**
27
- * Defines the state for AbstractDialog.
21
+ * The type of the React {@code Component} state of {@link AbstractDialog}.
28 22
  */
29
-type AbstractDialogState = {
30
-    submitting: boolean
31
-}
23
+export type State = {
24
+    submitting: ?boolean
25
+};
32 26
 
33 27
 /**
34 28
  * An abstract implementation of a dialog on Web/React and mobile/react-native.
35 29
  */
36
-export default class AbstractDialog
37
-    extends React.Component<AbstractDialogPropTypes, AbstractDialogState> {
38
-    _mounted: boolean;
30
+export default class AbstractDialog<P : Props, S : State>
31
+    extends Component<P, S> {
39 32
 
40
-    state = {
41
-        submitting: false
42
-    };
33
+    _mounted: boolean;
43 34
 
44 35
     /**
45 36
      * Initializes a new {@code AbstractDialog} instance.
@@ -47,7 +38,7 @@ export default class AbstractDialog
47 38
      * @param {Object} props - The read-only React {@code Component} props with
48 39
      * which the new instance is to be initialized.
49 40
      */
50
-    constructor(props: Object) {
41
+    constructor(props: P) {
51 42
         super(props);
52 43
 
53 44
         // Bind event handlers so they are only bound once per instance.

+ 54
- 45
react/features/base/dialog/components/Dialog.native.js 파일 보기

@@ -1,3 +1,6 @@
1
+// @flow
2
+
3
+import _ from 'lodash';
1 4
 import React from 'react';
2 5
 import { Modal, StyleSheet, TextInput } from 'react-native';
3 6
 import Prompt from 'react-native-prompt';
@@ -7,7 +10,11 @@ import { translate } from '../../i18n';
7 10
 import { LoadingIndicator } from '../../react';
8 11
 import { set } from '../../redux';
9 12
 
10
-import AbstractDialog, { AbstractDialogPropTypes } from './AbstractDialog';
13
+import AbstractDialog from './AbstractDialog';
14
+import type {
15
+    Props as AbstractDialogProps,
16
+    State as AbstractDialogState
17
+} from './AbstractDialog';
11 18
 import { dialog as styles } from './styles';
12 19
 
13 20
 /**
@@ -27,21 +34,24 @@ const _SUBMIT_TEXT_TAG_VALUE = '_SUBMIT_TEXT_TAG_VALUE';
27 34
 const _TAG_KEY = '_TAG_KEY';
28 35
 
29 36
 /**
30
- * {@code Dialog}'s React {@code Component} prop types.
37
+ * The type of the React {@code Component} props of {@link Dialog}.
31 38
  */
32
-type DialogPropTypes = {
33
-    ...AbstractDialogPropTypes,
39
+type Props = {
40
+    ...AbstractDialogProps,
34 41
 
35 42
     /**
36 43
      * I18n key to put as body title.
37 44
      */
38
-    bodyKey: String
39
-}
45
+    bodyKey: String,
46
+
47
+    textInputProps: Object
48
+};
40 49
 
41 50
 /**
42
- * Defines {@code Dialog}'s state.
51
+ * The type of the React {@code Component} state of {@link Dialog}.
43 52
  */
44
-type DialogState = {
53
+type State = {
54
+    ...AbstractDialogState,
45 55
 
46 56
     /**
47 57
      * The text of the {@link TextInput} rendered by {@link Prompt} in
@@ -50,18 +60,13 @@ type DialogState = {
50 60
      * functionality of {@code Prompt} because this {@code Dialog} does not
51 61
      * really render the (whole) {@code Prompt}.
52 62
      */
53
-    text: String
54
-}
63
+    text: string
64
+};
55 65
 
56 66
 /**
57 67
  * Implements {@code AbstractDialog} on react-native using {@code Prompt}.
58 68
  */
59
-class Dialog extends AbstractDialog<DialogPropTypes, DialogState> {
60
-
61
-    state = {
62
-        text: ''
63
-    };
64
-
69
+class Dialog extends AbstractDialog<Props, State> {
65 70
     /**
66 71
      * Initailizes a new {@code Dialog} instance.
67 72
      *
@@ -71,6 +76,8 @@ class Dialog extends AbstractDialog<DialogPropTypes, DialogState> {
71 76
     constructor(props: Object) {
72 77
         super(props);
73 78
 
79
+        this.state.text = '';
80
+
74 81
         // Bind event handlers so they are only bound once per instance.
75 82
         this._onChangeText = this._onChangeText.bind(this);
76 83
         this._onSubmit = this._onSubmit.bind(this);
@@ -89,7 +96,7 @@ class Dialog extends AbstractDialog<DialogPropTypes, DialogState> {
89 96
             cancelTitleKey = 'dialog.Cancel',
90 97
             okDisabled,
91 98
             okTitleKey = 'dialog.Ok',
92
-            t,
99
+            t /* XXX The following silences flow errors: */ = _.identity,
93 100
             titleKey,
94 101
             titleString
95 102
         } = this.props;
@@ -104,13 +111,10 @@ class Dialog extends AbstractDialog<DialogPropTypes, DialogState> {
104 111
             [_TAG_KEY]: _SUBMIT_TEXT_TAG_VALUE
105 112
         };
106 113
 
107
-        // eslint-disable-next-line no-extra-parens
108
-        let element = (
114
+        let el: ?React$Element<*> = ( // eslint-disable-line no-extra-parens
109 115
             <Prompt
110 116
                 cancelButtonTextStyle = { cancelButtonTextStyle }
111 117
                 cancelText = { t(cancelTitleKey) }
112
-
113
-                // $FlowFixMeState
114 118
                 defaultValue = { this.state.text }
115 119
                 onCancel = { this._onCancel }
116 120
                 onChangeText = { this._onChangeText }
@@ -126,16 +130,18 @@ class Dialog extends AbstractDialog<DialogPropTypes, DialogState> {
126 130
         // XXX The following implements workarounds with knowledge of
127 131
         // react-native-prompt/Prompt's implementation.
128 132
 
129
-        // eslint-disable-next-line no-extra-parens, new-cap
130
-        element = (new (element.type)(element.props)).render();
133
+        if (el) {
134
+            // eslint-disable-next-line new-cap, no-extra-parens
135
+            el = (new (el.type)(el.props)).render();
136
+        }
131 137
 
132 138
         let { children } = this.props;
133 139
 
134 140
         children = React.Children.count(children) ? children : undefined;
135 141
 
136 142
         // eslint-disable-next-line no-shadow
137
-        element = this._mapReactElement(element, element => {
138
-            const { type } = element;
143
+        el = this._mapReactElement(el, (el: React$Element<*>) => {
144
+            const { type } = el;
139 145
 
140 146
             if (type === Modal) {
141 147
                 // * Modal handles hardware button presses for back navigation.
@@ -144,7 +150,7 @@ class Dialog extends AbstractDialog<DialogPropTypes, DialogState> {
144 150
                 //   Secondly, we cannot get Prompt's default behavior anyway
145 151
                 //   because we've removed Prompt and we're preserving whatever
146 152
                 //   it's rendered only.
147
-                return this._cloneElement(element, /* props */ {
153
+                return this._cloneElement(el, /* props */ {
148 154
                     onRequestClose: this._onCancel
149 155
                 });
150 156
             }
@@ -153,12 +159,13 @@ class Dialog extends AbstractDialog<DialogPropTypes, DialogState> {
153 159
                 // * If this Dialog has children, they are to be rendered
154 160
                 //   instead of Prompt's TextInput.
155 161
                 if (children) {
156
-                    element = children; // eslint-disable-line no-param-reassign
162
+                    // $FlowFixMe
163
+                    el = children; // eslint-disable-line no-param-reassign
157 164
                     children = undefined;
158 165
                 }
159 166
 
160 167
             } else {
161
-                let { style } = element.props;
168
+                let { style } = el.props;
162 169
 
163 170
                 if (style
164 171
                         && (style = StyleSheet.flatten(style))
@@ -177,33 +184,33 @@ class Dialog extends AbstractDialog<DialogPropTypes, DialogState> {
177 184
                         break;
178 185
                     }
179 186
 
180
-                    return this._cloneElement(element, /* props */ {
187
+                    return this._cloneElement(el, /* props */ {
181 188
                         style: set(style, _TAG_KEY, undefined)
182 189
                     });
183 190
                 }
184 191
             }
185 192
 
186
-            return element;
193
+            return el;
187 194
         });
188 195
 
189
-        return element;
196
+        return el;
190 197
     }
191 198
 
192 199
     /**
193 200
      * Clones a specific {@code ReactElement} and adds/merges specific props
194 201
      * into the clone.
195 202
      *
196
-     * @param {ReactElement} element - The {@code ReactElement} to clone.
203
+     * @param {ReactElement} el - The {@code ReactElement} to clone.
197 204
      * @param {Object} props - The props to add/merge into the clone.
198
-     * @returns {ReactElement} The close of the specified {@code element} with
205
+     * @returns {ReactElement} The close of the specified {@code el} with
199 206
      * the specified {@code props} added/merged.
200 207
      */
201
-    _cloneElement(element, props) {
208
+    _cloneElement(el: React$Element<*>, props) {
202 209
         return (
203 210
             React.cloneElement(
204
-                element,
211
+                el,
205 212
                 props,
206
-                ...React.Children.toArray(element.props.children)));
213
+                ...React.Children.toArray(el.props.children)));
207 214
     }
208 215
 
209 216
     /**
@@ -211,33 +218,35 @@ class Dialog extends AbstractDialog<DialogPropTypes, DialogState> {
211 218
      * of calling a specific function on every node of a specific
212 219
      * {@code ReactElement} tree.
213 220
      *
214
-     * @param {ReactElement} element - The {@code ReactElement} to clone and
221
+     * @param {ReactElement} el - The {@code ReactElement} to clone and
215 222
      * call the specified {@code f} on.
216 223
      * @param {Function} f - The function to call on every node of the
217
-     * {@code ReactElement} tree represented by the specified {@code element}.
224
+     * {@code ReactElement} tree represented by the specified {@code el}.
218 225
      * @private
219 226
      * @returns {ReactElement}
220 227
      */
221
-    _mapReactElement(element, f) {
222
-        if (!element || !element.props || !element.type) {
223
-            return element;
228
+    _mapReactElement(
229
+            el: ?React$Element<*>,
230
+            f: (React$Element<*>) => ?React$Element<*>): ?React$Element<*> {
231
+        if (!el || !el.props || !el.type) {
232
+            return el;
224 233
         }
225 234
 
226
-        let mapped = f(element);
235
+        let mapped = f(el);
227 236
 
228 237
         if (mapped) {
229 238
             const { children } = mapped.props;
230 239
 
231
-            if (mapped === element || React.Children.count(children)) {
240
+            if (mapped === el || React.Children.count(children)) {
232 241
                 mapped
233 242
                     = React.cloneElement(
234 243
                         mapped,
235 244
                         /* props */ {},
236 245
                         ...React.Children.toArray(React.Children.map(
237 246
                             children,
238
-                            function(element) { // eslint-disable-line no-shadow
247
+                            function(el) { // eslint-disable-line no-shadow
239 248
                                 // eslint-disable-next-line no-invalid-this
240
-                                return this._mapReactElement(element, f);
249
+                                return this._mapReactElement(el, f);
241 250
                             },
242 251
                             this)));
243 252
             }

+ 15
- 7
react/features/base/dialog/components/Dialog.web.js 파일 보기

@@ -1,14 +1,17 @@
1
+// @flow
2
+
1 3
 import React from 'react';
2 4
 import { connect } from 'react-redux';
3 5
 
4
-import AbstractDialog, { AbstractDialogPropTypes } from './AbstractDialog';
6
+import AbstractDialog from './AbstractDialog';
7
+import type { Props as AbstractDialogProps, State } from './AbstractDialog';
5 8
 import StatelessDialog from './StatelessDialog';
6 9
 
7 10
 /**
8
- * Web dialog component's property types.
11
+ * The type of the React {@code Component} props of {@link Dialog}.
9 12
  */
10
-type DialogPropTypes = {
11
-    ...AbstractDialogPropTypes,
13
+type Props = {
14
+    ...AbstractDialogProps,
12 15
 
13 16
     /**
14 17
      * Whether the dialog is modal. This means clicking on the blanket will
@@ -28,13 +31,13 @@ type DialogPropTypes = {
28 31
      * - integer value for pixel width
29 32
      * - string value for percentage
30 33
      */
31
-    width: String
32
-}
34
+    width: string
35
+};
33 36
 
34 37
 /**
35 38
  * Web dialog that uses atlaskit modal-dialog to display dialogs.
36 39
  */
37
-class Dialog extends AbstractDialog<DialogPropTypes> {
40
+class Dialog extends AbstractDialog<Props, State> {
38 41
     /**
39 42
      * Initializes a new Dialog instance.
40 43
      *
@@ -44,6 +47,7 @@ class Dialog extends AbstractDialog<DialogPropTypes> {
44 47
     constructor(props) {
45 48
         super(props);
46 49
 
50
+        // Bind event handlers so they are only bound once per instance.
47 51
         this._onCancel = this._onCancel.bind(this);
48 52
         this._onSubmit = this._onSubmit.bind(this);
49 53
     }
@@ -66,6 +70,8 @@ class Dialog extends AbstractDialog<DialogPropTypes> {
66 70
         return <StatelessDialog { ...props } />;
67 71
     }
68 72
 
73
+    _onCancel: () => void;
74
+
69 75
     /**
70 76
      * Dispatches action to hide the dialog.
71 77
      *
@@ -74,6 +80,8 @@ class Dialog extends AbstractDialog<DialogPropTypes> {
74 80
     _onCancel() {
75 81
         this.props.isModal || super._onCancel();
76 82
     }
83
+
84
+    _onSubmit: (?string) => void;
77 85
 }
78 86
 
79 87
 export default connect()(Dialog);

+ 82
- 56
react/features/base/dialog/components/StatelessDialog.web.js 파일 보기

@@ -1,12 +1,14 @@
1
+// @flow
2
+
1 3
 import Button, { ButtonGroup } from '@atlaskit/button';
2 4
 import ModalDialog from '@atlaskit/modal-dialog';
3 5
 import { AtlasKitThemeProvider } from '@atlaskit/theme';
4
-import PropTypes from 'prop-types';
6
+import _ from 'lodash';
5 7
 import React, { Component } from 'react';
6 8
 
7 9
 import { translate } from '../../i18n';
8 10
 
9
-import { DIALOG_PROP_TYPES } from '../constants';
11
+import type { DialogProps } from '../constants';
10 12
 
11 13
 /**
12 14
  * The ID to be used for the cancel button if enabled.
@@ -21,48 +23,45 @@ const CANCEL_BUTTON_ID = 'modal-dialog-cancel-button';
21 23
 const OK_BUTTON_ID = 'modal-dialog-ok-button';
22 24
 
23 25
 /**
24
- * Web dialog that uses atlaskit modal-dialog to display dialogs.
26
+ * The type of the React {@code Component} props of {@link StatelessDialog}.
27
+ *
28
+ * @static
25 29
  */
26
-class StatelessDialog extends Component {
30
+type Props = {
31
+    ...DialogProps,
32
+
27 33
     /**
28
-     * {@code StatelessDialog} component's property types.
29
-     *
30
-     * @static
34
+     * Disables dismissing the dialog when the blanket is clicked. Enabled
35
+     * by default.
36
+     */
37
+    disableBlanketClickDismiss: boolean,
38
+
39
+    /**
40
+     * Whether the dialog is modal. This means clicking on the blanket will
41
+     * leave the dialog open. No cancel button.
31 42
      */
32
-    static propTypes = {
33
-        ...DIALOG_PROP_TYPES,
34
-
35
-        /**
36
-         * This is the body of the dialog, the component children.
37
-         */
38
-        children: PropTypes.node,
39
-
40
-        /**
41
-         * Disables dismissing the dialog when the blanket is clicked. Enabled
42
-         * by default.
43
-         */
44
-        disableBlanketClickDismiss: PropTypes.bool,
45
-
46
-        /**
47
-         * Whether the dialog is modal. This means clicking on the blanket will
48
-         * leave the dialog open. No cancel button.
49
-         */
50
-        isModal: PropTypes.bool,
51
-
52
-        /**
53
-         * Disables rendering of the submit button.
54
-         */
55
-        submitDisabled: PropTypes.bool,
56
-
57
-        /**
58
-         * Width of the dialog, can be:
59
-         * - 'small' (400px), 'medium' (600px), 'large' (800px),
60
-         *   'x-large' (968px)
61
-         * - integer value for pixel width
62
-         * - string value for percentage
63
-         */
64
-        width: PropTypes.string
65
-    };
43
+    isModal: boolean,
44
+
45
+    /**
46
+     * Disables rendering of the submit button.
47
+     */
48
+    submitDisabled: boolean,
49
+
50
+    /**
51
+     * Width of the dialog, can be:
52
+     * - 'small' (400px), 'medium' (600px), 'large' (800px),
53
+     *   'x-large' (968px)
54
+     * - integer value for pixel width
55
+     * - string value for percentage
56
+     */
57
+    width: string
58
+};
59
+
60
+/**
61
+ * Web dialog that uses atlaskit modal-dialog to display dialogs.
62
+ */
63
+class StatelessDialog extends Component<Props> {
64
+    _dialogElement: ?HTMLElement;
66 65
 
67 66
     /**
68 67
      * Initializes a new {@code StatelessDialog} instance.
@@ -100,8 +99,8 @@ class StatelessDialog extends Component {
100 99
         // if there is an update in any of the buttons enable/disable props
101 100
         // update the focus if needed
102 101
         if (prevProps.okDisabled !== this.props.okDisabled
103
-            || prevProps.cancelDisabled !== this.props.cancelDisabled
104
-            || prevProps.submitDisabled !== this.props.submitDisabled) {
102
+                || prevProps.cancelDisabled !== this.props.cancelDisabled
103
+                || prevProps.submitDisabled !== this.props.submitDisabled) {
105 104
             this._updateButtonFocus();
106 105
         }
107 106
     }
@@ -143,6 +142,8 @@ class StatelessDialog extends Component {
143 142
         );
144 143
     }
145 144
 
145
+    _onCancel: () => void;
146
+
146 147
     /**
147 148
      * Dispatches action to hide the dialog.
148 149
      *
@@ -150,10 +151,14 @@ class StatelessDialog extends Component {
150 151
      */
151 152
     _onCancel() {
152 153
         if (!this.props.isModal) {
153
-            this.props.onCancel();
154
+            const { onCancel } = this.props;
155
+
156
+            onCancel && onCancel();
154 157
         }
155 158
     }
156 159
 
160
+    _onDialogDismissed: () => void;
161
+
157 162
     /**
158 163
      * Handles click on the blanket area.
159 164
      *
@@ -165,6 +170,8 @@ class StatelessDialog extends Component {
165 170
         }
166 171
     }
167 172
 
173
+    _onSubmit: (?string) => void;
174
+
168 175
     /**
169 176
      * Dispatches the action when submitting the dialog.
170 177
      *
@@ -173,7 +180,9 @@ class StatelessDialog extends Component {
173 180
      * @returns {void}
174 181
      */
175 182
     _onSubmit(value) {
176
-        this.props.onSubmit(value);
183
+        const { onSubmit } = this.props;
184
+
185
+        onSubmit && onSubmit(value);
177 186
     }
178 187
 
179 188
     /**
@@ -187,6 +196,10 @@ class StatelessDialog extends Component {
187 196
             return null;
188 197
         }
189 198
 
199
+        const {
200
+            t /* The following fixes a flow error: */ = _.identity
201
+        } = this.props;
202
+
190 203
         return (
191 204
             <Button
192 205
                 appearance = 'subtle'
@@ -194,7 +207,7 @@ class StatelessDialog extends Component {
194 207
                 key = 'cancel'
195 208
                 onClick = { this._onCancel }
196 209
                 type = 'button'>
197
-                { this.props.t(this.props.cancelTitleKey || 'dialog.Cancel') }
210
+                { t(this.props.cancelTitleKey || 'dialog.Cancel') }
198 211
             </Button>
199 212
         );
200 213
     }
@@ -229,7 +242,9 @@ class StatelessDialog extends Component {
229 242
      * @returns {ReactElement}
230 243
      */
231 244
     _renderHeader() {
232
-        const { t } = this.props;
245
+        const {
246
+            t /* The following fixes a flow error: */ = _.identity
247
+        } = this.props;
233 248
 
234 249
         return (
235 250
             <header>
@@ -251,6 +266,10 @@ class StatelessDialog extends Component {
251 266
             return null;
252 267
         }
253 268
 
269
+        const {
270
+            t /* The following fixes a flow error: */ = _.identity
271
+        } = this.props;
272
+
254 273
         return (
255 274
             <Button
256 275
                 appearance = 'primary'
@@ -260,23 +279,28 @@ class StatelessDialog extends Component {
260 279
                 key = 'submit'
261 280
                 onClick = { this._onSubmit }
262 281
                 type = 'button'>
263
-                { this.props.t(this.props.okTitleKey || 'dialog.Ok') }
282
+                { t(this.props.okTitleKey || 'dialog.Ok') }
264 283
             </Button>
265 284
         );
266 285
     }
267 286
 
287
+    _setDialogElement: (?HTMLElement) => void;
288
+
268 289
     /**
269 290
      * Sets the instance variable for the div containing the component's dialog
270 291
      * element so it can be accessed directly.
271 292
      *
272
-     * @param {Object} element - The DOM element for the component's dialog.
293
+     * @param {HTMLElement} element - The DOM element for the component's
294
+     * dialog.
273 295
      * @private
274 296
      * @returns {void}
275 297
      */
276
-    _setDialogElement(element) {
298
+    _setDialogElement(element: ?HTMLElement) {
277 299
         this._dialogElement = element;
278 300
     }
279 301
 
302
+    _onKeyDown: (Object) => void;
303
+
280 304
     /**
281 305
      * Handles 'Enter' key in the dialog to submit/hide dialog depending on
282 306
      * the available buttons and their disabled state.
@@ -312,22 +336,24 @@ class StatelessDialog extends Component {
312 336
      * @returns {void}
313 337
      */
314 338
     _updateButtonFocus() {
315
-        if (this._dialogElement) {
339
+        const dialogElement = this._dialogElement;
340
+
341
+        if (dialogElement) {
316 342
 
317 343
             // if we have a focused element inside the dialog, skip changing
318 344
             // the focus
319
-            if (this._dialogElement.contains(document.activeElement)) {
345
+            if (dialogElement.contains(document.activeElement)) {
320 346
                 return;
321 347
             }
322 348
 
323 349
             let buttonToFocus;
324 350
 
325 351
             if (this.props.submitDisabled) {
326
-                buttonToFocus = this._dialogElement
327
-                    .querySelector(`[id=${CANCEL_BUTTON_ID}]`);
352
+                buttonToFocus
353
+                    = dialogElement.querySelector(`[id=${CANCEL_BUTTON_ID}]`);
328 354
             } else if (!this.props.okDisabled) {
329
-                buttonToFocus = this._dialogElement
330
-                    .querySelector(`[id=${OK_BUTTON_ID}]`);
355
+                buttonToFocus
356
+                    = dialogElement.querySelector(`[id=${OK_BUTTON_ID}]`);
331 357
             }
332 358
 
333 359
             if (buttonToFocus) {

+ 11
- 5
react/features/base/dialog/constants.js 파일 보기

@@ -1,5 +1,6 @@
1
+// @flow
1 2
 
2
-export type DialogPropTypes = {
3
+export type DialogProps = {
3 4
 
4 5
     /**
5 6
      * Whether cancel button is disabled. Enabled by default.
@@ -9,7 +10,12 @@ export type DialogPropTypes = {
9 10
     /**
10 11
      * Optional i18n key to change the cancel button title.
11 12
      */
12
-    cancelTitleKey: String,
13
+    cancelTitleKey: string,
14
+
15
+    /**
16
+     * The React {@code Component} children which represents the dialog's body.
17
+     */
18
+    children: React$Node,
13 19
 
14 20
     /**
15 21
      * Is ok button enabled/disabled. Enabled by default.
@@ -19,7 +25,7 @@ export type DialogPropTypes = {
19 25
     /**
20 26
      * Optional i18n key to change the ok button title.
21 27
      */
22
-    okTitleKey: String,
28
+    okTitleKey: string,
23 29
 
24 30
     /**
25 31
      * The handler for onCancel event.
@@ -39,12 +45,12 @@ export type DialogPropTypes = {
39 45
     /**
40 46
      * Key to use for showing a title.
41 47
      */
42
-    titleKey: String,
48
+    titleKey: string,
43 49
 
44 50
     /**
45 51
      * The string to use as a title instead of {@code titleKey}. If a truthy
46 52
      * value is specified, it takes precedence over {@code titleKey} i.e.
47 53
      * the latter is unused.
48 54
      */
49
-    titleString: String
55
+    titleString: string
50 56
 };

+ 14
- 5
react/features/conference/components/Conference.native.js 파일 보기

@@ -1,3 +1,5 @@
1
+// @flow
2
+
1 3
 import React, { Component } from 'react';
2 4
 
3 5
 // eslint-disable-next-line react-native/split-platform-components
@@ -25,11 +27,9 @@ import styles from './styles';
25 27
 const _TOOLBOX_TIMEOUT_MS = 5000;
26 28
 
27 29
 /**
28
- * Conference component's property types.
29
- *
30
- * @static
30
+ * The type of the React {@code Component} props of {@link Conference}.
31 31
  */
32
-type ConferencePropTypes = {
32
+type Props = {
33 33
 
34 34
     /**
35 35
      * The indicator which determines that we are still connecting to the
@@ -85,7 +85,11 @@ type ConferencePropTypes = {
85 85
 /**
86 86
  * The conference page of the mobile (i.e. React Native) application.
87 87
  */
88
-class Conference extends Component<ConferencePropTypes> {
88
+class Conference extends Component<Props> {
89
+    _backHandler: ?BackHandler;
90
+
91
+    _toolboxTimeout: ?number;
92
+
89 93
     /**
90 94
      * Initializes a new Conference instance.
91 95
      *
@@ -237,6 +241,8 @@ class Conference extends Component<ConferencePropTypes> {
237 241
         }
238 242
     }
239 243
 
244
+    _onClick: () => void;
245
+
240 246
     /**
241 247
      * Changes the value of the toolboxVisible state, thus allowing us to switch
242 248
      * between Toolbox and Filmstrip and change their visibility.
@@ -254,6 +260,8 @@ class Conference extends Component<ConferencePropTypes> {
254 260
         this._clearToolboxTimeout();
255 261
     }
256 262
 
263
+    _onHardwareBackPress: () => boolean;
264
+
257 265
     /**
258 266
      * Handles a hardware button press for back navigation.
259 267
      *
@@ -393,5 +401,6 @@ function _mapStateToProps(state) {
393 401
     };
394 402
 }
395 403
 
404
+// $FlowFixMe
396 405
 export default reactReduxConnect(_mapStateToProps, _mapDispatchToProps)(
397 406
     Conference);

+ 5
- 5
react/features/feedback/components/FeedbackButton.web.js 파일 보기

@@ -1,4 +1,4 @@
1
-/* @flow */
1
+// @flow
2 2
 
3 3
 import Tooltip from '@atlaskit/tooltip';
4 4
 import React, { Component } from 'react';
@@ -9,9 +9,9 @@ import { translate } from '../../base/i18n';
9 9
 import { openFeedbackDialog } from '../actions';
10 10
 
11 11
 /**
12
- * Defines property types for the FeedbackButton component.
12
+ * The type of the React {@code Component} props of {@link FeedbackButton}.
13 13
  */
14
-type FeedbackButtonPropTypes = {
14
+type Props = {
15 15
 
16 16
     /**
17 17
      * The JitsiConference for which the feedback will be about.
@@ -34,13 +34,13 @@ type FeedbackButtonPropTypes = {
34 34
     /**
35 35
      * From which side of the button the tooltip should appear from.
36 36
      */
37
-    tooltipPosition: String
37
+    tooltipPosition: string
38 38
 }
39 39
 
40 40
 /**
41 41
  * Implements a Web/React Component which renders a feedback button.
42 42
  */
43
-class FeedbackButton extends Component<FeedbackButtonPropTypes> {
43
+class FeedbackButton extends Component<Props> {
44 44
     _onClick: Function;
45 45
 
46 46
     /**

Loading…
취소
저장