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.

actions.ts 4.7KB

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