-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
post: add doc about scroll of mobile device
- Loading branch information
Showing
2 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
apps/doc/blog/frontend/2023/2023-06-26-device-keypad-open-check.mdx
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,47 @@ | ||
--- | ||
title: 모바일 디바이스에서 키패드 활성화 여부 확인하기 | ||
tags: ['scroll', 'mobile-devie', 'keypad'] | ||
date: 2023-06-26T19:38 | ||
--- | ||
|
||
<!--truncate--> | ||
|
||
모바일 디바이스에서 키패드의 활성화 여부를 체크하기 위해서는 사용자에게 보여지는 화면의 영역에 대한 뷰포트의 사이즈를 체크하여 확인할 수 있다. | ||
해당 값은 `window.innerHeight`의 값을 확인할 수 있는데, | ||
aos의 경우, 키패드가 활성화된 경우 뷰포트가 키패드 위로 줄어들면서 해당 값이 변화하게 되지만, | ||
ios의 경우에는 키패드가 활성화되더라도 해당 값은 동일하게 되지만, `window.visualViewport.height` 값은 키패드가 제외된 화면의 영영의 사이즈를 의미한다 | ||
|
||
그러므로 아래와 같이 작성하여 키패드 활성화 유무를 판단할 수 있다. | ||
|
||
```javascript | ||
const webViewHeight = useRef < number > 0; | ||
|
||
const isIOS = () => { | ||
const agent = navigator.userAgent || navigator.vendor; | ||
return /iPad|iPhone|iPod/i.test(agent); | ||
}; | ||
|
||
useEffect(() => { | ||
const handleVisualViewportResize = () => { | ||
const viewportHeight = isIOS | ||
? window.visualViewport.height | ||
: window.innerHeight; | ||
|
||
if (webViewHeight.current > viewportHeight) { | ||
// keypad open | ||
} | ||
}; | ||
|
||
webViewHeight.current = window.innerHeight; | ||
window.visualViewport.addEventListener('resize', handleVisualViewportResize); | ||
|
||
return () => { | ||
visualViewport.removeEventListener('resize', handleVisualViewportResize); | ||
}; | ||
}, []); | ||
``` | ||
## References | ||
- [VisualViewport | MDN](https://developer.mozilla.org/en-US/docs/Web/API/VisualViewport) | ||
- [(WebView) aOS, iOS에서 키패드 유무 파악하기](https://velog.io/@dongkyun/WebView-aOS-iOS%EC%97%90%EC%84%9C-%ED%82%A4%ED%8C%A8%EB%93%9C-%EC%9C%A0%EB%AC%B4-%ED%8C%8C%EC%95%85%ED%95%98%EA%B8%B0) |
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