Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

reducer.ts 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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('features/base/responsive-ui', (state: IResponsiveUIState = DEFAULT_STATE, action) => {
  39. switch (action.type) {
  40. case CLIENT_RESIZED: {
  41. return {
  42. ...state,
  43. clientWidth: action.clientWidth,
  44. clientHeight: action.clientHeight
  45. };
  46. }
  47. case SAFE_AREA_INSETS_CHANGED:
  48. return {
  49. ...state,
  50. safeAreaInsets: action.insets
  51. };
  52. case SET_ASPECT_RATIO:
  53. return set(state, 'aspectRatio', action.aspectRatio);
  54. case SET_REDUCED_UI:
  55. return set(state, 'reducedUI', action.reducedUI);
  56. case SET_CONTEXT_MENU_OPEN:
  57. return set(state, 'contextMenuOpened', action.isOpen);
  58. }
  59. return state;
  60. });