Created
September 8, 2022 09:00
-
-
Save abakers/0dcb56abc082a26c89da52a8841daae6 to your computer and use it in GitHub Desktop.
useGetStatusBarHeight
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
export const useGetStatusBarHeight = (): number => { | |
const [statusBarHeight, setStatusBarHeight] = useState(0); | |
const isMounted = useRef(true); | |
useEffect(() => { | |
if (Platform.OS === 'android') { | |
isMounted.current && | |
setStatusBarHeight( | |
NativeModules.StatusBarManager.HEIGHT, | |
); | |
} else { | |
NativeModules.StatusBarManager.getHeight( | |
(status: { height: number }) => { | |
isMounted.current && | |
setStatusBarHeight(status.height); | |
}, | |
); | |
} | |
return () => { | |
isMounted.current = false; | |
}; | |
}, []); | |
return statusBarHeight; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment