Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calendar: Close BottomSheet on screen rotation #847

Merged
merged 5 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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