Skip to content

Commit

Permalink
feat: 모바일 키보드 위로 바텀에 고정된 버튼이 올라올 수 있도록 하는 커스텀 훅 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
hwinkr committed Sep 21, 2024
1 parent 02c67e8 commit 4415590
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions frontend/src/hooks/useButtonOnKeyboard/useButtonOnKeyboard.ts
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;

0 comments on commit 4415590

Please sign in to comment.