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

reducer.ts 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_NARROW_LAYOUT,
  9. SET_REDUCED_UI
  10. } from './actionTypes';
  11. import { ASPECT_RATIO_NARROW } from './constants';
  12. const {
  13. innerHeight = 0,
  14. innerWidth = 0
  15. } = window;
  16. /**
  17. * The default/initial redux state of the feature base/responsive-ui.
  18. */
  19. const DEFAULT_STATE = {
  20. aspectRatio: ASPECT_RATIO_NARROW,
  21. clientHeight: innerHeight,
  22. clientWidth: innerWidth,
  23. isNarrowLayout: false,
  24. reducedUI: false,
  25. contextMenuOpened: false
  26. };
  27. export interface IResponsiveUIState {
  28. aspectRatio: Symbol;
  29. clientHeight: number;
  30. clientWidth: number;
  31. contextMenuOpened: boolean;
  32. isNarrowLayout: boolean;
  33. reducedUI: boolean;
  34. safeAreaInsets?: {
  35. bottom: number;
  36. left: number;
  37. right: number;
  38. top: number;
  39. };
  40. }
  41. ReducerRegistry.register<IResponsiveUIState>('features/base/responsive-ui',
  42. (state = DEFAULT_STATE, action): IResponsiveUIState => {
  43. switch (action.type) {
  44. case CLIENT_RESIZED: {
  45. return {
  46. ...state,
  47. clientWidth: action.clientWidth,
  48. clientHeight: action.clientHeight
  49. };
  50. }
  51. case SAFE_AREA_INSETS_CHANGED:
  52. return {
  53. ...state,
  54. safeAreaInsets: action.insets
  55. };
  56. case SET_ASPECT_RATIO:
  57. return set(state, 'aspectRatio', action.aspectRatio);
  58. case SET_REDUCED_UI:
  59. return set(state, 'reducedUI', action.reducedUI);
  60. case SET_CONTEXT_MENU_OPEN:
  61. return set(state, 'contextMenuOpened', action.isOpen);
  62. case SET_NARROW_LAYOUT:
  63. return set(state, 'isNarrowLayout', action.isNarrow);
  64. }
  65. return state;
  66. });