From 8405acb27d4971f422ff80ae6f73338ea0328806 Mon Sep 17 00:00:00 2001 From: primakov Date: Tue, 29 Nov 2022 21:36:30 +0300 Subject: [PATCH] fullscreen --- ijl.config.js | 5 +++++ src/pages/main.tsx | 29 +++++++++++++++++++++++++++-- src/pages/style.ts | 13 +++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/ijl.config.js b/ijl.config.js index dcb3443..d1d60bd 100644 --- a/ijl.config.js +++ b/ijl.config.js @@ -17,6 +17,11 @@ module.exports = { "on": true, "value": "true", "key": "keyboard" + }, + "fullScreen": { + "on": true, + "value": "true", + "key": "fullScreen" } }, }, diff --git a/src/pages/main.tsx b/src/pages/main.tsx index 3dd8567..b3c9c52 100644 --- a/src/pages/main.tsx +++ b/src/pages/main.tsx @@ -1,4 +1,4 @@ -import React, {useState, useCallback, useRef} from 'react'; +import React, {useState, useCallback, useRef, useMemo} from 'react'; import { getFeatures } from '@ijl/cli'; import logo from '../assets/logo-white.svg'; @@ -24,17 +24,21 @@ import { LineSvg, Svg, CircleDiv, + FullScreenButton, + InputHolder, } from './style'; import { socket } from "../socket"; const keyboardFeature = getFeatures('hub-video-start')?.keyboard; +const fullScreenFeature = getFeatures('hub-video-start')?.fullScreen; const Input = ({ onStart }) => { const [value, setValue] = useState(''); - const [inFocuse, setInfocuse] = useState(false); + const [inFocuse, setInfocuse] = useState(true); const handleChange = useCallback(event => { setValue(event.target.value.toUpperCase()) }, [setValue]); + const inputRef = useRef(null); const handleSubmit = useCallback((event) => { event.preventDefault(); @@ -56,9 +60,16 @@ const Input = ({ onStart }) => { value={value} onChange={handleChange} onFocus={() => setInfocuse(true)} + ref={inputRef} + onClick={(event) => { + event.preventDefault(); + event.stopPropagation(); + inputRef.current.blur(); + }} id="input" autoComplete="off" /> + setInfocuse(true)} /> @@ -204,9 +215,23 @@ const Start = () => { export const MainPage = () => { const [showStart, setShowStart] = useState(false); + const [isFull, setFull] = useState(false); + + const handleFullScreen = useCallback(() => { + const elem = document.documentElement; + if (elem.requestFullscreen) { + elem.requestFullscreen(); + } else if (elem.webkitRequestFullscreen) { /* Safari */ + elem.webkitRequestFullscreen(); + } else if (elem.msRequestFullscreen) { /* IE11 */ + elem.msRequestFullscreen(); + } + setFull(true); + }, []); return ( + {fullScreenFeature && !isFull && На весь экран} {/* */} {!showStart && setShowStart(true)} />} diff --git a/src/pages/style.ts b/src/pages/style.ts index 00103de..5bac5c9 100644 --- a/src/pages/style.ts +++ b/src/pages/style.ts @@ -276,4 +276,17 @@ export const Circle = styled.circle<{ circumference: number; percent: number }>` stroke-dashoffset: ${({ circumference, percent }) => circumference - percent / 100 * circumference}; `; +export const FullScreenButton = styled.button` + padding: 24px; + position: absolute; + top: 50px; + right: 50px; +`; +export const InputHolder = styled.div` + background-color: rgba(0, 0, 0, .0); + width: calc(100% - 70px); + height: 100%; + right: 70px; + position: absolute; +`;