Skip to content

Commit

Permalink
Merge pull request #847 from Stremio/fix/hide-calendar-bottom-sheet-o…
Browse files Browse the repository at this point in the history
…n-resize

Calendar: Close BottomSheet on screen rotation
  • Loading branch information
tymmesyde authored Feb 25, 2025
2 parents 3d3828f + a213139 commit 8fb09b0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const { default: useShell } = require('./useShell');
const useStreamingServer = require('./useStreamingServer');
const useTorrent = require('./useTorrent');
const useTranslate = require('./useTranslate');
const { default: useOrientation } = require('./useOrientation');

module.exports = {
FileDropProvider,
Expand Down Expand Up @@ -55,4 +56,5 @@ module.exports = {
useStreamingServer,
useTorrent,
useTranslate,
useOrientation,
};
34 changes: 34 additions & 0 deletions src/common/useOrientation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (C) 2017-2025 Smart code 203358507

import { useState, useEffect, useMemo } from 'react';

type DeviceOrientation = 'landscape' | 'portrait';

const useOrientation = () => {
const [windowHeight, setWindowHeight] = useState(window.innerHeight);
const [windowWidth, setWindowWidth] = useState(window.innerWidth);

const orientation: DeviceOrientation = useMemo(() => {
if (windowHeight > windowWidth) {
return 'portrait';
} else {
return 'landscape';
}
}, [windowWidth, windowHeight]);

useEffect(() => {
const handleResize = () => {
setWindowHeight(window.innerHeight);
setWindowWidth(window.innerWidth);
};

window.addEventListener('resize', handleResize);
return () => {
window.removeEventListener('resize', handleResize);
};
}, [window.innerWidth, window.innerHeight]);

return orientation;
};

export default useOrientation;
6 changes: 6 additions & 0 deletions src/components/BottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 useOrientation from 'stremio/common/useOrientation';
import styles from './BottomSheet.less';

const CLOSE_THRESHOLD = 100;
Expand All @@ -17,6 +18,7 @@ type Props = {

const BottomSheet = ({ children, title, show, onClose }: Props) => {
const containerRef = useRef<HTMLDivElement>(null);
const orientation = useOrientation();
const [startOffset, setStartOffset] = useState(0);
const [offset, setOffset] = useState(0);

Expand Down Expand Up @@ -58,6 +60,10 @@ const BottomSheet = ({ children, title, show, onClose }: Props) => {
!opened && onClose();
}, [opened]);

useEffect(() => {
opened && close();
}, [orientation]);

return opened && createPortal((
<div className={styles['bottom-sheet']}>
<div className={styles['backdrop']} onClick={onCloseRequest} />
Expand Down

0 comments on commit 8fb09b0

Please sign in to comment.