You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import { batch } from 'react-redux';
  2. import { IStore } from '../../app/types';
  3. import { CHAT_SIZE } from '../../chat/constants';
  4. import { getParticipantsPaneOpen } from '../../participants-pane/functions';
  5. import theme from '../components/themes/participantsPaneTheme.json';
  6. import {
  7. CLIENT_RESIZED,
  8. SAFE_AREA_INSETS_CHANGED,
  9. SET_ASPECT_RATIO,
  10. SET_CONTEXT_MENU_OPEN,
  11. SET_REDUCED_UI
  12. } from './actionTypes';
  13. import { ASPECT_RATIO_NARROW, ASPECT_RATIO_WIDE } from './constants';
  14. /**
  15. * Size threshold for determining if we are in reduced UI mode or not.
  16. *
  17. * FIXME The logic to base {@code reducedUI} on a hardcoded width or height is
  18. * very brittle because it's completely disconnected from the UI which wants to
  19. * be rendered and, naturally, it broke on iPad where even the secondary Toolbar
  20. * didn't fit in the height. We do need to measure the actual UI at runtime and
  21. * determine whether and how to render it.
  22. */
  23. const REDUCED_UI_THRESHOLD = 300;
  24. /**
  25. * Indicates a resize of the window.
  26. *
  27. * @param {number} clientWidth - The width of the window.
  28. * @param {number} clientHeight - The height of the window.
  29. * @returns {Object}
  30. */
  31. export function clientResized(clientWidth: number, clientHeight: number) {
  32. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  33. let availableWidth = clientWidth;
  34. if (navigator.product !== 'ReactNative') {
  35. const state = getState();
  36. const { isOpen: isChatOpen } = state['features/chat'];
  37. const isParticipantsPaneOpen = getParticipantsPaneOpen(state);
  38. if (isChatOpen) {
  39. availableWidth -= CHAT_SIZE;
  40. }
  41. if (isParticipantsPaneOpen) {
  42. availableWidth -= theme.participantsPaneWidth;
  43. }
  44. }
  45. batch(() => {
  46. dispatch({
  47. type: CLIENT_RESIZED,
  48. clientHeight,
  49. clientWidth: availableWidth
  50. });
  51. dispatch(setAspectRatio(clientWidth, clientHeight));
  52. });
  53. };
  54. }
  55. /**
  56. * Sets the aspect ratio of the app's user interface based on specific width and
  57. * height.
  58. *
  59. * @param {number} width - The width of the app's user interface.
  60. * @param {number} height - The height of the app's user interface.
  61. * @returns {{
  62. * type: SET_ASPECT_RATIO,
  63. * aspectRatio: Symbol
  64. * }}
  65. */
  66. export function setAspectRatio(width: number, height: number) {
  67. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  68. // Don't change the aspect ratio if width and height are the same, that
  69. // is, if we transition to a 1:1 aspect ratio.
  70. if (width !== height) {
  71. const aspectRatio
  72. = width < height ? ASPECT_RATIO_NARROW : ASPECT_RATIO_WIDE;
  73. if (aspectRatio
  74. !== getState()['features/base/responsive-ui'].aspectRatio) {
  75. return dispatch({
  76. type: SET_ASPECT_RATIO,
  77. aspectRatio
  78. });
  79. }
  80. }
  81. };
  82. }
  83. /**
  84. * Sets the "reduced UI" property. In reduced UI mode some components will
  85. * be hidden if there is no space to render them.
  86. *
  87. * @param {number} width - Current usable width.
  88. * @param {number} height - Current usable height.
  89. * @returns {{
  90. * type: SET_REDUCED_UI,
  91. * reducedUI: boolean
  92. * }}
  93. */
  94. export function setReducedUI(width: number, height: number) {
  95. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  96. const reducedUI = Math.min(width, height) < REDUCED_UI_THRESHOLD;
  97. if (reducedUI !== getState()['features/base/responsive-ui'].reducedUI) {
  98. return dispatch({
  99. type: SET_REDUCED_UI,
  100. reducedUI
  101. });
  102. }
  103. };
  104. }
  105. /**
  106. * Sets whether the local or remote participant context menu is open.
  107. *
  108. * @param {boolean} isOpen - Whether local or remote context menu is open.
  109. * @returns {Object}
  110. */
  111. export function setParticipantContextMenuOpen(isOpen: boolean) {
  112. return {
  113. type: SET_CONTEXT_MENU_OPEN,
  114. isOpen
  115. };
  116. }
  117. /**
  118. * Sets the insets from the SafeAreaProvider.
  119. *
  120. * @param {Object} insets - The new insets to be set.
  121. * @returns {{
  122. * type: SAFE_AREA_INSETS_CHANGED,
  123. * insets: Object
  124. * }}
  125. */
  126. export function setSafeAreaInsets(insets: Object) {
  127. return {
  128. type: SAFE_AREA_INSETS_CHANGED,
  129. insets
  130. };
  131. }