Improve resizing screen until it switches to/from Mobile

This commit is contained in:
Rafael 2022-04-05 09:59:06 -03:00 committed by Thomas Zarebczan
parent 65b9906086
commit 9f04370516

View file

@ -112,6 +112,7 @@ export default function FileRenderFloating(props: Props) {
const isMobile = useIsMobile(); const isMobile = useIsMobile();
const initialMobileState = React.useRef(isMobile);
const initialPlayerHeight = React.useRef(); const initialPlayerHeight = React.useRef();
const resizedBetweenFloating = React.useRef(); const resizedBetweenFloating = React.useRef();
@ -170,7 +171,11 @@ export default function FileRenderFloating(props: Props) {
x: rect.x, x: rect.x,
}; };
if (videoAspectRatio && !initialPlayerHeight.current) { // replace the initial value every time the window is resized if isMobile is true,
// since it could be a portrait -> landscape rotation switch, or if it was a mobile - desktop
// switch, so use the ref to compare the initial state
const resizedEnoughForMobileSwitch = isMobile !== initialMobileState.current;
if (videoAspectRatio && (!initialPlayerHeight.current || isMobile || resizedEnoughForMobileSwitch)) {
const heightForRect = getPossiblePlayerHeight(videoAspectRatio * rect.width, isMobile); const heightForRect = getPossiblePlayerHeight(videoAspectRatio * rect.width, isMobile);
initialPlayerHeight.current = heightForRect; initialPlayerHeight.current = heightForRect;
} }
@ -526,7 +531,9 @@ const PlayerGlobalStyles = (props: GlobalStylesProps) => {
const transparentBackground = { const transparentBackground = {
background: videoGreaterThanLandscape && mainFilePlaying && !forceDefaults ? 'transparent !important' : undefined, background: videoGreaterThanLandscape && mainFilePlaying && !forceDefaults ? 'transparent !important' : undefined,
}; };
const maxHeight = { maxHeight: !videoTheaterMode ? 'var(--desktop-portrait-player-max-height)' : undefined }; const maxHeight = {
maxHeight: !videoTheaterMode && !isMobile ? 'var(--desktop-portrait-player-max-height)' : undefined,
};
return ( return (
<Global <Global