Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

functions.web.ts 3.5KB

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