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

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