react-native icon indicating copy to clipboard operation
react-native copied to clipboard

getStatusBarHeightPx is initialized before decorview is attached

Open kevinpvh opened this issue 4 months ago • 9 comments

Description

Hi everyone, after I updated the app to 0.77.3. I noticed that on Android StatusBar.currentHeight always returns 0.

Through investigation I found that at file react-native/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.kt line 48

private fun getStatusBarHeightPx(): Float { val windowInsets = currentActivity?.window?.decorView?.let(ViewCompat::getRootWindowInsets) ?: return 0f return windowInsets .getInsets( WindowInsetsCompat.Type.statusBars() or WindowInsetsCompat.Type.navigationBars() or WindowInsetsCompat.Type.displayCutout()) .top .toFloat() }

Here use decorview's getRootWindowInsets.

The problem here is that this function is called before the decorview is attached, which causes currentActivity?.window?.decorView?.let(ViewCompat::getRootWindowInsets) to always return null, and getStatusBarHeightPx()

This happens more often in release mode, but sometimes in debug mode too. It's possible that in debug mode it takes longer for metro to attach, so there's enough time for the decorview to be attached before the StatusbarHeight is initialized.

Anyone else having the same problem?

Steps to reproduce

  1. init project with react-native 0.77.3
  2. set newArchEnabled=false in gradle.properties
  3. try to display something StatusBar.currentHeight
  4. npm run android

React Native Version

0.77.3

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info

--

Stacktrace or Logs

--

MANDATORY Reproducer

  1. init project with react-native 0.77.3
  2. set newArchEnabled=false in gradle.properties
  3. try to display something StatusBar.currentHeight
  4. npm run android

Screenshots and Videos

No response

kevinpvh avatar Aug 13 '25 16:08 kevinpvh

[!WARNING] Unsupported version: It looks like your issue or the example you provided uses an unsupported version of React Native.

Due to the number of issues we receive, we're currently only accepting new issues against one of the supported versions. Please upgrade to latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If you cannot upgrade, please open your issue on StackOverflow to get further community support.

react-native-bot avatar Aug 13 '25 16:08 react-native-bot

[!WARNING] Unsupported version: It looks like your issue or the example you provided uses an unsupported version of React Native.

Due to the number of issues we receive, we're currently only accepting new issues against one of the supported versions. Please upgrade to latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If you cannot upgrade, please open your issue on StackOverflow to get further community support.

react-native-bot avatar Aug 13 '25 16:08 react-native-bot

[!WARNING] Missing reproducer: We could not detect a reproducible example in your issue report. Reproducers are mandatory and we can accept only one of those as a valid reproducer:


You can read more about about it on our website: How to report a bug.

react-native-bot avatar Aug 13 '25 16:08 react-native-bot

@kevinpvh Hey can you verify you hare facing this on new arch as well, also on latest version of react native. Unsupported version: It looks like your issue or the example you provided uses an unsupported version of React Native.

JatinDream11 avatar Aug 17 '25 10:08 JatinDream11

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

react-native-bot avatar Sep 11 '25 05:09 react-native-bot

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

react-native-bot avatar Oct 05 '25 05:10 react-native-bot

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

react-native-bot avatar Oct 29 '25 05:10 react-native-bot

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

react-native-bot avatar Nov 22 '25 05:11 react-native-bot

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

react-native-bot avatar Dec 16 '25 05:12 react-native-bot