Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

functions.web.ts 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { IReduxState } from '../app/types';
  2. import {
  3. ABSOLUTE_MAX_COLUMNS,
  4. DEFAULT_MAX_COLUMNS,
  5. TILE_PORTRAIT_ASPECT_RATIO
  6. } from '../filmstrip/constants';
  7. import {
  8. getNumberOfPartipantsForTileView,
  9. getThumbnailMinHeight,
  10. getTileDefaultAspectRatio
  11. } from '../filmstrip/functions.web';
  12. export * from './functions.any';
  13. /**
  14. * Returns how many columns should be displayed in tile view. The number
  15. * returned will be between 1 and 7, inclusive.
  16. *
  17. * @param {Object} state - The redux store state.
  18. * @param {Object} options - Object with custom values used to override the values that we get from redux by default.
  19. * @param {number} options.width - Custom width to be used.
  20. * @param {boolean} options.disableResponsiveTiles - Custom value to be used instead of config.disableResponsiveTiles.
  21. * @param {boolean} options.disableTileEnlargement - Custom value to be used instead of config.disableTileEnlargement.
  22. * @returns {number}
  23. */
  24. export function getMaxColumnCount(state: IReduxState, options: {
  25. disableResponsiveTiles?: boolean; disableTileEnlargement?: boolean; width?: number | null; } = {}) {
  26. if (typeof interfaceConfig === 'undefined') {
  27. return DEFAULT_MAX_COLUMNS;
  28. }
  29. const {
  30. disableResponsiveTiles: configDisableResponsiveTiles,
  31. disableTileEnlargement: configDisableTileEnlargement
  32. } = state['features/base/config'];
  33. const {
  34. width,
  35. disableResponsiveTiles = configDisableResponsiveTiles,
  36. disableTileEnlargement = configDisableTileEnlargement
  37. } = options;
  38. const { clientWidth } = state['features/base/responsive-ui'];
  39. const widthToUse = width || clientWidth;
  40. const configuredMax = interfaceConfig.TILE_VIEW_MAX_COLUMNS;
  41. if (disableResponsiveTiles) {
  42. return Math.min(Math.max(configuredMax || DEFAULT_MAX_COLUMNS, 1), ABSOLUTE_MAX_COLUMNS);
  43. }
  44. if (typeof interfaceConfig.TILE_VIEW_MAX_COLUMNS !== 'undefined' && interfaceConfig.TILE_VIEW_MAX_COLUMNS > 0) {
  45. return Math.max(configuredMax, 1);
  46. }
  47. const aspectRatio = disableTileEnlargement
  48. ? getTileDefaultAspectRatio(true, disableTileEnlargement, widthToUse)
  49. : TILE_PORTRAIT_ASPECT_RATIO;
  50. const minHeight = getThumbnailMinHeight(widthToUse);
  51. const minWidth = aspectRatio * minHeight;
  52. return Math.floor(widthToUse / minWidth);
  53. }
  54. /**
  55. * Returns the cell count dimensions for tile view. Tile view tries to uphold
  56. * equal count of tiles for height and width, until maxColumn is reached in
  57. * which rows will be added but no more columns.
  58. *
  59. * @param {Object} state - The redux store state.
  60. * @param {boolean} stageFilmstrip - Whether the dimensions should be calculated for the stage filmstrip.
  61. * @returns {Object} An object is return with the desired number of columns,
  62. * rows, and visible rows (the rest should overflow) for the tile view layout.
  63. */
  64. export function getNotResponsiveTileViewGridDimensions(state: IReduxState, stageFilmstrip = false) {
  65. const maxColumns = getMaxColumnCount(state);
  66. const { activeParticipants } = state['features/filmstrip'];
  67. const numberOfParticipants = stageFilmstrip ? activeParticipants.length : getNumberOfPartipantsForTileView(state);
  68. const columnsToMaintainASquare = Math.ceil(Math.sqrt(numberOfParticipants));
  69. const columns = Math.min(columnsToMaintainASquare, maxColumns);
  70. const rows = Math.ceil(numberOfParticipants / columns);
  71. const minVisibleRows = Math.min(maxColumns, rows);
  72. return {
  73. columns,
  74. minVisibleRows,
  75. rows
  76. };
  77. }