Skip to content

Commit

Permalink
chore(ui): added screenfull library for fullscreen functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
wialy committed Mar 28, 2024
1 parent d2bbbd2 commit 7a379d6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"react-hotkeys-hook": "^4.5.0",
"react-swipeable": "^7.0.1",
"react-use-clipboard": "^1.0.9",
"screenfull": "^6.0.2",
"use-debounce": "^10.0.0",
"uuid": "^9.0.1",
"zustand": "^4.5.2"
Expand Down
20 changes: 16 additions & 4 deletions src/features/ui/components/fullscreen-toggle/fullscreen-toggle.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
import { useEffect, useState } from 'react';
import screenfull from 'screenfull';

import { Button } from '../button';
import { Icon } from '../icon';
import $$ from './fullscreen-toggle.module.css';

export const FullscreenToggle = () => {
const [isEnabled, setIsEnabled] = useState(false);
const [isFullscreen, setIsFullscreen] = useState(false);

const toggleFullscreen = () => {
setIsFullscreen((previous) => !previous);
};

useEffect(() => {
if (!isEnabled) {
return;
}

void (async () => {
try {
await (isFullscreen
? document.documentElement.requestFullscreen()
: document.exitFullscreen());
await (isFullscreen ? screenfull.request() : screenfull.exit());
} catch {
// Ignore
}
})();
}, [isFullscreen]);
}, [isEnabled, isFullscreen]);

useEffect(() => {
setIsEnabled(screenfull.isEnabled);
}, []);

if (!isEnabled) {
return null;
}

return (
<Button
Expand Down

0 comments on commit 7a379d6

Please sign in to comment.