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.

reducer.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // @flow
  2. import { ReducerRegistry, set } from '../redux';
  3. import {
  4. CLIENT_RESIZED,
  5. SAFE_AREA_INSETS_CHANGED,
  6. SET_ASPECT_RATIO,
  7. SET_CONTEXT_MENU_OPEN,
  8. SET_REDUCED_UI
  9. } from './actionTypes';
  10. import { ASPECT_RATIO_NARROW } from './constants';
  11. const {
  12. innerHeight = 0,
  13. innerWidth = 0
  14. } = window;
  15. /**
  16. * The default/initial redux state of the feature base/responsive-ui.
  17. */
  18. const DEFAULT_STATE = {
  19. aspectRatio: ASPECT_RATIO_NARROW,
  20. clientHeight: innerHeight,
  21. clientWidth: innerWidth,
  22. reducedUI: false,
  23. contextMenuOpened: false
  24. };
  25. ReducerRegistry.register('features/base/responsive-ui', (state = DEFAULT_STATE, action) => {
  26. switch (action.type) {
  27. case CLIENT_RESIZED: {
  28. return {
  29. ...state,
  30. clientWidth: action.clientWidth,
  31. clientHeight: action.clientHeight
  32. };
  33. }
  34. case SAFE_AREA_INSETS_CHANGED:
  35. return {
  36. ...state,
  37. safeAreaInsets: action.insets
  38. };
  39. case SET_ASPECT_RATIO:
  40. return set(state, 'aspectRatio', action.aspectRatio);
  41. case SET_REDUCED_UI:
  42. return set(state, 'reducedUI', action.reducedUI);
  43. case SET_CONTEXT_MENU_OPEN:
  44. return set(state, 'contextMenuOpened', action.isOpen);
  45. }
  46. return state;
  47. });