-
Notifications
You must be signed in to change notification settings - Fork 0
fix: useFullScreen escKey가 적용안되는 문제 제거 #287
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@musma/react-utils": patch | ||
| --- | ||
|
|
||
| fix: useFullScreen escKey event일때, 적용안돼는 문제 제거 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { useCallback, useState } from 'react' | ||
| import { useEffect, useState } from 'react' | ||
|
|
||
| /** | ||
| * @description | ||
|
|
@@ -7,15 +7,28 @@ import { useCallback, useState } from 'react' | |
| export const useFullScreen = () => { | ||
| const [isFullScreen, setFullScreen] = useState(Boolean(document.fullscreenElement)) | ||
|
|
||
| const toggleFullScreen = useCallback(() => { | ||
| if (isFullScreen) { | ||
| // onClick 이벤트에 넣으세요 | ||
| const toggleFullScreen = () => { | ||
| if (document.fullscreenElement) { | ||
| // 전체모드 해제 | ||
| document.exitFullscreen() | ||
| } else { | ||
| document.documentElement.requestFullscreen() | ||
| setFullScreen(false) | ||
| } | ||
|
|
||
| setFullScreen((value) => !value) | ||
| }, [isFullScreen]) | ||
| // 전체모드 실행 | ||
| document.documentElement.requestFullscreen() | ||
| setFullScreen(true) | ||
| } | ||
|
|
||
| // 전체모드 실행될 때 + 사용자가 전체모드 이벤트를 사용할 때, | ||
| useEffect(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. useEffect로 풀스크린 감지 되던가용?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. useEffect가 감지한다기보다는 fullscreenchange 이벤트가 풀스크린을 감지합니다. window.addEventListener('fullscreenchange', 콜백함수)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 의존성 배열이 비어있다면 이 훅을 다시 호출할 때 도는 거잖아용 그럼 esc눌렀을 때 이 훅을 다시 호출하는 걱나요?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 솔직히 말해서, useEffect안에 넣는 이유는 모르겠는데, 즉 window.addEvent~~~('fullscreenchange')가 전체모드 이벤트를 감지해서 알아서 해줍니다.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 풀스크린 모드 설정, 해제가 사용자 이벤트에 의해 일어나야 하는 일이면 useEffect를 쓰지 않는게 좋을 듯 합니다. https://react.dev/learn/you-might-not-need-an-effect#how-to-remove-unnecessary-effects
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on, off 함수를 만들어서 풀스크린 모드 버튼 클릭시 on 메서드를 실행하고, 해제 버튼을 클릭하거나 esc키를 눌렀을 때는 off 메서드를 실행시키는식으로요! |
||
| const fullscreenchangeHandler = () => { | ||
| setFullScreen(Boolean(document.fullscreenElement)) | ||
| } | ||
|
|
||
| window.addEventListener('fullscreenchange', fullscreenchangeHandler) | ||
| return () => window.removeEventListener('fullscreenchange', fullscreenchangeHandler) | ||
| }, []) | ||
|
|
||
| return [isFullScreen, toggleFullScreen] as const | ||
| } | ||
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.
return 이 빠진 것 같습니다