question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`StatusBar.currentHeight` gives incorrect height on Google Pixel 5a (Android 12)

See original GitHub issue

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: Screen Shot 2022-04-11 at 2 43 54 PM

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

  1. use StatusBar.currentHeight
  2. 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

https://snack.expo.dev/qXx7COUDg

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:10
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
cristianoccazinspcommented, Apr 18, 2022

Not just Pixel 5a, but many devices that may have a notch.

2reactions
julienR2commented, Jun 9, 2022

Hi ! We quick fixed it statically until we have time to tackle it properly or it gets fixed. It look like this:

import { initialWindowMetrics } from 'react-native-safe-area-context'
import { hasNotch } from 'react-native-device-info'

const getStatusBarHeight = () => {
  if (isIos) {
    return hasNotch() ? 44 : 20
  }
  return initialWindowMetrics?.insets.top || 0
}

The initialWindowMetrics?.insets.top actually returns the correct insets. (Obviously it would be better to use a useInsets and the context to be sure to have it updated in case it change dynamically)

Let me know if it’s unclear !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pixel 6 & 6 Pro 'incorrect status bar height relative to camera ...
Many Pixel 6 and 6 Pro users are now reporting that the level of the status bar has moved up relative to the...
Read more >
How to find height of status bar in Android through React ...
HEIGHT will give you the current height of the Status Bar on Android. import { Platform, NativeModules } from 'react-native'; const { StatusBarManager...
Read more >
Statusbar Size Fix | XDA Forums
Here's a workaround on getting a smaller statusbar area if you have root. Flash the attached zip in magisk manager. Go to developer...
Read more >
TextureView - Android Developers
Boolean internal attribute to adjust view layout based on system windows such as the status bar. If true, adjusts the padding of this...
Read more >
The status bar on the pixel 5 is way too tall - Reddit
It shifts the position of the hole punch, it's size, and its padding. You end up with more usable screen, but it looks...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found