fix(BottomSheet): hide BottomSheet when screen is resized

This commit is contained in:
Botzy 2025-02-25 11:45:48 +02:00
parent 2b5df90827
commit b563ea1d10

View file

@ -4,6 +4,7 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { createPortal } from 'react-dom';
import classNames from 'classnames';
import useBinaryState from 'stremio/common/useBinaryState';
import useWindowSize from 'stremio/common/useWindowSize';
import styles from './BottomSheet.less';
const CLOSE_THRESHOLD = 100;
@ -17,6 +18,7 @@ type Props = {
const BottomSheet = ({ children, title, show, onClose }: Props) => {
const containerRef = useRef<HTMLDivElement>(null);
const { width: windowWidth, height: windowHeight } = useWindowSize();
const [startOffset, setStartOffset] = useState(0);
const [offset, setOffset] = useState(0);
@ -58,6 +60,10 @@ const BottomSheet = ({ children, title, show, onClose }: Props) => {
!opened && onClose();
}, [opened]);
useEffect(() => {
opened && close();
}, [windowWidth, windowHeight]);
return opened && createPortal((
<div className={styles['bottom-sheet']}>
<div className={styles['backdrop']} onClick={onCloseRequest} />