Sfoglia il codice sorgente

feat(tile-vew): Calculate maxColumns dynamically

master
Hristo Terezov 3 anni fa
parent
commit
221ecac12d

+ 13
- 7
react/features/filmstrip/actions.web.js Vedi File

@@ -83,14 +83,15 @@ export function setTileViewDimensions() {
83 83
                 disableTileEnlargement,
84 84
                 maxColumns,
85 85
                 numberOfParticipants,
86
-                numberOfVisibleTiles
86
+                desiredNumberOfVisibleTiles: numberOfVisibleTiles
87 87
             });
88 88
         const thumbnailsTotalHeight = rows * (TILE_VERTICAL_MARGIN + height);
89
-        const hasScroll = clientHeight < thumbnailsTotalHeight;
89
+        const availableHeight = clientHeight - TILE_VIEW_GRID_VERTICAL_MARGIN;
90
+        const hasScroll = availableHeight < thumbnailsTotalHeight;
90 91
         const filmstripWidth
91 92
             = Math.min(clientWidth - TILE_VIEW_GRID_HORIZONTAL_MARGIN, columns * (TILE_HORIZONTAL_MARGIN + width))
92 93
                 + (hasScroll ? SCROLL_SIZE : 0);
93
-        const filmstripHeight = Math.min(clientHeight - TILE_VIEW_GRID_VERTICAL_MARGIN, thumbnailsTotalHeight);
94
+        const filmstripHeight = Math.min(availableHeight, thumbnailsTotalHeight);
94 95
 
