-
Notifications
You must be signed in to change notification settings - Fork 24k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StatusBar.currentHeight
gives incorrect height on Google Pixel 5a (Android 12)
#33612
Comments
Not just Pixel 5a, but many devices that may have a notch. |
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. |
I'm also running into this issue |
Our users also experiences this issue in our app running on an Android 12. After looking a bit around, this is probably not a React Native issue, but most likely a Android 12 issue. It seems they when through their beta without realising that the native function returning the status bar height, was giving back a wrong value/ Hopefully Android 12 issues a fix soon, in the meantime you'll have to either:
|
Bump? Has anyone found a solution for this? |
For me, |
Would you be willing to share your implantation for this. Me and others who stumble on this would appreciate it 🙂 |
It's actually a really ugly work around, shouldn't really share something that ugly!. Either way, the idea is simple:
|
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 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 ! |
Do you have any code snippet that you could share ? I tried to use react-native-safe-area-context (SafeAreaProvider & SafeAreaView) but it does not seems to work Thanks |
Hi !
The Let me know if it's unclear ! |
I'm programming an app with Android Studio and testing it in a virtual Pixel 6, and the functions to get statusbar height return something like 60px, but the real bar is at least 125px |
Arf that's annoying when we can't rely on this value.. Specially on Android were there's a big range of different devices. Does Also side discovery, in android developer option, you can simulate different status bar height: search for |
Sizes in Pixel 6 are (measured from a screenshot): My functions to get them are:
But they return 63 and 42. I assume with a navbar (not the pill) the result would be correct too, so the main problem here is the statusbar. I knew the Pixel 3XL had a huge notch (from a internet screenshot I calculated it was less than 140px).
That assigns the value as if it was 140, in case it's a Pixel. It would be amazing to get the exact value but it's not strictly necessary for my app. I just needto set the exact value or bigger, so this makes the trick in Pixels, for now. |
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:
|
It looks like your issue or the example you provided uses an unsupported version of React Native. Due to the amount of issues we receive, we're currently accepting only new issues against one of the supported version. Please open your issue on StackOverflow to get further community support. |
` public void getStatusBarHeight(Promise promise) {
|
This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days. |
This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days. |
This issue was closed because the author hasn't provided the requested feedback after 7 days. |
Stop auto closing these! This is a bug! And why doesn't the RN team respond to something like this? |
still an issue. anyone figure it out? |
Getting the Incorrect Status bar height on Google pixel 4a |
still an issue, managed to find a workaround:
|
Summary: Google has discouraged attempting to read the `status_bar_height` resource [since 2017](https://youtu.be/_mGDMVRO3iE?si=qGQd7gLa_qTmfLGL&t=1079). With the introduction of display cutouts there can be a mismatch between the resource value and the true status bar size (and issues like [this one](facebook#33612) popped up). The recommended approach is to instead call `getInsets` with the proper status bar and navigation flags provided by `WindowInsets`. On older APIs where `getInsets` is not supported, we have access to `systemWindowInsetTop`. Changelog: [Android][Fixed] - Fixed StatusBar.currentHeight calculations to honor all cutout sizes Differential Revision: D57878119
Summary: Google has discouraged attempting to read the `status_bar_height` resource [since 2017](https://youtu.be/_mGDMVRO3iE?si=qGQd7gLa_qTmfLGL&t=1079). With the introduction of display cutouts there can be a mismatch between the resource value and the true status bar size (and issues like [this one](facebook#33612) popped up). The recommended approach is to instead call `getInsets` with the proper status bar and navigation flags provided by `WindowInsets`. On older APIs where `getInsets` is not supported, we have access to `systemWindowInsetTop`. Changelog: [Android][Fixed] - Fixed StatusBar.currentHeight calculations to honor all cutout sizes Reviewed By: alanleedev Differential Revision: D57878119
👋 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 |
Summary: Pull Request resolved: #44697 Google has discouraged attempting to read the `status_bar_height` resource [since 2017](https://youtu.be/_mGDMVRO3iE?si=qGQd7gLa_qTmfLGL&t=1079). With the introduction of display cutouts there can be a mismatch between the resource value and the true status bar size (and issues like [this one](#33612) popped up). The recommended approach is to instead call `getInsets` with the proper status bar and navigation flags provided by `WindowInsets`. On older APIs where `getInsets` is not supported, we have access to `systemWindowInsetTop`. Changelog: [Android][Fixed] - Fixed StatusBar.currentHeight calculations to honor all cutout sizes Reviewed By: cipolleschi, alanleedev Differential Revision: D57878119 fbshipit-source-id: 9fadd33d5f9b617a70a052c98dbd53fd29281650
Thanks for tackling this long-lasting issue @Abbondanzo 🙌 |
Summary: Google has discouraged attempting to read the `status_bar_height` resource [since 2017](https://youtu.be/_mGDMVRO3iE?si=qGQd7gLa_qTmfLGL&t=1079). With the introduction of display cutouts there can be a mismatch between the resource value and the true status bar size (and issues like [this one](facebook#33612) popped up). The recommended approach is to instead call `getInsets` with the proper status bar and navigation flags provided by `WindowInsets`. On older APIs where `getInsets` is not supported, we have access to `systemWindowInsetTop`. Changelog: [Android][Fixed] - Fixed StatusBar.currentHeight calculations to honor all cutout sizes Differential Revision: D58088036
Summary: Google has discouraged attempting to read the `status_bar_height` resource [since 2017](https://youtu.be/_mGDMVRO3iE?si=qGQd7gLa_qTmfLGL&t=1079). With the introduction of display cutouts there can be a mismatch between the resource value and the true status bar size (and issues like [this one](facebook#33612) popped up). The recommended approach is to instead call `getInsets` with the proper status bar and navigation flags provided by `WindowInsets`. On older APIs where `getInsets` is not supported, we have access to `systemWindowInsetTop`. Changelog: [Android][Fixed] - Fixed StatusBar.currentHeight calculations to honor all cutout sizes Differential Revision: D58088036
Summary: Google has discouraged attempting to read the `status_bar_height` resource [since 2017](https://youtu.be/_mGDMVRO3iE?si=qGQd7gLa_qTmfLGL&t=1079). With the introduction of display cutouts there can be a mismatch between the resource value and the true status bar size (and issues like [this one](facebook#33612) popped up). The recommended approach is to instead call `getInsets` with the proper status bar and navigation flags provided by `WindowInsets`. On older APIs where `getInsets` is not supported, we have access to `systemWindowInsetTop`. Changelog: [Android][Fixed] - Fixed StatusBar.currentHeight calculations to honor all cutout sizes Reviewed By: tdn120 Differential Revision: D58088036
Summary: Pull Request resolved: #44805 Google has discouraged attempting to read the `status_bar_height` resource [since 2017](https://youtu.be/_mGDMVRO3iE?si=qGQd7gLa_qTmfLGL&t=1079). With the introduction of display cutouts there can be a mismatch between the resource value and the true status bar size (and issues like [this one](#33612) popped up). The recommended approach is to instead call `getInsets` with the proper status bar and navigation flags provided by `WindowInsets`. On older APIs where `getInsets` is not supported, we have access to `systemWindowInsetTop`. Changelog: [Android][Fixed] - Fixed StatusBar.currentHeight calculations to honor all cutout sizes Reviewed By: tdn120 Differential Revision: D58088036 fbshipit-source-id: 9c035a79cbb96db1cf3b5b5c36242df7453fe205
Summary: Pull Request resolved: facebook#44697 Google has discouraged attempting to read the `status_bar_height` resource [since 2017](https://youtu.be/_mGDMVRO3iE?si=qGQd7gLa_qTmfLGL&t=1079). With the introduction of display cutouts there can be a mismatch between the resource value and the true status bar size (and issues like [this one](facebook#33612) popped up). The recommended approach is to instead call `getInsets` with the proper status bar and navigation flags provided by `WindowInsets`. On older APIs where `getInsets` is not supported, we have access to `systemWindowInsetTop`. Changelog: [Android][Fixed] - Fixed StatusBar.currentHeight calculations to honor all cutout sizes Reviewed By: cipolleschi, alanleedev Differential Revision: D57878119 fbshipit-source-id: 9fadd33d5f9b617a70a052c98dbd53fd29281650
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 marginExpected:
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
and0.64.2
Steps to reproduce
StatusBar.currentHeight
Snack, code example, screenshot, or link to a repository
https://snack.expo.dev/qXx7COUDg
The text was updated successfully, but these errors were encountered: