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

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