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.5KB

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