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
 
20
 
21
 import styles from './styles';
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
  * The type of the React {@code Component} props of {@link Conference}.
24
  * The type of the React {@code Component} props of {@link Conference}.
33
  */
25
  */
68
      */
60
      */
69
     _onHardwareBackPress: Function,
61
     _onHardwareBackPress: Function,
70
 
62
 
63
+    /**
64
+     * Number of participants in the conference.
65
+     *
66
+     * @private
67
+     */
68
+    _participantCount: number,
69
+
71
     /**
70
     /**
72
      * The indicator which determines whether the UI is reduced (to accommodate
71
      * The indicator which determines whether the UI is reduced (to accommodate
73
      * smaller display areas).
72
      * smaller display areas).
98
 class Conference extends Component<Props> {
97
 class Conference extends Component<Props> {
99
     _backHandler: ?BackHandler;
98
     _backHandler: ?BackHandler;
100
 
99
 
101
-    _toolboxTimeout: ?number;
102
-
103
     /**
100
     /**
104
      * Initializes a new Conference instance.
101
      * Initializes a new Conference instance.
105
      *
102
      *
109
     constructor(props) {
106
     constructor(props) {
110
         super(props);
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
         // Bind event handlers so they are only bound once per instance.
109
         // Bind event handlers so they are only bound once per instance.
122
         this._onClick = this._onClick.bind(this);
110
         this._onClick = this._onClick.bind(this);
123
         this._onHardwareBackPress = this._onHardwareBackPress.bind(this);
111
         this._onHardwareBackPress = this._onHardwareBackPress.bind(this);
141
                 this._onHardwareBackPress);
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
         this.props._onConnect();
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
      * Implements {@link Component#componentWillUnmount()}. Invoked immediately
174
      * Implements {@link Component#componentWillUnmount()}. Invoked immediately
161
      * before this component is unmounted and destroyed. Disconnects the
175
      * before this component is unmounted and destroyed. Disconnects the
175
                 this._onHardwareBackPress);
189
                 this._onHardwareBackPress);
176
         }
190
         }
177
 
191
 
178
-        this._clearToolboxTimeout();
179
-
180
         this.props._onDisconnect();
192
         this.props._onDisconnect();
181
     }
193
     }
182
 
194
 
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
     _onClick: () => void;
262
     _onClick: () => void;
264
 
263
 
265
     /**
264
     /**
273
         const toolboxVisible = !this.props._toolboxVisible;
272
         const toolboxVisible = !this.props._toolboxVisible;
274
 
273
 
275
         this.props._setToolboxVisible(toolboxVisible);
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
     _onHardwareBackPress: () => boolean;
277
     _onHardwareBackPress: () => boolean;
306
             ? <ConferenceNotification />
301
             ? <ConferenceNotification />
307
             : undefined;
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
     const { connecting, connection } = state['features/base/connection'];
381
     const { connecting, connection } = state['features/base/connection'];
403
     const { conference, joining, leaving } = state['features/base/conference'];
382
     const { conference, joining, leaving } = state['features/base/conference'];
404
     const { reducedUI } = state['features/base/responsive-ui'];
383
     const { reducedUI } = state['features/base/responsive-ui'];
384
+    const participants = state['features/base/participants'];
405
 
385
 
406
     // XXX There is a window of time between the successful establishment of the
386
     // XXX There is a window of time between the successful establishment of the
407
     // XMPP connection and the subsequent commencement of joining the MUC during
387
     // XMPP connection and the subsequent commencement of joining the MUC during
427
          */
407
          */
428
         _connecting: Boolean(connecting_),
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
          * The indicator which determines whether the UI is reduced (to
419
          * The indicator which determines whether the UI is reduced (to
432
          * accommodate smaller display areas).
420
          * accommodate smaller display areas).

Loading…
Cancel
Save