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
- init project with react-native 0.77.3
- set newArchEnabled=false in gradle.properties
- try to display something StatusBar.currentHeight
- 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
- init project with react-native 0.77.3
- set newArchEnabled=false in gradle.properties
- try to display something StatusBar.currentHeight
- npm run android
Screenshots and Videos
No response
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
React Native Version
0.77.3
Affected Platforms
Runtime - Android
Output of
npx @react-native-community/cli infoStacktrace or Logs
MANDATORY Reproducer
Screenshots and Videos
No response