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

123456789101112131415161718192021222324252627282930313233343536
  1. // @flow
  2. import { SET_ASPECT_RATIO } from './actionTypes';
  3. import { ASPECT_RATIO_NARROW, ASPECT_RATIO_WIDE } from './constants';
  4. import type { Dispatch } from 'redux';
  5. /**
  6. * Sets the aspect ratio of the app's user interface based on specific width and
  7. * height.
  8. *
  9. * @param {number} width - The width of the app's user interface.
  10. * @param {number} height - The height of the app's user interface.
  11. * @returns {{
  12. * type: SET_ASPECT_RATIO,
  13. * aspectRatio: Symbol
  14. * }}
  15. */
  16. export function setAspectRatio(width: number, height: number): Object {
  17. return (dispatch: Dispatch<*>, getState: Function) => {
  18. // Don't change the aspect ratio if width and height are the same, that
  19. // is, if we transition to a 1:1 aspect ratio.
  20. if (width !== height) {
  21. const aspectRatio
  22. = width < height ? ASPECT_RATIO_NARROW : ASPECT_RATIO_WIDE;
  23. if (aspectRatio
  24. !== getState()['features/base/responsive-ui'].aspectRatio) {
  25. return dispatch({
  26. type: SET_ASPECT_RATIO,
  27. aspectRatio
  28. });
  29. }
  30. }
  31. };
  32. }