Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

actions.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // @flow
  2. import { batch } from 'react-redux';
  3. import type { Dispatch } from 'redux';
  4. import { CHAT_SIZE } from '../../chat/constants';
  5. import { getParticipantsPaneOpen } from '../../participants-pane/functions';
  6. import theme from '../components/themes/participantsPaneTheme.json';
  7. import {
  8. CLIENT_RESIZED,
  9. SAFE_AREA_INSETS_CHANGED,
  10. SET_ASPECT_RATIO,
  11. SET_CONTEXT_MENU_OPEN,
  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: Dispatch<any>, getState: Function) => {
  34. let availableWidth = clientWidth;
  35. if (navigator.product !== 'ReactNative') {
  36. const state = getState();
  37. const { isOpen: isChatOpen } = state['features/chat'];
  38. const isParticipantsPaneOpen = getParticipantsPaneOpen(state);
  39. if (isChatOpen) {
  40. availableWidth -= CHAT_SIZE;
  41. }
  42. if (isParticipantsPaneOpen) {
  43. availableWidth -= theme.participantsPaneWidth;
  44. }
  45. }
  46. batch(() => {
  47. dispatch({
  48. type: CLIENT_RESIZED,
  49. clientHeight,
  50. clientWidth: availableWidth
  51. });
  52. dispatch(setAspectRatio(clientWidth, clientHeight));
  53. });
  54. };
  55. }
  56. /**
  57. * Sets the aspect ratio of the app's user interface based on specific width and
  58. * height.
  59. *
  60. * @param {number} width - The width of the app's user interface.
  61. * @param {number} height - The height of the app's user interface.
  62. * @returns {{
  63. * type: SET_ASPECT_RATIO,
  64. * aspectRatio: Symbol
  65. * }}
  66. */
  67. export function setAspectRatio(width: number, height: number): Function {
  68. return (dispatch: Dispatch<any>, getState: Function) => {
  69. // Don't change the aspect ratio if width and height are the same, that
  70. // is, if we transition to a 1:1 aspect ratio.
  71. if (width !== height) {
  72. const aspectRatio
  73. = width < height ? ASPECT_RATIO_NARROW : ASPECT_RATIO_WIDE;
  74. if (aspectRatio
  75. !== getState()['features/base/responsive-ui'].aspectRatio) {
  76. return dispatch({
  77. type: SET_ASPECT_RATIO,
  78. aspectRatio
  79. });
  80. }
  81. }
  82. };
  83. }
  84. /**
  85. * Sets the "reduced UI" property. In reduced UI mode some components will
  86. * be hidden if there is no space to render them.
  87. *
  88. * @param {number} width - Current usable width.
  89. * @param {number} height - Current usable height.
  90. * @returns {{
  91. * type: SET_REDUCED_UI,
  92. * reducedUI: boolean
  93. * }}
  94. */
  95. export function setReducedUI(width: number, height: number): Function {
  96. return (dispatch: Dispatch<any>, getState: Function) => {
  97. const reducedUI = Math.min(width, height) < REDUCED_UI_THRESHOLD;
  98. if (reducedUI !== getState()['features/base/responsive-ui'].reducedUI) {
  99. return dispatch({
  100. type: SET_REDUCED_UI,
  101. reducedUI
  102. });
  103. }
  104. };
  105. }
  106. /**
  107. * Sets whether the local or remote participant context menu is open.
  108. *
  109. * @param {boolean} isOpen - Whether local or remote context menu is open.
  110. * @returns {Object}
  111. */
  112. export function setParticipantContextMenuOpen(isOpen: boolean) {
  113. return {
  114. type: SET_CONTEXT_MENU_OPEN,
  115. isOpen
  116. };
  117. }
  118. /**
  119. * Sets the insets from the SafeAreaProvider.
  120. *
  121. * @param {Object} insets - The new insets to be set.
  122. * @returns {{
  123. * type: SAFE_AREA_INSETS_CHANGED,
  124. * insets: Object
  125. * }}
  126. */
  127. export function setSafeAreaInsets(insets) {
  128. return {
  129. type: SAFE_AREA_INSETS_CHANGED,
  130. insets
  131. };
  132. }