소스 검색

Coding style: comments

master
Lyubo Marinov 7 년 전
부모
커밋
df8eb36d0e

+ 4
- 2
react/features/base/toolbox/components/AbstractToolboxItem.js 파일 보기

@@ -10,7 +10,7 @@ export type Styles = {
10 10
     iconStyle: Object,
11 11
 
12 12
     /**
13
-     * Style for te item's label.
13
+     * Style for the item's label.
14 14
      */
15 15
     labelStyle: Object,
16 16
 
@@ -174,7 +174,9 @@ export default class AbstractToolboxItem<P : Props> extends Component<P> {
174 174
     }
175 175
 
176 176
     /**
177
-     * Handles rendering of the actual item.
177
+     * Renders this {@code AbstractToolboxItem} (if it is {@code visible}). To
178
+     * be implemented/overridden by extenders. The default implementation of
179
+     * {@code AbstractToolboxItem} does nothing.
178 180
      *
179 181
      * @protected
180 182
      * @returns {ReactElement}

+ 19
- 14
react/features/base/toolbox/components/ToolboxItem.native.js 파일 보기

@@ -26,7 +26,7 @@ export default class ToolboxItem extends AbstractToolboxItem<Props> {
26 26
     }
27 27
 
28 28
     /**
29
-     * Helper function to render the {@code Icon} part of this item.
29
+     * Renders the {@code Icon} part of this {@code ToolboxItem}.
30 30
      *
31 31
      * @private
32 32
      * @returns {ReactElement}
@@ -42,8 +42,9 @@ export default class ToolboxItem extends AbstractToolboxItem<Props> {
42 42
     }
43 43
 
44 44
     /**
45
-     * Handles rendering of the actual item.
45
+     * Renders this {@code ToolboxItem}. Invoked by {@link AbstractToolboxItem}.
46 46
      *
47
+     * @override
47 48
      * @protected
48 49
      * @returns {ReactElement}
49 50
      */
@@ -56,25 +57,29 @@ export default class ToolboxItem extends AbstractToolboxItem<Props> {
56 57
             styles
57 58
         } = this.props;
58 59
 
59
-        let children;
60
+        let children = this._renderIcon();
61
+
62
+        // XXX When using a wrapper View, apply the style to it instead of
63
+        // applying it to the TouchableHighlight.
64
+        let style = styles && styles.style;
60 65
 
61 66
         if (showLabel) {
62
-            // eslint-disable-next-line no-extra-parens
63
-            children = (
64
-                <View style = { styles && styles.style } >
65
-                    { this._renderIcon() }
66
-                    <Text style = { styles && styles.labelStyle } >
67
+            // XXX TouchableHighlight requires 1 child. If there's a need to
68
+            // show both the icon and the label, then these two need to be
69
+            // wrapped in a View.
70
+            children = ( // eslint-disable-line no-extra-parens
71
+                <View style = { style }>
72
+                    { children }
73
+                    <Text style = { styles && styles.labelStyle }>
67 74
                         { this.label }
68 75
                     </Text>
69 76
                 </View>
70 77
             );
71
-        } else {
72
-            children = this._renderIcon();
73
-        }
74 78
 
75
-        // When using a wrapper view, apply the style to it instead of
76
-        // applying it to the TouchableHighlight.
77
-        const style = showLabel ? undefined : styles && styles.style;
79
+            // XXX As stated earlier, the style was applied to the wrapper View
80
+            // (above).
81
+            style = undefined;
82
+        }
78 83
 
79 84
         return (
80 85
             <TouchableHighlight

+ 2
- 1
react/features/invite/components/InviteButton.native.js 파일 보기

@@ -47,7 +47,8 @@ type Props = AbstractButtonProps & {
47 47
 const _SHARE_ROOM_TOOLBAR_BUTTON = true;
48 48
 
49 49
 /**
50
- * Implements a {@link ToolbarButton} to enter Picture-in-Picture.
50
+ * Implements an {@link AbstractButton} to enter add/invite people to the
51
+ * current call/conference/meeting.
51 52
  */
52 53
 class InviteButton extends AbstractButton<Props, *> {
53 54
     accessibilityLabel = 'Share room';

+ 13
- 9
react/features/toolbox/components/native/OverflowMenu.js 파일 보기

@@ -3,16 +3,18 @@
3 3
 import React, { Component } from 'react';
4 4
 import { connect } from 'react-redux';
5 5
 
6
-import { hideDialog, BottomSheet } from '../../../base/dialog';
6
+import { BottomSheet, hideDialog } from '../../../base/dialog';
7 7
 import { AudioRouteButton } from '../../../mobile/audio-mode';
8 8
 import { PictureInPictureButton } from '../../../mobile/picture-in-picture';
9 9
 import { RoomLockButton } from '../../../room-lock';
10 10
 
11 11
 import AudioOnlyButton from './AudioOnlyButton';
12
-import ToggleCameraButton from './ToggleCameraButton';
13
-
14 12
 import { overflowMenuItemStyles } from './styles';
13
+import ToggleCameraButton from './ToggleCameraButton';
15 14
 
15
+/**
16
+ * The type of the React {@code Component} props of {@link OverflowMenu}.
17
+ */
16 18
 type Props = {
17 19
 
18 20
     /**
@@ -22,12 +24,13 @@ type Props = {
22 24
 };
23 25
 
24 26
 /**
25
- * The exported React {@code Component}. We need a reference to the wrapped
26
- * component in order to be able to hide it using the dialog hiding logic.
27
+ * The exported React {@code Component}. We need it to execute
28
+ * {@link hideDialog}.
29
+ *
30
+ * XXX It does not break our coding style rule to not utilize globals for state,
31
+ * because it is merely another name for {@code export}'s {@code default}.
27 32
  */
28
-
29
-// eslint-disable-next-line prefer-const
30
-let OverflowMenu_;
33
+let OverflowMenu_; // eslint-disable-line prefer-const
31 34
 
32 35
 /**
33 36
  * Implements a React {@code Component} with some extra actions in addition to
@@ -42,6 +45,7 @@ class OverflowMenu extends Component<Props> {
42 45
     constructor(props: Props) {
43 46
         super(props);
44 47
 
48
+        // Bind event handlers so they are only bound once per instance.
45 49
         this._onCancel = this._onCancel.bind(this);
46 50
     }
47 51
 
@@ -76,7 +80,7 @@ class OverflowMenu extends Component<Props> {
76 80
     _onCancel: () => void;
77 81
 
78 82
     /**
79
-     * Hides the dialog.
83
+     * Hides this {@code OverflowMenu}.
80 84
      *
81 85
      * @private
82 86
      * @returns {void}

+ 6
- 3
react/features/toolbox/components/native/OverflowMenuButton.js 파일 보기

@@ -9,13 +9,16 @@ import type { AbstractButtonProps } from '../../../base/toolbox';
9 9
 
10 10
 import OverflowMenu from './OverflowMenu';
11 11
 
12
+/**
13
+ * The type of the React {@code Component} props of {@link OverflowMenuButton}.
14
+ */
12 15
 type Props = AbstractButtonProps & {
13 16
 
14 17
     /**
15 18
      * The redux {@code dispatch} function.
16 19
      */
17 20
     dispatch: Function
18
-}
21
+};
19 22
 
20 23
 /**
21 24
  * An implementation of a button for showing the {@code OverflowMenu}.
@@ -26,9 +29,9 @@ class OverflowMenuButton extends AbstractButton<Props, *> {
26 29
     label = 'toolbar.moreActions';
27 30
 
28 31
     /**
29
-     * Handles clicking / pressing the button.
32
+     * Handles clicking / pressing this {@code OverflowMenuButton}.
30 33
      *
31
-     * @private
34
+     * @protected
32 35
      * @returns {void}
33 36
      */
34 37
     _handleClick() {

+ 75
- 64
react/features/toolbox/components/native/Toolbox.js 파일 보기

@@ -13,24 +13,29 @@ import { InviteButton } from '../../../invite';
13 13
 
14 14
 import AudioMuteButton from '../AudioMuteButton';
15 15
 import HangupButton from '../HangupButton';
16
-import VideoMuteButton from '../VideoMuteButton';
17
-
18 16
 import OverflowMenuButton from './OverflowMenuButton';
19 17
 import styles, {
20 18
     hangupButtonStyles,
21 19
     toolbarButtonStyles,
22 20
     toolbarToggledButtonStyles
23 21
 } from './styles';
22
+import VideoMuteButton from '../VideoMuteButton';
24 23
 
25 24
 /**
26
- * Number of buttons in the toolbar.
25
+ * The number of buttons to render in {@link Toolbox}.
26
+ *
27
+ * @private
28
+ * @type number
27 29
  */
28
-const NUM_TOOLBAR_BUTTONS = 4;
30
+const _BUTTON_COUNT = 4;
29 31
 
30 32
 /**
31 33
  * Factor relating the hangup button and other toolbar buttons.
34
+ *
35
+ * @private
36
+ * @type number
32 37
  */
33
-const TOOLBAR_BUTTON_SIZE_FACTOR = 0.8;
38
+const _BUTTON_SIZE_FACTOR = 0.8;
34 39
 
35 40
 /**
36 41
  * The type of {@link Toolbox}'s React {@code Component} props.
@@ -75,48 +80,10 @@ class Toolbox extends Component<Props, State> {
75 80
     constructor(props: Props) {
76 81
         super(props);
77 82
 
83
+        // Bind event handlers so they are only bound once per instance.
78 84
         this._onLayout = this._onLayout.bind(this);
79 85
     }
80 86
 
81
-    _onLayout: (Object) => void;
82
-
83
-    /**
84
-     * Handles the "on layout" View's event and stores the width as state.
85
-     *
86
-     * @param {Object} event - The "on layout" event object/structure passed
87
-     * by react-native.
88
-     * @private
89
-     * @returns {void}
90
-     */
91
-    _onLayout({ nativeEvent: { layout: { width } } }) {
92
-        this.setState({ width });
93
-    }
94
-
95
-    /**
96
-     * Calculates how large our toolbar buttons can be, given the available
97
-     * width. In the future we might want to have a size threshold, and once
98
-     * it's passed a completely different style could be used, akin to the web.
99
-     *
100
-     * @private
101
-     * @returns {number}
102
-     */
103
-    _calculateToolbarButtonSize() {
104
-        const width = this.state.width;
105
-        const hangupButtonSize = styles.hangupButton.width;
106
-
107
-        let buttonSize
108
-            = (width - hangupButtonSize
109
-                - (NUM_TOOLBAR_BUTTONS * styles.toolbarButton.margin * 2))
110
-                    / NUM_TOOLBAR_BUTTONS;
111
-
112
-        // Make sure it's an even number.
113
-        buttonSize = 2 * Math.round(buttonSize / 2);
114
-
115
-        // The button should be at most 80% of the hangup button's size.
116
-        return Math.min(
117
-            buttonSize, hangupButtonSize * TOOLBAR_BUTTON_SIZE_FACTOR);
118
-    }
119
-
120 87
     /**
121 88
      * Implements React's {@link Component#render()}.
122 89
      *
@@ -129,31 +96,35 @@ class Toolbox extends Component<Props, State> {
129 96
                 ? styles.toolboxNarrow
130 97
                 : styles.toolboxWide;
131 98
         const { _visible } = this.props;
132
-        const buttonStyles = {
133
-            ...toolbarButtonStyles
134
-        };
135
-        const toggledButtonStyles = {
136
-            ...toolbarToggledButtonStyles
137
-        };
138
-
139
-        if (_visible && this.state.width) {
140
-            const buttonSize = this._calculateToolbarButtonSize();
141
-            const extraStyle = {
142
-                borderRadius: buttonSize / 2,
143
-                height: buttonSize,
144
-                width: buttonSize
145
-            };
146
-
147
-            buttonStyles.style = [ buttonStyles.style, extraStyle ];
148
-            toggledButtonStyles.style
149
-                = [ toggledButtonStyles.style, extraStyle ];
99
+        let buttonStyles = toolbarButtonStyles;
100
+        let toggledButtonStyles = toolbarToggledButtonStyles;
101
+
102
+        if (_visible) {
103
+            const buttonSize = this._calculateButtonSize();
104
+
105
+            if (buttonSize > 0) {
106
+                const extraButtonStyle = {
107
+                    borderRadius: buttonSize / 2,
108
+                    height: buttonSize,
109
+                    width: buttonSize
110
+                };
111
+
112
+                buttonStyles = {
113
+                    ...buttonStyles,
114
+                    style: [ buttonStyles.style, extraButtonStyle ]
115
+                };
116
+                toggledButtonStyles = {
117
+                    ...toggledButtonStyles,
118
+                    style: [ toggledButtonStyles.style, extraButtonStyle ]
119
+                };
120
+            }
150 121
         }
151 122
 
152 123
         return (
153 124
             <Container
154 125
                 onLayout = { this._onLayout }
155 126
                 style = { toolboxStyle }
156
-                visible = { _visible } >
127
+                visible = { _visible }>
157 128
                 <View
158 129
                     pointerEvents = 'box-none'
159 130
                     style = { styles.toolbar }>
@@ -172,6 +143,47 @@ class Toolbox extends Component<Props, State> {
172 143
             </Container>
173 144
         );
174 145
     }
146
+
147
+    /**
148
+     * Calculates how large our toolbar buttons can be, given the available
149
+     * width. In the future we might want to have a size threshold, and once
150
+     * it's passed a completely different style could be used, akin to the web.
151
+     *
152
+     * @private
153
+     * @returns {number}
154
+     */
155
+    _calculateButtonSize() {
156
+        const { width } = this.state;
157
+        const hangupButtonSize = styles.hangupButton.width;
158
+
159
+        let buttonSize
160
+            = (width
161
+                    - hangupButtonSize
162
+                    - (_BUTTON_COUNT * styles.toolbarButton.margin * 2))
163
+                / _BUTTON_COUNT;
164
+
165
+        // Make sure it's an even number.
166
+        buttonSize = 2 * Math.round(buttonSize / 2);
167
+
168
+        // The button should be at most 80% of the hangup button's size.
169
+        return Math.min(
170
+            buttonSize,
171
+            hangupButtonSize * _BUTTON_SIZE_FACTOR);
172
+    }
173
+
174
+    _onLayout: (Object) => void;
175
+
176
+    /**
177
+     * Handles the "on layout" View's event and stores the width as state.
178
+     *
179
+     * @param {Object} event - The "on layout" event object/structure passed
180
+     * by react-native.
181
+     * @private
182
+     * @returns {void}
183
+     */
184
+    _onLayout({ nativeEvent: { layout: { width } } }) {
185
+        this.setState({ width });
186
+    }
175 187
 }
176 188
 
177 189
 /**
@@ -182,7 +194,6 @@ class Toolbox extends Component<Props, State> {
182 194
  * {@code Toolbox} props.
183 195
  * @private
184 196
  * @returns {{
185
- *     _enabled: boolean,
186 197
  *     _visible: boolean
187 198
  * }}
188 199
  */

+ 6
- 0
react/features/toolbox/components/native/styles.js 파일 보기

@@ -1,5 +1,9 @@
1
+// @flow
2
+
1 3
 import { BoxModel, ColorPalette, createStyleSheet } from '../../../base/styles';
2 4
 
5
+// Toolbox, toolbar:
6
+
3 7
 /**
4 8
  * The style of toolbar buttons.
5 9
  */
@@ -141,6 +145,8 @@ export const toolbarToggledButtonStyles = {
141 145
     style: styles.whiteToolbarButton
142 146
 };
143 147
 
148
+// Overflow menu:
149
+
144 150
 /**
145 151
  * Styles for the {@code OverflowMenu} items.
146 152
  *

Loading…
취소
저장