-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 모바일 키보드 위로 바텀에 고정된 버튼이 올라올 수 있도록 하는 커스텀 훅 구현
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
frontend/src/hooks/useButtonOnKeyboard/useButtonOnKeyboard.ts
This file contains 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,25 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
const useButtonOnKeyboard = () => { | ||
const [resizedButtonHeight, setResizedButtonHeight] = useState(0); | ||
|
||
useEffect(() => { | ||
const handleButtonHeightResize = () => { | ||
if (!visualViewport?.height) return; | ||
|
||
setResizedButtonHeight(window.innerHeight - visualViewport.height); | ||
}; | ||
|
||
// 약속 이름 -> 약속 주최자 정보 입력으로 넘어갈 때 다음 버튼을 모바일 키보드로 올리기 위해서 resize 이벤트가 발생하지 않더라도 초기에 실행되도록 구현했어요.(@해리) | ||
handleButtonHeightResize(); | ||
visualViewport?.addEventListener('resize', handleButtonHeightResize); | ||
|
||
return () => { | ||
visualViewport?.removeEventListener('resize', handleButtonHeightResize); | ||
}; | ||
}, []); | ||
|
||
return resizedButtonHeight; | ||
}; | ||
|
||
export default useButtonOnKeyboard; |