Browse Source

Coding style: comments

master
Lyubo Marinov 7 years ago
parent
commit
df8eb36d0e

+ 4
- 2
react/features/base/toolbox/components/AbstractToolboxItem.js View File

10
     iconStyle: Object,
10
     iconStyle: Object,
11
 
11
 
12
     /**
12
     /**
13
-     * Style for te item's label.
13
+     * Style for the item's label.
14
      */
14
      */
15
     labelStyle: Object,
15
     labelStyle: Object,
16
 
16
 
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
      * @protected
181
      * @protected
180
      * @returns {ReactElement}
182
      * @returns {ReactElement}

+ 19
- 14
react/features/base/toolbox/components/ToolboxItem.native.js View File

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
      * @private
31
      * @private
32
      * @returns {ReactElement}
32
      * @returns {ReactElement}
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
      * @protected
48
      * @protected
48
      * @returns {ReactElement}
49
      * @returns {ReactElement}
49
      */
50
      */
56
             styles
57
             styles
57
         } = this.props;
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
         if (showLabel) {
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
                         { this.label }
74
                         { this.label }
68
                     </Text>
75
                     </Text>
69
                 </View>
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
         return (
84
         return (
80
             <TouchableHighlight
85
             <TouchableHighlight

+ 2
- 1
react/features/invite/components/InviteButton.native.js View File

47
 const _SHARE_ROOM_TOOLBAR_BUTTON = true;
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
 class InviteButton extends AbstractButton<Props, *> {
53
 class InviteButton extends AbstractButton<Props, *> {
53
     accessibilityLabel = 'Share room';
54
     accessibilityLabel = 'Share room';

+ 13
- 9
react/features/toolbox/components/native/OverflowMenu.js View File

3
 import React, { Component } from 'react';
3
 import React, { Component } from 'react';
4
 import { connect } from 'react-redux';
4
 import { connect } from 'react-redux';
5
 
5
 
6
-import { hideDialog, BottomSheet } from '../../../base/dialog';
6
+import { BottomSheet, hideDialog } from '../../../base/dialog';
7
 import { AudioRouteButton } from '../../../mobile/audio-mode';
7
 import { AudioRouteButton } from '../../../mobile/audio-mode';
8
 import { PictureInPictureButton } from '../../../mobile/picture-in-picture';
8
 import { PictureInPictureButton } from '../../../mobile/picture-in-picture';
9
 import { RoomLockButton } from '../../../room-lock';
9
 import { RoomLockButton } from '../../../room-lock';
10
 
10
 
11
 import AudioOnlyButton from './AudioOnlyButton';
11
 import AudioOnlyButton from './AudioOnlyButton';
12
-import ToggleCameraButton from './ToggleCameraButton';
13
-
14
 import { overflowMenuItemStyles } from './styles';
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
 type Props = {
18
 type Props = {
17
 
19
 
18
     /**
20
     /**
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
  * Implements a React {@code Component} with some extra actions in addition to
36
  * Implements a React {@code Component} with some extra actions in addition to
42
     constructor(props: Props) {
45
     constructor(props: Props) {
43
         super(props);
46
         super(props);
44
 
47
 
48
+        // Bind event handlers so they are only bound once per instance.
45
         this._onCancel = this._onCancel.bind(this);
49
         this._onCancel = this._onCancel.bind(this);
46
     }
50
     }
47
 
51
 
76
     _onCancel: () => void;
80
     _onCancel: () => void;
77
 
81
 
78
     /**
82
     /**
79
-     * Hides the dialog.
83
+     * Hides this {@code OverflowMenu}.
80
      *
84
      *
81
      * @private
85
      * @private
82
      * @returns {void}
86
      * @returns {void}

+ 6
- 3
react/features/toolbox/components/native/OverflowMenuButton.js View File

9
 
9
 
10
 import OverflowMenu from './OverflowMenu';
10
 import OverflowMenu from './OverflowMenu';
11
 
11
 
12
+/**
13
+ * The type of the React {@code Component} props of {@link OverflowMenuButton}.
14
+ */
12
 type Props = AbstractButtonProps & {
15
 type Props = AbstractButtonProps & {
13
 
16
 
14
     /**
17
     /**
15
      * The redux {@code dispatch} function.
18
      * The redux {@code dispatch} function.
16
      */
19
      */
17
     dispatch: Function
20
     dispatch: Function
18
-}
21
+};
19
 
22
 
20
 /**
23
 /**
21
  * An implementation of a button for showing the {@code OverflowMenu}.
24
  * An implementation of a button for showing the {@code OverflowMenu}.
26
     label = 'toolbar.moreActions';
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
      * @returns {void}
35
      * @returns {void}
33
      */
36
      */
34
     _handleClick() {
37
     _handleClick() {

+ 75
- 64
react/features/toolbox/components/native/Toolbox.js View File

13
 
13
 
14
 import AudioMuteButton from '../AudioMuteButton';
14
 import AudioMuteButton from '../AudioMuteButton';
15
 import HangupButton from '../HangupButton';
15
 import HangupButton from '../HangupButton';
16
-import VideoMuteButton from '../VideoMuteButton';
17
-
18
 import OverflowMenuButton from './OverflowMenuButton';
16
 import OverflowMenuButton from './OverflowMenuButton';
19
 import styles, {
17
 import styles, {
20
     hangupButtonStyles,
18
     hangupButtonStyles,
21
     toolbarButtonStyles,
19
     toolbarButtonStyles,
22
     toolbarToggledButtonStyles
20
     toolbarToggledButtonStyles
23
 } from './styles';
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
  * Factor relating the hangup button and other toolbar buttons.
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
  * The type of {@link Toolbox}'s React {@code Component} props.
41
  * The type of {@link Toolbox}'s React {@code Component} props.
75
     constructor(props: Props) {
80
     constructor(props: Props) {
76
         super(props);
81
         super(props);
77
 
82
 
83
+        // Bind event handlers so they are only bound once per instance.
78
         this._onLayout = this._onLayout.bind(this);
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
      * Implements React's {@link Component#render()}.
88
      * Implements React's {@link Component#render()}.
122
      *
89
      *
129
                 ? styles.toolboxNarrow
96
                 ? styles.toolboxNarrow
130
                 : styles.toolboxWide;
97
                 : styles.toolboxWide;
131
         const { _visible } = this.props;
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
         return (
123
         return (
153
             <Container
124
             <Container
154
                 onLayout = { this._onLayout }
125
                 onLayout = { this._onLayout }
155
                 style = { toolboxStyle }
126
                 style = { toolboxStyle }
156
-                visible = { _visible } >
127
+                visible = { _visible }>
157
                 <View
128
                 <View
158
                     pointerEvents = 'box-none'
129
                     pointerEvents = 'box-none'
159
                     style = { styles.toolbar }>
130
                     style = { styles.toolbar }>
172
             </Container>
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
  * {@code Toolbox} props.
194
  * {@code Toolbox} props.
183
  * @private
195
  * @private
184
  * @returns {{
196
  * @returns {{
185
- *     _enabled: boolean,
186
  *     _visible: boolean
197
  *     _visible: boolean
187
  * }}
198
  * }}
188
  */
199
  */

+ 6
- 0
react/features/toolbox/components/native/styles.js View File

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

Loading…
Cancel
Save