95 96
         dispatch({
96 97
             type: SET_TILE_VIEW_DIMENSIONS,
@@ -139,7 +140,11 @@ export function setVerticalViewDimensions() {
139 140
             const { tileView = {} } = state['features/base/config'];
140 141
             const { numberOfVisibleTiles = TILE_VIEW_DEFAULT_NUMBER_OF_VISIBLE_TILES } = tileView;
141 142
             const numberOfParticipants = getNumberOfPartipantsForTileView(state);
142
-            const maxColumns = getMaxColumnCount(state);
143
+            const maxColumns = getMaxColumnCount(state, {
144
+                width: filmstripWidth.current,
145
+                disableResponsiveTiles: false,
146
+                disableTileEnlargement: false
147
+            });
143 148
             const {
144 149
                 height,
145 150
                 width,
@@ -152,7 +157,7 @@ export function setVerticalViewDimensions() {
152 157
                 maxColumns,
153 158
                 noHorizontalContainerMargin: true,
154 159
                 numberOfParticipants,
155
-                numberOfVisibleTiles
160
+                desiredNumberOfVisibleTiles: numberOfVisibleTiles
156 161
             });
157 162
             const thumbnailsTotalHeight = rows * (TILE_VERTICAL_MARGIN + height);
158 163
 
@@ -269,7 +274,8 @@ export function setStageFilmstripViewDimensions() {
269 274
         const verticalWidth = visible ? getVerticalViewMaxWidth(state) : 0;
270 275
         const { numberOfVisibleTiles = MAX_ACTIVE_PARTICIPANTS } = tileView;
271 276
         const numberOfParticipants = state['features/filmstrip'].activeParticipants.length;
272
-        const maxColumns = getMaxColumnCount(state);
277
+        const availableWidth = clientWidth - verticalWidth;
278
+        const maxColumns = getMaxColumnCount(state, { width: availableWidth });
273 279
 
274 280
         const {
275 281
             height,
@@ -279,7 +285,7 @@ export function setStageFilmstripViewDimensions() {
279 285
         } = disableResponsiveTiles
280 286
             ? calculateNonResponsiveTileViewDimensions(state, true)
281 287
             : calculateResponsiveTileViewDimensions({
282
-                clientWidth: clientWidth - verticalWidth,
288
+                clientWidth: availableWidth,
283 289
                 clientHeight,
284 290
                 disableTileEnlargement,
285 291
                 maxColumns,

+ 53
- 37
react/features/filmstrip/functions.web.js Vedi File

@@ -297,7 +297,7 @@ export function calculateResponsiveTileViewDimensions({
297 297
     noHorizontalContainerMargin = false,
298 298
     maxColumns,
299 299
     numberOfParticipants,
300
-    numberOfVisibleTiles = TILE_VIEW_DEFAULT_NUMBER_OF_VISIBLE_TILES
300
+    desiredNumberOfVisibleTiles = TILE_VIEW_DEFAULT_NUMBER_OF_VISIBLE_TILES
301 301
 }) {
302 302
     let height, width;
303 303
     let columns, rows;
@@ -311,12 +311,12 @@ export function calculateResponsiveTileViewDimensions({
311 311
         maxArea: 0
312 312
     };
313 313
 
314
-    for (let c = 1; c <= Math.min(maxColumns, numberOfParticipants); c++) {
314
+    for (let c = 1; c <= Math.min(maxColumns, numberOfParticipants, desiredNumberOfVisibleTiles); c++) {
315 315
         const r = Math.ceil(numberOfParticipants / c);
316 316
 
317
-        // we want to display as much as possible tumbnails up to numberOfVisibleTiles
317
+        // we want to display as much as possible tumbnails up to desiredNumberOfVisibleTiles
318 318
         const visibleRows
319
-            = numberOfParticipants <= numberOfVisibleTiles ? r : Math.floor(numberOfVisibleTiles / c);
319
+            = numberOfParticipants <= desiredNumberOfVisibleTiles ? r : Math.floor(desiredNumberOfVisibleTiles / c);
320 320
 
321 321
         const size = calculateThumbnailSizeForTileView({
322 322
             columns: c,
@@ -330,18 +330,38 @@ export function calculateResponsiveTileViewDimensions({
330 330
 
331 331
         if (size) {
332 332
             const { height: currentHeight, width: currentWidth, minHeightEnforced, maxVisibleRows } = size;
333
-            let area = currentHeight * currentWidth * Math.min(c * maxVisibleRows, numberOfParticipants);
333
+            const numberOfVisibleParticipants = Math.min(c * maxVisibleRows, numberOfParticipants);
334
+
335
+            let area = Math.round(
336
+                (currentHeight + TILE_VERTICAL_MARGIN)
337
+                * (currentWidth + TILE_HORIZONTAL_MARGIN)
338
+                * numberOfVisibleParticipants);
339
+
334 340
             const currentDimensions = {
335 341
                 maxArea: area,
336 342
                 height: currentHeight,
337 343
                 width: currentWidth,
338 344
                 columns: c,
339
-                rows: r
345
+                rows: r,
346
+                numberOfVisibleParticipants
340 347
             };
341
-
342
-            if (!minHeightEnforced && area > dimensions.maxArea) {
343
-                dimensions = currentDimensions;
344
-            } else if (minHeightEnforced && area > minHeightEnforcedDimensions.maxArea) {
348
+            const { numberOfVisibleParticipants: oldNumberOfVisibleParticipants = 0 } = dimensions;
349
+
350
+            if (!minHeightEnforced) {
351
+                if (area > dimensions.maxArea) {
352
+                    dimensions = currentDimensions;
353
+                } else if ((area === dimensions.maxArea)
354
+                    && ((oldNumberOfVisibleParticipants > desiredNumberOfVisibleTiles
355
+                            && oldNumberOfVisibleParticipants >= numberOfParticipants)
356
+                        || (oldNumberOfVisibleParticipants < numberOfParticipants
357
+                            && numberOfVisibleParticipants <= desiredNumberOfVisibleTiles))
358
+                ) { // If the area of the new candidates and the old ones are equal we preffer the one that will have
359
+                    // closer number of visible participants to desiredNumberOfVisibleTiles config.
360
+                    dimensions = currentDimensions;
361
+                }
362
+            } else if (minHeightEnforced && area >= minHeightEnforcedDimensions.maxArea) {
363
+                // If we choose configuration with minHeightEnforced there will be less than desiredNumberOfVisibleTiles
364
+                // visible tiles, that's why we prefer more columns when the area is the same.
345 365
                 minHeightEnforcedDimensions = currentDimensions;
346 366
             } else if (minHeightEnforced && maxVisibleRows === 0) {
347 367
                 area = currentHeight * currentWidth * Math.min(c, numberOfParticipants);
@@ -400,7 +420,8 @@ export function calculateThumbnailSizeForTileView({
400 420
     const minHeight = getThumbnailMinHeight(clientWidth);
401 421
     const viewWidth = clientWidth - (columns * TILE_HORIZONTAL_MARGIN)
402 422
         - (noHorizontalContainerMargin ? SCROLL_SIZE : TILE_VIEW_GRID_HORIZONTAL_MARGIN);
403
-    const viewHeight = clientHeight - (minVisibleRows * TILE_VERTICAL_MARGIN) - TILE_VIEW_GRID_VERTICAL_MARGIN;
423
+    const availableHeight = clientHeight - TILE_VIEW_GRID_VERTICAL_MARGIN;
424
+    const viewHeight = availableHeight - (minVisibleRows * TILE_VERTICAL_MARGIN);
404 425
     const initialWidth = viewWidth / columns;
405 426
     let initialHeight = viewHeight / minVisibleRows;
406 427
     let minHeightEnforced = false;
@@ -417,52 +438,47 @@ export function calculateThumbnailSizeForTileView({
417 438
             return;
418 439
         }
419 440
 
420
-        const height = Math.floor(Math.min(aspectRatioHeight, initialHeight));
441
+        const height = Math.min(aspectRatioHeight, initialHeight);
421 442
 
422 443
         return {
423 444
             height,
424
-            width: Math.floor(aspectRatio * height),
445
+            width: aspectRatio * height,
425 446
             minHeightEnforced,
426
-            maxVisibleRows: Math.floor(viewHeight / height)
447
+            maxVisibleRows: Math.floor(availableHeight / (height + TILE_VERTICAL_MARGIN))
427 448
         };
428 449
     }
429 450
 
430 451
     const initialRatio = initialWidth / initialHeight;
431
-    let height = Math.floor(initialHeight);
452
+    let height = initialHeight;
453
+    let width;
432 454
 
433 455
     // The biggest area of the grid will be when the grid's height is equal to clientHeight or when the grid's width is
434 456
     // equal to clientWidth.
435 457
 
436 458
     if (initialRatio > aspectRatio) {
437
-        return {
438
-            height,
439
-            width: Math.floor(initialHeight * aspectRatio),
440
-            minHeightEnforced,
441
-            maxVisibleRows: Math.floor(viewHeight / height)
442
-        };
459
+        width = initialHeight * aspectRatio;
443 460
     } else if (initialRatio >= TILE_PORTRAIT_ASPECT_RATIO) {
444
-        return {
445
-            height,
446
-            width: Math.floor(initialWidth),
447
-            minHeightEnforced,
448
-            maxVisibleRows: Math.floor(viewHeight / height)
449
-        };
461
+        width = initialWidth;
462
+    // eslint-disable-next-line no-negated-condition
450 463
     } else if (!minHeightEnforced) {
451
-        height = Math.floor(initialWidth / TILE_PORTRAIT_ASPECT_RATIO);
464
+        height = initialWidth / TILE_PORTRAIT_ASPECT_RATIO;
452 465
 
453 466
         if (height >= minHeight) {
454
-            return {
455
-                height,
456
-                width: Math.floor(initialWidth),
457
-                minHeightEnforced,
458
-                maxVisibleRows: Math.floor(viewHeight / height)
459
-            };
467
+            width = initialWidth;
468
+        } else { // The width is so small that we can't reach the minimum height with portrait aspect ratio.
469
+            return;
460 470
         }
471
+    } else {
472
+        // We can't fit that number of columns with the desired min height and aspect ratio.
473
+        return;
461 474
     }
462 475
 
463
-    // else
464
-    // We can't fit that number of columns with the desired min height and aspect ratio.
465
-    return;
476
+    return {
477
+        height,
478
+        width,
479
+        minHeightEnforced,
480
+        maxVisibleRows: Math.floor(availableHeight / (height + TILE_VERTICAL_MARGIN))
481
+    };
466 482
 }
467 483
 
468 484
 /**

+ 43
- 8
react/features/video-layout/functions.js Vedi File

@@ -9,9 +9,14 @@ import {
9 9
 } from '../base/participants';
10 10
 import {
11 11
     DEFAULT_MAX_COLUMNS,
12
-    ABSOLUTE_MAX_COLUMNS
12
+    ABSOLUTE_MAX_COLUMNS,
13
+    TILE_PORTRAIT_ASPECT_RATIO
13 14
 } from '../filmstrip/constants';
14
-import { getNumberOfPartipantsForTileView } from '../filmstrip/functions.web';
15
+import {
16
+    getNumberOfPartipantsForTileView,
17
+    getThumbnailMinHeight,
18
+    getTileDefaultAspectRatio
19
+} from '../filmstrip/functions.web';
15 20
 import { isVideoPlaying } from '../shared-video/functions';
16 21
 import { VIDEO_QUALITY_LEVELS } from '../video-quality/constants';
17 22
 
@@ -56,15 +61,45 @@ export function getCurrentLayout(state: Object) {
56 61
  * returned will be between 1 and 7, inclusive.
57 62
  *
58 63
  * @param {Object} state - The redux store state.
59
- * @param {number} width - Custom width to use for calculation.
64
+ * @param {Object} options - Object with custom values used to override the values that we get from redux by default.
65
+ * @param {number} options.width - Custom width to be used.
66
+ * @param {boolean} options.disableResponsiveTiles - Custom value to be used instead of config.disableResponsiveTiles.
67
+ * @param {boolean} options.disableTileEnlargement - Custom value to be used instead of config.disableTileEnlargement.
60 68
  * @returns {number}
61 69
  */
62
-export function getMaxColumnCount() {
63
-    const configuredMax = (typeof interfaceConfig === 'undefined'
64
-        ? DEFAULT_MAX_COLUMNS
65
-        : interfaceConfig.TILE_VIEW_MAX_COLUMNS) || DEFAULT_MAX_COLUMNS;
70
+export function getMaxColumnCount(state, options = {}) {
71
+    if (typeof interfaceConfig === 'undefined') {
72
+        return DEFAULT_MAX_COLUMNS;
73
+    }
74
+
75
+    const {
76
+        disableResponsiveTiles: configDisableResponsiveTiles,
77
+        disableTileEnlargement: configDisableTileEnlargement
78
+    } = state['features/base/config'];
79
+    const {
80
+        width,
81
+        disableResponsiveTiles = configDisableResponsiveTiles,
82
+        disableTileEnlargement = configDisableTileEnlargement
83
+    } = options;
84
+    const { clientWidth } = state['features/base/responsive-ui'];
85
+    const widthToUse = width || clientWidth;
86
+    const configuredMax = interfaceConfig.TILE_VIEW_MAX_COLUMNS;
87
+
88
+    if (disableResponsiveTiles) {
89
+        return Math.min(Math.max(configuredMax || DEFAULT_MAX_COLUMNS, 1), ABSOLUTE_MAX_COLUMNS);
90
+    }
91
+
92
+    if (typeof interfaceConfig.TILE_VIEW_MAX_COLUMNS !== 'undefined' && interfaceConfig.TILE_VIEW_MAX_COLUMNS > 0) {
93
+        return Math.max(configuredMax, 1);
94
+    }
95
+
96
+    const aspectRatio = disableTileEnlargement
97
+        ? getTileDefaultAspectRatio(true, disableTileEnlargement, widthToUse)
98
+        : TILE_PORTRAIT_ASPECT_RATIO;
99
+    const minHeight = getThumbnailMinHeight(widthToUse);
100
+    const minWidth = aspectRatio * minHeight;
66 101
 
67
-    return Math.min(Math.max(configuredMax, 1), ABSOLUTE_MAX_COLUMNS);
102
+    return Math.floor(widthToUse / minWidth);
68 103
 }
69 104
 
70 105
 /**

Loading…
Annulla
Salva