Created
September 17, 2019 13:58
-
-
Save godness84/931f12dd4088b632570151f36298e04b to your computer and use it in GitHub Desktop.
react-native hook useStatusBarHeight
This file contains hidden or 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
import { useEffect, useState } from "react"; | |
import { NativeModules, StatusBarIOS } from "react-native"; | |
export function useStatusBarHeight() { | |
const [height, setHeight] = useState(0) | |
useEffect(() => { | |
NativeModules.StatusBarManager.getHeight((frame: any) => setHeight(frame.height)) | |
const changeListener = StatusBarIOS.addListener('statusBarFrameWillChange', (data: any) => { | |
setHeight(data.frame.height) | |
}) | |
return () => changeListener.remove() | |
}, []) | |
return height | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment