2022-07-26 10:20:39 +00:00
|
|
|
import ReducerRegistry from '../redux/ReducerRegistry';
|
|
|
|
import { set } from '../redux/functions';
|
2017-10-13 16:13:46 +00:00
|
|
|
|
2022-05-06 10:18:57 +00:00
|
|
|
import {
|
|
|
|
CLIENT_RESIZED,
|
|
|
|
SAFE_AREA_INSETS_CHANGED,
|
|
|
|
SET_ASPECT_RATIO,
|
|
|
|
SET_CONTEXT_MENU_OPEN,
|
|
|
|
SET_REDUCED_UI
|
|
|
|
} from './actionTypes';
|
2017-10-13 16:13:46 +00:00
|
|
|
import { ASPECT_RATIO_NARROW } from './constants';
|
|
|
|
|
2020-01-24 16:28:47 +00:00
|
|
|
const {
|
|
|
|
innerHeight = 0,
|
|
|
|
innerWidth = 0
|
|
|
|
} = window;
|
|
|
|
|
2017-11-07 14:28:08 +00:00
|
|
|
/**
|
2018-02-14 18:28:22 +00:00
|
|
|
* The default/initial redux state of the feature base/responsive-ui.
|
2017-11-07 14:28:08 +00:00
|
|
|
*/
|
2018-02-14 18:28:22 +00:00
|
|
|
const DEFAULT_STATE = {
|
2018-02-02 13:39:27 +00:00
|
|
|
aspectRatio: ASPECT_RATIO_NARROW,
|
2020-01-24 16:28:47 +00:00
|
|
|
clientHeight: innerHeight,
|
|
|
|
clientWidth: innerWidth,
|
2021-09-14 07:43:52 +00:00
|
|
|
reducedUI: false,
|
|
|
|
contextMenuOpened: false
|
2017-10-13 16:13:46 +00:00
|
|
|
};
|
|
|
|
|
2022-07-26 10:20:39 +00:00
|
|
|
export interface IResponsiveUIState {
|
|
|
|
aspectRatio: Symbol;
|
|
|
|
clientHeight: number;
|
|
|
|
clientWidth: number;
|
|
|
|
contextMenuOpened: boolean;
|
|
|
|
reducedUI: boolean;
|
|
|
|
safeAreaInsets?: {
|
|
|
|
bottom: number;
|
|
|
|
left: number;
|
|
|
|
right: number;
|
|
|
|
top: number;
|
2022-09-08 09:52:36 +00:00
|
|
|
};
|
2022-07-26 10:20:39 +00:00
|
|
|
}
|
|
|
|
|
2022-09-05 09:05:07 +00:00
|
|
|
ReducerRegistry.register<IResponsiveUIState>('features/base/responsive-ui',
|
|
|
|
(state = DEFAULT_STATE, action): IResponsiveUIState => {
|
2019-11-08 16:42:39 +00:00
|
|
|
switch (action.type) {
|
2020-01-24 16:28:47 +00:00
|
|
|
case CLIENT_RESIZED: {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
clientWidth: action.clientWidth,
|
|
|
|
clientHeight: action.clientHeight
|
|
|
|
};
|
|
|
|
}
|
2022-05-06 10:18:57 +00:00
|
|
|
|
|
|
|
case SAFE_AREA_INSETS_CHANGED:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
safeAreaInsets: action.insets
|
|
|
|
};
|
|
|
|
|
2019-11-08 16:42:39 +00:00
|
|
|
case SET_ASPECT_RATIO:
|
|
|
|
return set(state, 'aspectRatio', action.aspectRatio);
|
2018-02-02 13:39:27 +00:00
|
|
|
|
2019-11-08 16:42:39 +00:00
|
|
|
case SET_REDUCED_UI:
|
|
|
|
return set(state, 'reducedUI', action.reducedUI);
|
2021-09-14 07:43:52 +00:00
|
|
|
|
|
|
|
case SET_CONTEXT_MENU_OPEN:
|
|
|
|
return set(state, 'contextMenuOpened', action.isOpen);
|
2019-11-08 16:42:39 +00:00
|
|
|
}
|
2017-10-13 16:13:46 +00:00
|
|
|
|
2019-11-08 16:42:39 +00:00
|
|
|
return state;
|
|
|
|
});
|