|
@@ -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
|
*/
|