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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // @flow
  2. import { SET_ASPECT_RATIO, SET_REDUCED_UI } from './actionTypes';
  3. import { ASPECT_RATIO_NARROW, ASPECT_RATIO_WIDE } from './constants';
  4. import type { Dispatch } from 'redux';
  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. I'm bumping from 240 to 300 because I
  13. * don't have the time now to refactor {@code ReducedUIDetector} or rip it out
  14. * completely.
  15. */
  16. const REDUCED_UI_THRESHOLD = 300;
  17. /**
  18. * Sets the aspect ratio of the app's user interface based on specific width and
  19. * height.
  20. *
  21. * @param {number} width - The width of the app's user interface.
  22. * @param {number} height - The height of the app's user interface.
  23. * @returns {{
  24. * type: SET_ASPECT_RATIO,
  25. * aspectRatio: Symbol
  26. * }}
  27. */
  28. export function setAspectRatio(width: number, height: number): Function {
  29. return (dispatch: Dispatch<*>, getState: Function) => {
  30. // Don't change the aspect ratio if width and height are the same, that
  31. // is, if we transition to a 1:1 aspect ratio.
  32. if (width !== height) {
  33. const aspectRatio
  34. = width < height ? ASPECT_RATIO_NARROW : ASPECT_RATIO_WIDE;
  35. if (aspectRatio
  36. !== getState()['features/base/responsive-ui'].aspectRatio) {
  37. return dispatch({
  38. type: SET_ASPECT_RATIO,
  39. aspectRatio
  40. });
  41. }
  42. }
  43. };
  44. }
  45. /**
  46. * Sets the "reduced UI" property. In reduced UI mode some components will
  47. * be hidden if there is no space to render them.
  48. *
  49. * @param {number} width - Current usable width.
  50. * @param {number} height - Current usable height.
  51. * @returns {{
  52. * type: SET_REDUCED_UI,
  53. * reducedUI: boolean
  54. * }}
  55. */
  56. export function setReducedUI(width: number, height: number): Function {
  57. return (dispatch: Dispatch<*>, getState: Function) => {
  58. const reducedUI = Math.min(width, height) < REDUCED_UI_THRESHOLD;
  59. if (reducedUI !== getState()['features/base/responsive-ui'].reducedUI) {
  60. return dispatch({
  61. type: SET_REDUCED_UI,
  62. reducedUI
  63. });
  64. }
  65. };
  66. }