Revert refresh on resize
This commit is contained in:
parent
73e5fc7919
commit
9de06f856a
@ -1,31 +1,12 @@
|
|||||||
import { throttle } from './schedulers';
|
import { throttle } from './schedulers';
|
||||||
import {
|
|
||||||
MOBILE_SCREEN_LANDSCAPE_MAX_HEIGHT,
|
|
||||||
MOBILE_SCREEN_LANDSCAPE_MAX_WIDTH,
|
|
||||||
MOBILE_SCREEN_MAX_WIDTH,
|
|
||||||
} from '../config';
|
|
||||||
import { IS_MOBILE_SCREEN } from './environment';
|
|
||||||
|
|
||||||
type IDimensions = {
|
type IDimensions = {
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
const IS_LANDSCAPE = IS_MOBILE_SCREEN && isLandscape();
|
|
||||||
|
|
||||||
let windowSize = updateSizes();
|
let windowSize = updateSizes();
|
||||||
|
|
||||||
const handleResize = throttle(() => {
|
|
||||||
windowSize = updateSizes();
|
|
||||||
|
|
||||||
if ((isMobileScreen() !== IS_MOBILE_SCREEN) || (IS_MOBILE_SCREEN && IS_LANDSCAPE !== isLandscape())) {
|
|
||||||
window.location.reload();
|
|
||||||
}
|
|
||||||
}, 250, true);
|
|
||||||
|
|
||||||
window.addEventListener('resize', handleResize);
|
|
||||||
window.addEventListener('orientationchange', handleResize);
|
|
||||||
|
|
||||||
export function updateSizes(): IDimensions {
|
export function updateSizes(): IDimensions {
|
||||||
const vh = window.innerHeight * 0.01;
|
const vh = window.innerHeight * 0.01;
|
||||||
|
|
||||||
@ -37,15 +18,12 @@ export function updateSizes(): IDimensions {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function isMobileScreen() {
|
const handleResize = throttle(() => {
|
||||||
return windowSize.width <= MOBILE_SCREEN_MAX_WIDTH || (
|
windowSize = updateSizes();
|
||||||
windowSize.width <= MOBILE_SCREEN_LANDSCAPE_MAX_WIDTH && windowSize.height <= MOBILE_SCREEN_LANDSCAPE_MAX_HEIGHT
|
}, 250, true);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isLandscape() {
|
window.addEventListener('resize', handleResize);
|
||||||
return window.matchMedia('(orientation: landscape)').matches;
|
window.addEventListener('orientationchange', handleResize);
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
get: () => windowSize,
|
get: () => windowSize,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user