* Show round videos in the voices tab * Pause audio player when starting round video playback * Changed text for empty votes tab (taken from TDesktop) * Capitalized month name on Shared Media tabs. * Display title context menu button in unjoined channels or groups * Fixed voice recording timer flickering * Don't restart emoji animation when pressed while animation is playing * Corrected viewport calculation for iOS15 * Changed the border color of avatars in own poll
87 lines
2.3 KiB
TypeScript
87 lines
2.3 KiB
TypeScript
import { throttle } from './schedulers';
|
|
import {
|
|
MOBILE_SCREEN_LANDSCAPE_MAX_HEIGHT,
|
|
MOBILE_SCREEN_LANDSCAPE_MAX_WIDTH,
|
|
MOBILE_SCREEN_MAX_WIDTH,
|
|
} from '../config';
|
|
import { IS_IOS, IS_SINGLE_COLUMN_LAYOUT } from './environment';
|
|
|
|
type IDimensions = {
|
|
width: number;
|
|
height: number;
|
|
};
|
|
|
|
const IS_LANDSCAPE = IS_SINGLE_COLUMN_LAYOUT && isLandscape();
|
|
|
|
const initialHeight = window.innerHeight;
|
|
let windowSize = updateSizes();
|
|
let isRefreshDisabled = false;
|
|
|
|
function disableRefresh() {
|
|
isRefreshDisabled = true;
|
|
}
|
|
|
|
function enableRefresh() {
|
|
isRefreshDisabled = false;
|
|
}
|
|
|
|
const handleResize = throttle(() => {
|
|
windowSize = updateSizes();
|
|
|
|
if (!isRefreshDisabled && (
|
|
isMobileScreen() !== IS_SINGLE_COLUMN_LAYOUT
|
|
|| (IS_SINGLE_COLUMN_LAYOUT && IS_LANDSCAPE !== isLandscape())
|
|
)) {
|
|
window.location.reload();
|
|
}
|
|
}, 250, true);
|
|
|
|
window.addEventListener('orientationchange', handleResize);
|
|
if (IS_IOS) {
|
|
window.visualViewport.addEventListener('resize', handleResize);
|
|
} else {
|
|
window.addEventListener('resize', handleResize);
|
|
}
|
|
|
|
export function updateSizes(): IDimensions {
|
|
let height: number;
|
|
if (IS_IOS) {
|
|
height = window.visualViewport.height + window.visualViewport.pageTop;
|
|
} else {
|
|
height = window.innerHeight;
|
|
}
|
|
const vh = height * 0.01;
|
|
|
|
document.documentElement.style.setProperty('--vh', `${vh}px`);
|
|
|
|
return {
|
|
width: window.innerWidth,
|
|
height: window.innerHeight,
|
|
};
|
|
}
|
|
|
|
function isMobileScreen() {
|
|
return windowSize.width <= MOBILE_SCREEN_MAX_WIDTH || (
|
|
windowSize.width <= MOBILE_SCREEN_LANDSCAPE_MAX_WIDTH && windowSize.height <= MOBILE_SCREEN_LANDSCAPE_MAX_HEIGHT
|
|
);
|
|
}
|
|
|
|
function isLandscape() {
|
|
if (IS_IOS) {
|
|
return window.matchMedia('(orientation: landscape)').matches;
|
|
}
|
|
|
|
// eslint-disable-next-line max-len
|
|
// Source: https://web.archive.org/web/20160509220835/http://blog.abouthalf.com/development/orientation-media-query-challenges-in-android-browsers/
|
|
// Feature is marked as deprecated now, but it is still supported
|
|
// https://developer.mozilla.org/en-US/docs/Web/CSS/@media/device-aspect-ratio#browser_compatibility
|
|
return window.matchMedia('screen and (min-device-aspect-ratio: 1/1) and (orientation: landscape)').matches;
|
|
}
|
|
|
|
export default {
|
|
get: () => windowSize,
|
|
getIsKeyboardVisible: () => initialHeight > windowSize.height,
|
|
disableRefresh,
|
|
enableRefresh,
|
|
};
|