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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import ReducerRegistry from '../redux/ReducerRegistry';
  2. import { set } from '../redux/functions';
  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. export interface IResponsiveUIState {
  26. aspectRatio: Symbol;
  27. clientHeight: number;
  28. clientWidth: number;
  29. contextMenuOpened: boolean;
  30. reducedUI: boolean;
  31. safeAreaInsets?: {
  32. bottom: number;
  33. left: number;
  34. right: number;
  35. top: number;
  36. };
  37. }
  38. ReducerRegistry.register<IResponsiveUIState>('features/base/responsive-ui',
  39. (state = DEFAULT_STATE, action): IResponsiveUIState => {
  40. switch (action.type) {
  41. case CLIENT_RESIZED: {
  42. return {
  43. ...state,
  44. clientWidth: action.clientWidth,
  45. clientHeight: action.clientHeight
  46. };
  47. }
  48. case SAFE_AREA_INSETS_CHANGED:
  49. return {
  50. ...state,
  51. safeAreaInsets: action.insets
  52. };
  53. case SET_ASPECT_RATIO:
  54. return set(state, 'aspectRatio', action.aspectRatio);
  55. case SET_REDUCED_UI:
  56. return set(state, 'reducedUI', action.reducedUI);
  57. case SET_CONTEXT_MENU_OPEN:
  58. return set(state, 'contextMenuOpened', action.isOpen);
  59. }
  60. return state;
  61. });