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 2.7KB

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