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

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