react-native: `StatusBar.currentHeight` gives incorrect height on Google Pixel 5a (Android 12)
Description
StatusBar.currentHeight provides an incorrect value for the height of the status bar on a Google Pixel 5a with Android 12. From basic testing, this does not seem to be an issue on other devices or on an older OS (Android 11)
Screenshot when using StatusBar.currentHeight as the top margin

Expected:

Version
0.66.0
Output of npx react-native info
example on Expo, this is occurring in multiple versions of react native, notably tested on 0.66.0 and 0.64.2
Steps to reproduce
- use
StatusBar.currentHeight - compare calculated height on Google Pixel 5a (Android 12) to other Android devices - the height for Pixel 5a Android 12 does not match the full height as it appears on the device while other devices do still work
Snack, code example, screenshot, or link to a repository
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 10
- Comments: 26 (4 by maintainers)
Commits related to this issue
- Fix status bar height calculation for all cutout sizes Summary: Google has discouraged attempting to read the `status_bar_height` resource [since 2017](https://youtu.be/_mGDMVRO3iE?si=qGQd7gLa_qTmfLG... — committed to Abbondanzo/react-native by Abbondanzo 2 years ago
- Fix status bar height calculation for all cutout sizes (#44697) Summary: Google has discouraged attempting to read the `status_bar_height` resource [since 2017](https://youtu.be/_mGDMVRO3iE?si=qGQd7... — committed to Abbondanzo/react-native by Abbondanzo 2 years ago
- Fix status bar height calculation for all cutout sizes (#44697) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44697 Google has discouraged attempting to read the `sta... — committed to facebook/react-native by Abbondanzo 2 years ago
- Fix status bar height calculation for all cutout sizes Summary: Google has discouraged attempting to read the `status_bar_height` resource [since 2017](https://youtu.be/_mGDMVRO3iE?si=qGQd7gLa_qTmfLG... — committed to Abbondanzo/react-native by Abbondanzo 2 years ago
- Fix status bar height calculation for all cutout sizes (#44805) Summary: Google has discouraged attempting to read the `status_bar_height` resource [since 2017](https://youtu.be/_mGDMVRO3iE?si=qGQd7... — committed to Abbondanzo/react-native by Abbondanzo 2 years ago
- Fix status bar height calculation for all cutout sizes (#44805) Summary: Google has discouraged attempting to read the `status_bar_height` resource [since 2017](https://youtu.be/_mGDMVRO3iE?si=qGQd7... — committed to Abbondanzo/react-native by Abbondanzo 2 years ago
- Fix status bar height calculation for all cutout sizes (#44805) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44805 Google has discouraged attempting to read the `sta... — committed to facebook/react-native by Abbondanzo 2 years ago
- Fix status bar height calculation for all cutout sizes (#44697) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44697 Google has discouraged attempting to read the `sta... — committed to kosmydel/react-native by Abbondanzo 2 years ago
Stop auto closing these! This is a bug! And why doesn’t the RN team respond to something like this?
👋 I’ve put a fix in #44697 that relies on window insets to determine status bar height, rather than reading from a potentially mismatched resource value. This should make its way into 0.75
Hi ! We quick fixed it statically until we have time to tackle it properly or it gets fixed. It look like this:
The
initialWindowMetrics?.insets.topactually returns the correct insets. (Obviously it would be better to use auseInsetsand the context to be sure to have it updated in case it change dynamically)Let me know if it’s unclear !
Not just Pixel 5a, but many devices that may have a notch.
We ended up using react-native-safe-area-context which were luckily already using (I hate adding lib to palliate a bug in a native function)…
It gives the insets of the devices, with the correct value for the top inset (the status bar). They probably don’t rely on
StatusBar.currentHeight, but on the native function instead, which makes it perfectly reliable.It also enforces a better usage of this value which can actually change when rotating the screen. So we shouldn’t get it statically, but react to its changes instead. And react-native-safe-area-context provides the tools for it.
Again, not the best solution as it requires to add a lib, but at least the lib provides the right values !
Hope it can help until it’s fix on React-Native side !
Thanks for tackling this long-lasting issue @Abbondanzo 🙌
still an issue, managed to find a workaround:
Getting the Incorrect Status bar height on Google pixel 4a
` Working solution for API 29+ It was with this version that Google introduced edge-to-edge
public void getStatusBarHeight(Promise promise) {
Well finally I managed to get the exact value, using some deprecated functions. What I did was detect the full screen height (2400) and supress the innerheight (2222) from it and the navbar too (42) so I ended with the long awaited 136.
EDIT: Turns out this method only worked on Pixels, so the final result is a mix of those 2:
This started happening for me on my Pixel 4a after the 5 March 2022 Android security update. Before this it was not an issue on Android 12 for me.