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.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 '../../participants-pane/theme.json';
  7. import { CLIENT_RESIZED, SET_ASPECT_RATIO, SET_REDUCED_UI } from './actionTypes';
  8. import { ASPECT_RATIO_NARROW, ASPECT_RATIO_WIDE } from './constants';
  9. /**
  10. * Size threshold for determining if we are in reduced UI mode or not.
  11. *
  12. * FIXME The logic to base {@code reducedUI} on a hardcoded width or height is
  13. * very brittle because it's completely disconnected from the UI which wants to
  14. * be rendered and, naturally, it broke on iPad where even the secondary Toolbar
  15. * didn't fit in the height. We do need to measure the actual UI at runtime and
  16. * determine whether and how to render it.
  17. */
  18. const REDUCED_UI_THRESHOLD = 300;
  19. /**
  20. * Indicates a resize of the window.
  21. *
  22. * @param {number} clientWidth - The width of the window.
  23. * @param {number} clientHeight - The height of the window.
  24. * @returns {Object}
  25. */
  26. export function clientResized(clientWidth: number, clientHeight: number) {
  27. return (dispatch: Dispatch<any>, getState: Function) => {
  28. let availableWidth = clientWidth;
  29. if (navigator.product !== 'ReactNative') {
  30. const state = getState();
  31. const { isOpen: isChatOpen } = state['features/chat'];
  32. const isParticipantsPaneOpen = getParticipantsPaneOpen(state);
  33. if (isChatOpen) {
  34. availableWidth -= CHAT_SIZE;
  35. }
  36. if (isParticipantsPaneOpen) {
  37. availableWidth -= theme.participantsPaneWidth;
  38. }
  39. }
  40. batch(() => {
  41. dispatch({
  42. type: CLIENT_RESIZED,
  43. clientHeight,
  44. clientWidth: availableWidth
  45. });
  46. dispatch(setAspectRatio(clientWidth, clientHeight));
  47. });
  48. };
  49. }
  50. /**
  51. * Sets the aspect ratio of the app's user interface based on specific width and
  52. * height.
  53. *
  54. * @param {number} width - The width of the app's user interface.
  55. * @param {number} height - The height of the app's user interface.
  56. * @returns {{
  57. * type: SET_ASPECT_RATIO,
  58. * aspectRatio: Symbol
  59. * }}
  60. */
  61. export function setAspectRatio(width: number, height: number): Function {
  62. return (dispatch: Dispatch<any>, getState: Function) => {
  63. // Don't change the aspect ratio if width and height are the same, that
  64. // is, if we transition to a 1:1 aspect ratio.
  65. if (width !== height) {
  66. const aspectRatio
  67. = width < height ? ASPECT_RATIO_NARROW : ASPECT_RATIO_WIDE;
  68. if (aspectRatio
  69. !== getState()['features/base/responsive-ui'].aspectRatio) {
  70. return dispatch({
  71. type: SET_ASPECT_RATIO,
  72. aspectRatio
  73. });
  74. }
  75. }
  76. };
  77. }
  78. /**
  79. * Sets the "reduced UI" property. In reduced UI mode some components will
  80. * be hidden if there is no space to render them.
  81. *
  82. * @param {number} width - Current usable width.
  83. * @param {number} height - Current usable height.
  84. * @returns {{
  85. * type: SET_REDUCED_UI,
  86. * reducedUI: boolean
  87. * }}
  88. */
  89. export function setReducedUI(width: number, height: number): Function {
  90. return (dispatch: Dispatch<any>, getState: Function) => {
  91. const reducedUI = Math.min(width, height) < REDUCED_UI_THRESHOLD;
  92. if (reducedUI !== getState()['features/base/responsive-ui'].reducedUI) {
  93. return dispatch({
  94. type: SET_REDUCED_UI,
  95. reducedUI
  96. });
  97. }
  98. };
  99. }