|
|
@@ -22,7 +22,8 @@ import styles, {
|
|
22
|
22
|
import VideoMuteButton from '../VideoMuteButton';
|
|
23
|
23
|
|
|
24
|
24
|
/**
|
|
25
|
|
- * The number of buttons to render in {@link Toolbox}.
|
|
|
25
|
+ * The number of buttons other than {@link HangupButton} to render in
|
|
|
26
|
+ * {@link Toolbox}.
|
|
26
|
27
|
*
|
|
27
|
28
|
* @private
|
|
28
|
29
|
* @type number
|
|
|
@@ -84,62 +85,6 @@ class Toolbox extends Component<Props, State> {
|
|
84
|
85
|
this._onLayout = this._onLayout.bind(this);
|
|
85
|
86
|
}
|
|
86
|
87
|
|
|
87
|
|
- /**
|
|
88
|
|
- * Renders the toolbar. It will only be rendered if the {@code Toolbox} is
|
|
89
|
|
- * visible and we have already calculated the available width. This avoids
|
|
90
|
|
- * a weird effect in which the toolbar is displayed and then changes size.
|
|
91
|
|
- *
|
|
92
|
|
- * @returns {ReactElement}
|
|
93
|
|
- */
|
|
94
|
|
- _renderToolbar() {
|
|
95
|
|
- const { _visible } = this.props;
|
|
96
|
|
- const { width } = this.state;
|
|
97
|
|
-
|
|
98
|
|
- if (!_visible || !width) {
|
|
99
|
|
- return null;
|
|
100
|
|
- }
|
|
101
|
|
-
|
|
102
|
|
- let buttonStyles = toolbarButtonStyles;
|
|
103
|
|
- let toggledButtonStyles = toolbarToggledButtonStyles;
|
|
104
|
|
-
|
|
105
|
|
- const buttonSize = this._calculateButtonSize();
|
|
106
|
|
-
|
|
107
|
|
- if (buttonSize > 0) {
|
|
108
|
|
- const extraButtonStyle = {
|
|
109
|
|
- borderRadius: buttonSize / 2,
|
|
110
|
|
- height: buttonSize,
|
|
111
|
|
- width: buttonSize
|
|
112
|
|
- };
|
|
113
|
|
-
|
|
114
|
|
- buttonStyles = {
|
|
115
|
|
- ...buttonStyles,
|
|
116
|
|
- style: [ buttonStyles.style, extraButtonStyle ]
|
|
117
|
|
- };
|
|
118
|
|
- toggledButtonStyles = {
|
|
119
|
|
- ...toggledButtonStyles,
|
|
120
|
|
- style: [ toggledButtonStyles.style, extraButtonStyle ]
|
|
121
|
|
- };
|
|
122
|
|
- }
|
|
123
|
|
-
|
|
124
|
|
- return (
|
|
125
|
|
- <View
|
|
126
|
|
- pointerEvents = 'box-none'
|
|
127
|
|
- style = { styles.toolbar }>
|
|
128
|
|
- <InviteButton styles = { buttonStyles } />
|
|
129
|
|
- <AudioMuteButton
|
|
130
|
|
- styles = { buttonStyles }
|
|
131
|
|
- toggledStyles = { toggledButtonStyles } />
|
|
132
|
|
- <HangupButton styles = { hangupButtonStyles } />
|
|
133
|
|
- <VideoMuteButton
|
|
134
|
|
- styles = { buttonStyles }
|
|
135
|
|
- toggledStyles = { toggledButtonStyles } />
|
|
136
|
|
- <OverflowMenuButton
|
|
137
|
|
- styles = { buttonStyles }
|
|
138
|
|
- toggledStyles = { toggledButtonStyles } />
|
|
139
|
|
- </View>
|
|
140
|
|
- );
|
|
141
|
|
- }
|
|
142
|
|
-
|
|
143
|
88
|
/**
|
|
144
|
89
|
* Implements React's {@link Component#render()}.
|
|
145
|
90
|
*
|
|
|
@@ -151,13 +96,12 @@ class Toolbox extends Component<Props, State> {
|
|
151
|
96
|
= isNarrowAspectRatio(this)
|
|
152
|
97
|
? styles.toolboxNarrow
|
|
153
|
98
|
: styles.toolboxWide;
|
|
154
|
|
- const { _visible } = this.props;
|
|
155
|
99
|
|
|
156
|
100
|
return (
|
|
157
|
101
|
<Container
|
|
158
|
102
|
onLayout = { this._onLayout }
|
|
159
|
103
|
style = { toolboxStyle }
|
|
160
|
|
- visible = { _visible }>
|
|
|
104
|
+ visible = { this.props._visible }>
|
|
161
|
105
|
{ this._renderToolbar() }
|
|
162
|
106
|
</Container>
|
|
163
|
107
|
);
|
|
|
@@ -173,22 +117,37 @@ class Toolbox extends Component<Props, State> {
|
|
173
|
117
|
*/
|
|
174
|
118
|
_calculateButtonSize() {
|
|
175
|
119
|
const { width } = this.state;
|
|
176
|
|
- const hangupButtonSize = styles.hangupButton.width;
|
|
177
|
120
|
|
|
|
121
|
+ if (width <= 0) {
|
|
|
122
|
+ // We don't know how much space is allocated to the toolbar yet.
|
|
|
123
|
+ return width;
|
|
|
124
|
+ }
|
|
|
125
|
+
|
|
|
126
|
+ const hangupButtonSize = styles.hangupButton.width;
|
|
|
127
|
+ const { style } = toolbarButtonStyles;
|
|
178
|
128
|
let buttonSize
|
|
179
|
129
|
= (width
|
|
|
130
|
+
|
|
|
131
|
+ // Account for HangupButton without its margin which is not
|
|
|
132
|
+ // included in _BUTTON_COUNT:
|
|
180
|
133
|
- hangupButtonSize
|
|
181
|
|
- - (_BUTTON_COUNT
|
|
182
|
|
- * styles.toolbarButton.marginHorizontal * 2))
|
|
|
134
|
+
|
|
|
135
|
+ // Account for the horizontal margins of all buttons:
|
|
|
136
|
+ - ((_BUTTON_COUNT + 1) * style.marginHorizontal * 2))
|
|
183
|
137
|
/ _BUTTON_COUNT;
|
|
184
|
138
|
|
|
185
|
|
- // Make sure it's an even number.
|
|
186
|
|
- buttonSize = 2 * Math.round(buttonSize / 2);
|
|
|
139
|
+ // Well, don't return a non-positive button size.
|
|
|
140
|
+ if (buttonSize <= 0) {
|
|
|
141
|
+ buttonSize = style.width;
|
|
|
142
|
+ }
|
|
|
143
|
+
|
|
|
144
|
+ // The button should be at most _BUTTON_SIZE_FACTOR of the hangup
|
|
|
145
|
+ // button's size.
|
|
|
146
|
+ buttonSize
|
|
|
147
|
+ = Math.min(buttonSize, hangupButtonSize * _BUTTON_SIZE_FACTOR);
|
|
187
|
148
|
|
|
188
|
|
- // The button should be at most 80% of the hangup button's size.
|
|
189
|
|
- return Math.min(
|
|
190
|
|
- buttonSize,
|
|
191
|
|
- hangupButtonSize * _BUTTON_SIZE_FACTOR);
|
|
|
149
|
+ // Make sure it's an even number.
|
|
|
150
|
+ return 2 * Math.round(buttonSize / 2);
|
|
192
|
151
|
}
|
|
193
|
152
|
|
|
194
|
153
|
_onLayout: (Object) => void;
|
|
|
@@ -204,6 +163,66 @@ class Toolbox extends Component<Props, State> {
|
|
204
|
163
|
_onLayout({ nativeEvent: { layout: { width } } }) {
|
|
205
|
164
|
this.setState({ width });
|
|
206
|
165
|
}
|
|
|
166
|
+
|
|
|
167
|
+ /**
|
|
|
168
|
+ * Renders the toolbar. In order to avoid a weird visual effect in which the
|
|
|
169
|
+ * toolbar is (visually) rendered and then visibly changes its size, it is
|
|
|
170
|
+ * rendered only after we've figured out the width available to the toolbar.
|
|
|
171
|
+ *
|
|
|
172
|
+ * @returns {React$Node}
|
|
|
173
|
+ */
|
|
|
174
|
+ _renderToolbar() {
|
|
|
175
|
+ const buttonSize = this._calculateButtonSize();
|
|
|
176
|
+ let buttonStyles = toolbarButtonStyles;
|
|
|
177
|
+ let toggledButtonStyles = toolbarToggledButtonStyles;
|
|
|
178
|
+
|
|
|
179
|
+ if (buttonSize > 0) {
|
|
|
180
|
+ const extraButtonStyle = {
|
|
|
181
|
+ borderRadius: buttonSize / 2,
|
|
|
182
|
+ height: buttonSize,
|
|
|
183
|
+ width: buttonSize
|
|
|
184
|
+ };
|
|
|
185
|
+
|
|
|
186
|
+ // XXX The following width equality checks attempt to minimize
|
|
|
187
|
+ // unnecessary objects and possibly re-renders.
|
|
|
188
|
+ if (buttonStyles.style.width !== extraButtonStyle.width) {
|
|
|
189
|
+ buttonStyles = {
|
|
|
190
|
+ ...buttonStyles,
|
|
|
191
|
+ style: [ buttonStyles.style, extraButtonStyle ]
|
|
|
192
|
+ };
|
|
|
193
|
+ }
|
|
|
194
|
+ if (toggledButtonStyles.style.width !== extraButtonStyle.width) {
|
|
|
195
|
+ toggledButtonStyles = {
|
|
|
196
|
+ ...toggledButtonStyles,
|
|
|
197
|
+ style: [ toggledButtonStyles.style, extraButtonStyle ]
|
|
|
198
|
+ };
|
|
|
199
|
+ }
|
|
|
200
|
+ } else {
|
|
|
201
|
+ // XXX In order to avoid a weird visual effect in which the toolbar
|
|
|
202
|
+ // is (visually) rendered and then visibly changes its size, it is
|
|
|
203
|
+ // rendered only after we've figured out the width available to the
|
|
|
204
|
+ // toolbar.
|
|
|
205
|
+ return null;
|
|
|
206
|
+ }
|
|
|
207
|
+
|
|
|
208
|
+ return (
|
|
|
209
|
+ <View
|
|
|
210
|
+ pointerEvents = 'box-none'
|
|
|
211
|
+ style = { styles.toolbar }>
|
|
|
212
|
+ <InviteButton styles = { buttonStyles } />
|
|
|
213
|
+ <AudioMuteButton
|
|
|
214
|
+ styles = { buttonStyles }
|
|
|
215
|
+ toggledStyles = { toggledButtonStyles } />
|
|
|
216
|
+ <HangupButton styles = { hangupButtonStyles } />
|
|
|
217
|
+ <VideoMuteButton
|
|
|
218
|
+ styles = { buttonStyles }
|
|
|
219
|
+ toggledStyles = { toggledButtonStyles } />
|
|
|
220
|
+ <OverflowMenuButton
|
|
|
221
|
+ styles = { buttonStyles }
|
|
|
222
|
+ toggledStyles = { toggledButtonStyles } />
|
|
|
223
|
+ </View>
|
|
|
224
|
+ );
|
|
|
225
|
+ }
|
|
207
|
226
|
}
|
|
208
|
227
|
|
|
209
|
228
|
/**
|