-
-
Notifications
You must be signed in to change notification settings - Fork 530
Expand file tree
/
Copy pathuseSafeAreaPadding.ts
More file actions
31 lines (27 loc) · 1.17 KB
/
useSafeAreaPadding.ts
File metadata and controls
31 lines (27 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { ReactNativeToWebEvent } from '@standardnotes/snjs'
import { useApplication } from '@/Components/ApplicationProvider'
import { useEffect, useState } from 'react'
export const useAvailableSafeAreaPadding = () => {
const documentStyle = getComputedStyle(document.documentElement)
const top = parseInt(documentStyle.getPropertyValue('--safe-area-inset-top'))
const right = parseInt(documentStyle.getPropertyValue('--safe-area-inset-right'))
const bottom = parseInt(documentStyle.getPropertyValue('--safe-area-inset-bottom'))
const left = parseInt(documentStyle.getPropertyValue('--safe-area-inset-left'))
const application = useApplication()
const [isKeyboardVisible, setIsKeyboardVisible] = useState(false)
useEffect(() => {
return application.addNativeMobileEventListener((event) => {
if (event === ReactNativeToWebEvent.KeyboardWillShow) {
setIsKeyboardVisible(true)
} else if (event === ReactNativeToWebEvent.KeyboardWillHide) {
setIsKeyboardVisible(false)
}
})
}, [application])
return {
hasTopInset: !!top,
hasRightInset: !!right,
hasBottomInset: !!bottom && !isKeyboardVisible,
hasLeftInset: !!left,
}
}