How can I find the height of the status bar on Android through React Native?
If I check the React.Dimensions
height the value seems to include the status bar height too but I'm trying to find the height of the layout without the status bar.
How can I find the height of the status bar on Android through React Native?
If I check the React.Dimensions
height the value seems to include the status bar height too but I'm trying to find the height of the layout without the status bar.
You don't need any plugins for this (anymore), just use
StatusBar.currentHeight
:EDIT: Apparently this does seem to work on Android always, but on iOS, initially
undefined
is indeed returned :(Unfortunately, as of v0.34, the API to do this is still inconsistent across platforms.
StatusBarManager.HEIGHT
will give you the current height of the Status Bar on Android.On iOS, you can use
getHeight()
As a side note, if you want your app to draw under the status bar on Android similar to the default iOS behavior, you can do so by setting a couple props on
<StatusBar>
as follows:You can use this helper function which enables you to get the Status Bar height on iOS and Android. For iOS, the calculation is done to get the different StatusBar height when >= iPhone X (with notch) is used.
Then use it directly when imported:
Another option if you use
react-navigation-stack
- it provides the header height via hook - https://reactnavigation.org/docs/en/stack-navigator.html#headertransparent