u
This commit is contained in:
1 parent
6277fb2f9e
commit
8ecac0d7dd
270 files changed
+40438
-529
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import type { KeyboardEvent } from 'react-native'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Keyboard } from 'react-native'
|
||||
|
||||
/**
|
||||
* useKeyboardHeight - 获取键盘高度的 Hooks
|
||||
* @returns {number} 当前键盘高度,键盘收起时为 0
|
||||
*/
|
||||
export function useKeyboardHeight() {
|
||||
const [keyboardHeight, setKeyboardHeight] = useState(0)
|
||||
|
||||
useEffect(() => {
|
||||
const onKeyboardShow = (e: KeyboardEvent) => {
|
||||
setKeyboardHeight(e.endCoordinates.height)
|
||||
}
|
||||
|
||||
const onKeyboardHide = () => {
|
||||
setKeyboardHeight(0)
|
||||
}
|
||||
|
||||
const showSub = Keyboard.addListener('keyboardDidShow', onKeyboardShow)
|
||||
const hideSub = Keyboard.addListener('keyboardDidHide', onKeyboardHide)
|
||||
|
||||
return () => {
|
||||
showSub.remove()
|
||||
hideSub.remove()
|
||||
}
|
||||
}, [])
|
||||
|
||||
return keyboardHeight
|
||||
}
|
||||
Reference in new issue
Block a user