Browse Source

[RN] Show / hide the toolbox based on the participant count

Show it if we are the only participant, and hide it the moment someone else
joins the conference.
master
Saúl Ibarra Corretgé 7 years ago
parent
commit
5bd975e3f3
1 changed files with 43 additions and 55 deletions
  1. 43
    55
      react/features/conference/components/Conference.native.js

+ 43
- 55
react/features/conference/components/Conference.native.js View File

@@ -20,14 +20,6 @@ import { setToolboxVisible, Toolbox } from '../../toolbox';
20 20
 
21 21
 import styles from './styles';
22 22
 
23
-/**
24
- * The timeout in milliseconds after which the Toolbox will be hidden.
25
- *
26
- * @private
27
- * @type {number}
28
- */
29
-const _TOOLBOX_TIMEOUT_MS = 5000;
30
-
31 23
 /**
32 24
  * The type of the React {@code Component} props of {@link Conference}.
33 25
  */
@@ -68,6 +60,13 @@ type Props = {
68 60
      */
69 61
     _onHardwareBackPress: Function,
70 62
 
63
+    /**
64
+     * Number of participants in the conference.
65
+     *
66
+     * @private
67
+     */
68
+    _participantCount: number,
69
+
71 70
     /**
72 71
      * The indicator which determines whether the UI is reduced (to accommodate
73 72
      * smaller display areas).
@@ -98,8 +97,6 @@ type Props = {
98 97
 class Conference extends Component<Props> {
99 98
     _backHandler: ?BackHandler;
100 99
 
101
-    _toolboxTimeout: ?number;
102
-
103 100
     /**
104 101
      * Initializes a new Conference instance.
105 102
      *
@@ -109,15 +106,6 @@ class Conference extends Component<Props> {
109 106
     constructor(props) {
110 107
         super(props);
111 108
 
112
-        /**
113
-         * The numerical ID of the timeout in milliseconds after which the
114
-         * Toolbox will be hidden. To be used with
115
-         * {@link WindowTimers#clearTimeout()}.
116
-         *
117
-         * @private
118
-         */
119
-        this._toolboxTimeout = undefined;
120
-
121 109
         // Bind event handlers so they are only bound once per instance.
122 110
         this._onClick = this._onClick.bind(this);
123 111
         this._onHardwareBackPress = this._onHardwareBackPress.bind(this);
@@ -141,7 +129,12 @@ class Conference extends Component<Props> {
141 129
                 this._onHardwareBackPress);
142 130
         }
143 131
 
144
-        this._setToolboxTimeout(this.props._toolboxVisible);
132
+        // Show the toolbar if we are the only participant.
133
+        const { _participantCount, _setToolboxVisible } = this.props;
134
+
135
+        if (_participantCount === 1) {
136
+            _setToolboxVisible(true);
137
+        }
145 138
     }
146 139
 
147 140
     /**
@@ -156,6 +149,27 @@ class Conference extends Component<Props> {
156 149
         this.props._onConnect();
157 150
     }
158 151
 
152
+    /**
153
+     * Notifies this mounted React {@code Component} that it will receive new
154
+     * props. Check if we need to show / hide the toolbox based on the
155
+     * participant count.
156
+     *
157
+     * @inheritdoc
158
+     * @param {Object} nextProps - The read-only React {@code Component} props
159
+     * that this instance will receive.
160
+     * @returns {void}
161
+     */
162
+    componentWillReceiveProps(nextProps) {
163
+        const oldParticipantCount = this.props._participantCount;
164
+        const newParticipantCount = nextProps._participantCount;
165
+
166
+        if (oldParticipantCount === 1 && newParticipantCount > 1) {
167
+            this.props._setToolboxVisible(false);
168
+        } else if (oldParticipantCount > 1 && newParticipantCount === 1) {
169
+            this.props._setToolboxVisible(true);
170
+        }
171
+    }
172
+
159 173
     /**
160 174
      * Implements {@link Component#componentWillUnmount()}. Invoked immediately
161 175
      * before this component is unmounted and destroyed. Disconnects the
@@ -175,8 +189,6 @@ class Conference extends Component<Props> {
175 189
                 this._onHardwareBackPress);
176 190
         }
177 191
 
178
-        this._clearToolboxTimeout();
179
-
180 192
         this.props._onDisconnect();
181 193
     }
182 194
 
@@ -247,19 +259,6 @@ class Conference extends Component<Props> {
247 259
         );
248 260
     }
249 261
 
250
-    /**
251
-     * Clears {@link #_toolboxTimeout} if any.
252
-     *
253
-     * @private
254
-     * @returns {void}
255
-     */
256
-    _clearToolboxTimeout() {
257
-        if (this._toolboxTimeout) {
258
-            clearTimeout(this._toolboxTimeout);
259
-            this._toolboxTimeout = undefined;
260
-        }
261
-    }
262
-
263 262
     _onClick: () => void;
264 263
 
265 264
     /**
@@ -273,10 +272,6 @@ class Conference extends Component<Props> {
273 272
         const toolboxVisible = !this.props._toolboxVisible;
274 273
 
275 274
         this.props._setToolboxVisible(toolboxVisible);
276
-
277
-        // XXX If the user taps to toggle the visibility of the Toolbox, then no
278
-        // automatic toggling of the visibility should happen.
279
-        this._clearToolboxTimeout();
280 275
     }
281 276
 
282 277
     _onHardwareBackPress: () => boolean;
@@ -306,22 +301,6 @@ class Conference extends Component<Props> {
306 301
             ? <ConferenceNotification />
307 302
             : undefined;
308 303
     }
309
-
310
-    /**
311
-     * Triggers the default Toolbox timeout.
312
-     *
313
-     * @param {boolean} toolboxVisible - Indicates whether the Toolbox is
314
-     * currently visible.
315
-     * @private
316
-     * @returns {void}
317
-     */
318
-    _setToolboxTimeout(toolboxVisible) {
319
-        this._clearToolboxTimeout();
320
-        if (toolboxVisible) {
321
-            this._toolboxTimeout
322
-                = setTimeout(this._onClick, _TOOLBOX_TIMEOUT_MS);
323
-        }
324
-    }
325 304
 }
326 305
 
327 306
 /**
@@ -402,6 +381,7 @@ function _mapStateToProps(state) {
402 381
     const { connecting, connection } = state['features/base/connection'];
403 382
     const { conference, joining, leaving } = state['features/base/conference'];
404 383
     const { reducedUI } = state['features/base/responsive-ui'];
384
+    const participants = state['features/base/participants'];
405 385
 
406 386
     // XXX There is a window of time between the successful establishment of the
407 387
     // XMPP connection and the subsequent commencement of joining the MUC during
@@ -427,6 +407,14 @@ function _mapStateToProps(state) {
427 407
          */
428 408
         _connecting: Boolean(connecting_),
429 409
 
410
+        /**
411
+         * Number of participants in the conference.
412
+         *
413
+         * @private
414
+         * @type {number}
415
+         */
416
+        _participantCount: participants.length,
417
+
430 418
         /**
431 419
          * The indicator which determines whether the UI is reduced (to
432 420
          * accommodate smaller display areas).

Loading…
Cancel
Save