-
Notifications
You must be signed in to change notification settings - Fork 2
[FEAT] 타이머에 전체 화면 기능 추가 #380
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
266dc85
feat: 전체 화면 로직을 useTimerPageState 훅에 추가
i-meant-to-be fec80cc
design: 헤더 아이콘 벡터 써니가 두께 줄인 것으로 변경
i-meant-to-be b0b4559
feat: 도움말에 전체 화면 관련 내용 추가
i-meant-to-be 4d35c35
design: 아이콘에 Figma 시안대로 패딩 추가
i-meant-to-be 8cf96cc
fix: 텍스트가 2줄 이상 늘어나는 문제 수정
i-meant-to-be 33e5dba
fix: 누락된 의존성 배열 추가
i-meant-to-be b936bc2
fix: 아이콘 크기 문제 수정
i-meant-to-be 76c6cc1
fix: 아이콘 벡터에서 빠진 색상 매개변수 추가
i-meant-to-be 277725a
refactor: 전체화면 토글 함수 useCallback 적용하여 개선
i-meant-to-be 534a001
fix: 전체화면 아이콘 너비 오류 수정
i-meant-to-be cf91488
refactor: 전체화면 인터페이스 별도 파일로 분리
i-meant-to-be 6659e78
refactor: 전체 화면 로직 별도 훅으로 분리
i-meant-to-be ae356a0
feat: 홈, 로그아웃 버튼 클릭 시 전체 화면 끄도록 구현
i-meant-to-be a3cc47a
feat: 토론 종료 시 전체 화면 끄도록 구현
i-meant-to-be File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import { useCallback, useLayoutEffect, useState } from 'react'; | ||
| import { | ||
| DocumentWithFullscreen, | ||
| HTMLElementWithFullscreen, | ||
| } from '../type/fullscreen'; | ||
|
|
||
| // 헬퍼 함수: 현재 전체 화면 요소가 무엇인지 반환 (없으면 null) | ||
| const getFullscreenElement = (): Element | null => { | ||
| const doc = document as DocumentWithFullscreen; | ||
| return ( | ||
| doc.fullscreenElement || | ||
| doc.webkitFullscreenElement || | ||
| doc.mozFullScreenElement || | ||
| doc.msFullscreenElement || | ||
| null | ||
| ); | ||
| }; | ||
|
|
||
| // 헬퍼 함수: 전체 화면 진입 | ||
| const enterFullscreen = async (element: HTMLElementWithFullscreen) => { | ||
| try { | ||
| if (element.requestFullscreen) { | ||
| await element.requestFullscreen(); | ||
| } else if (element.webkitRequestFullscreen) { | ||
| await element.webkitRequestFullscreen(); // Safari | ||
| } else if (element.mozRequestFullScreen) { | ||
| await element.mozRequestFullScreen(); // Firefox | ||
| } else if (element.msRequestFullscreen) { | ||
| await element.msRequestFullscreen(); // IE11 | ||
| } | ||
| } catch (error) { | ||
| console.error('# Failed to enter fullscreen mode:', error); | ||
| } | ||
| }; | ||
|
|
||
| // 헬퍼 함수: 전체 화면 해제 | ||
| const exitFullscreen = async () => { | ||
| const doc = document as DocumentWithFullscreen; | ||
| try { | ||
| if (doc.exitFullscreen) { | ||
| await doc.exitFullscreen(); | ||
| } else if (doc.webkitExitFullscreen) { | ||
| await doc.webkitExitFullscreen(); // Safari | ||
| } else if (doc.mozCancelFullScreen) { | ||
| await doc.mozCancelFullScreen(); // Firefox | ||
| } else if (doc.msExitFullscreen) { | ||
| await doc.msExitFullscreen(); // IE11 | ||
| } | ||
| } catch (error) { | ||
| console.error('# Failed to exit fullscreen mode:', error); | ||
| } | ||
| }; | ||
|
|
||
| export default function useFullscreen() { | ||
| // 전체 화면 여부를 묘사하는 변수 | ||
| const [isFullscreen, setIsFullscreen] = useState(!!getFullscreenElement()); | ||
| const handleFullscreenChange = useCallback(() => { | ||
| setIsFullscreen(!!getFullscreenElement()); | ||
| }, []); | ||
|
|
||
| // 이벤트 리스너 등록 | ||
| useLayoutEffect(() => { | ||
| const EVENTS = [ | ||
| 'fullscreenchange', | ||
| 'webkitfullscreenchange', | ||
| 'mozfullscreenchange', | ||
| 'MSFullscreenChange', | ||
| ]; | ||
|
|
||
| EVENTS.forEach((event) => { | ||
| document.addEventListener(event, handleFullscreenChange); | ||
| }); | ||
|
|
||
| return () => { | ||
| EVENTS.forEach((event) => { | ||
| document.removeEventListener(event, handleFullscreenChange); | ||
| }); | ||
| }; | ||
| }, [handleFullscreenChange]); | ||
|
|
||
| // 토글 함수 | ||
| const toggleFullscreen = useCallback(async () => { | ||
| const element = document.documentElement as HTMLElementWithFullscreen; | ||
|
|
||
| if (isFullscreen) { | ||
| await exitFullscreen(); | ||
| } else { | ||
| await enterFullscreen(element); | ||
| } | ||
| }, [isFullscreen]); | ||
|
|
||
| // 값을 직접 입력하는 함수 | ||
| const setFullscreen = useCallback(async (value: boolean) => { | ||
| const element = document.documentElement as HTMLElementWithFullscreen; | ||
| const isCurrentlyFullscreen = !!getFullscreenElement(); | ||
|
|
||
| if (value && !isCurrentlyFullscreen) { | ||
| await enterFullscreen(element); | ||
| } else if (!value && isCurrentlyFullscreen) { | ||
| await exitFullscreen(); | ||
| } | ||
| }, []); | ||
|
|
||
| return { isFullscreen, toggleFullscreen, setFullscreen }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다른 곳에서 setFullscreen을 보고 state 값을 설정한다고 느껴졌어요!! 실제 역할은 단순 상태 변경이 아니고 set함수를 넘긴 것도 아니고 true/false에 따라 전체 화면을 켜고 끄는 함수 호출이니 의도를 담은 함수명이 좋을 것 같은데 어떻게 생각하시나요? 지금 당장 생각나는 것은 handleFullscreen과 같은 ,, ?!!?