Skip to content
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

Hidden Status Bar results in black bar instead of transparent [Android 13, Google Pixel 6] #39362

Closed
jordanjuras opened this issue Sep 9, 2023 · 13 comments
Labels
Newer Patch Available Platform: Android Android applications. Resolution: Fixed A PR that fixes this issue has been merged.

Comments

@jordanjuras
Copy link

Description

Greetings,

Reporting a bug found in react-native Status Bar, specifically on Google Pixel 6. I have only been able to test on a Pixel 6 device setup with Android v13 (API 33).

In order to hide the status bar, and expose the view behind it, we do the following:

  StatusBar.setHidden(true);
  if (Platform.OS === 'android')
  {
    StatusBar.setBackgroundColor('transparent');
    StatusBar.setTranslucent(true);
  }

On Pixel 6, this does not work, and instead the status bar is rendered as a black bar, entirely covering the status bar area.

The bug does not reproduce on any of the following devices available to me:

  • Google Pixel 3 Android v11
  • Samsung Galaxy s9 Android v10
  • Android Pixel 6 v13 EMULATOR

EXPECTED:
Pixel 3 & Galaxy s9 - init state
Pixel3_v11_and_GalaxyS9_v10_statusbar_initState

Pixel 3 & Galaxy s9 - touched
Pixel3_v11_and_GalaxyS9_v10_statusbar_touched

ACTUAL:
Pixel 6 - init state
Pixel6_v13_statusbar_initState

Pixel 6 - touched
Pixel6_v13_statusbar_touched

React Native Version

0.71.7

Output of npx react-native info

System:
    OS: macOS 13.4.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 60.08 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.4.0 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.7.2 - /opt/homebrew/bin/npm
    Watchman: 2023.07.10.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.12.1 - /Users/joju/.rbenv/shims/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.3 AI-213.7172.25.2113.9014738
    Xcode: 14.3.1/14E300c - /usr/bin/xcodebuild
  Languages:
    Java: 20.0.1 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0
    react-native: 0.71.7 => 0.71.7
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

On Google Pixel 6, create react native app with the following component

import { Component } from "react";
import { Platform, StatusBar, View } from "react-native";

export default class App extends Component<{},{}> {

  componentDidMount() {

    StatusBar.setHidden(true);
    if (Platform.OS === 'android')
    {
      StatusBar.setBackgroundColor('transparent');
      StatusBar.setTranslucent(true);
    }
      
  }

  render() {
    return (
      <View style={{flex: 1, backgroundColor:'blue'}}/>
    );
  }

}

Snack, screenshot, or link to a repository

https://snack.expo.dev/Kdn-2a-rX

@github-actions
Copy link

github-actions bot commented Sep 9, 2023

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - 0.71.13. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@github-actions github-actions bot added the Platform: Android Android applications. label Sep 9, 2023
@jordanjuras
Copy link
Author

I have tested and the issue is reproducible on react native version 0.71.13

@jordanjuras
Copy link
Author

I have just confirmed that the issue also reproduces on Google Pixel 7 Android v13.

@IamMasterWayne
Copy link

+1

@yaroslavnikiforov
Copy link

The same issue is on Android 14 and react-native 0.69.9.

@jrpn93
Copy link

jrpn93 commented Apr 10, 2024

Same issue here!
<StatusBar hidden={true} />will result in black areas on some devices in Android 13 & 14.
Devices like the Google Pixel 6 and MIUI devices have camera cut-outs.

@jrpn93
Copy link

jrpn93 commented Apr 10, 2024

Okay, I found a solution pretty quickly!
Adding <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item> in my android/app/src/main/res/values/styles.xml resolved this issue.
just use <StatusBar hidden={true} /> after adding & Rebuilding your react native android app

Found Here :
expo/expo#15244 (comment)

@yaroslavnikiforov
Copy link

Thanks @jrpn93

@AustineA
Copy link

Okay, I found a solution pretty quickly! Adding <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item> in my android/app/src/main/res/values/styles.xml resolved this issue. just use <StatusBar hidden={true} /> after adding & Rebuilding your react native android app

Found Here : expo/expo#15244 (comment)

This doesn't work on Samsung devices

@jim-king-2000
Copy link

jim-king-2000 commented Aug 16, 2024

The same issue on Samsung Galaxy A54. But sometimes it shows transparent status bar. Any solution?

Weixin Image_20240816102314

@shubhamguptadream11
Copy link
Collaborator

I am also facing this issue.
Not working in OnePlus, Vivo.

I tried creating sample android app as well.
Without following approaches but didn't worked.

Approach 1:
//    private fun hideStatusBar() {
//        window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
//        actionBar?.hide()
//    }
//
//    private fun showStatusBar() {
//        window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
//        actionBar?.show()
//    }

Approach 2:
//    fun hideStatusBar(activity: Activity) {
//        activity.window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
//    }
//
//    fun showStatusBar(activity: Activity) {
//        activity.window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
//    }

Is this an issue with all such devices with camera notch at top?

@shubhamguptadream11
Copy link
Collaborator

I had shared my findings regarding this here: #46070 (comment)
Also shared one fix. Let me know if it fixes this.

facebook-github-bot pushed a commit that referenced this issue Aug 20, 2024
Summary:
Fixes these issues:
- #46070
- #39362

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[ANDROID] [FIXED] - Fixed black strip coming when hiding status bar

`setHidden` function is responsible for hiding status bar

https://github.com/facebook/react-native/blob/25d6a152cc720e0d5f860dab228ac2e43321d9e4/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.kt#L122

**What real issue is?** **_For android devices with camera area on top a black strip is coming after hidding status bar._**

Previous Implementation:
```
  override fun setHidden(hidden: Boolean) {
    val activity = currentActivity
    if (activity == null) {
      Log.w(
          ReactConstants.TAG,
          "StatusBarModule: Ignored status bar change, current activity is null.")
      return
    }
    UiThreadUtil.runOnUiThread(
        Runnable {
          val window = activity.window ?: return@Runnable
          if (hidden) {
            window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
            window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN)
          } else {
            window.addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN)
            window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
          }
        })
  }
```
It seems that FLAG_FULLSCREEN flag are not enough to draw content in camera area.

**Solution:**
In order to tackle this, android exposes 2 flags:
- [layoutInDisplayCutOutMode](https://developer.android.com/reference/android/view/WindowManager.LayoutParams#layoutInDisplayCutoutMode):  The window is always allowed to extend into the [DisplayCutout](https://developer.android.com/reference/android/view/DisplayCutout) areas on the short edges of the screen. [Android 9.0 and above]
- [setDecorFitsSystemWindows](https://developer.android.com/reference/android/view/Window#setDecorFitsSystemWindows(boolean)):  allows content to be able to extend into the cutout area. [Android 10.0 and above]

By adding this flag we are now able to hide status bar properly.
```
  override fun setHidden(hidden: Boolean) {
    val activity = currentActivity
    if (activity == null) {
      FLog.w(
          ReactConstants.TAG,
          "StatusBarModule: Ignored status bar change, current activity is null.")
      return
    }
    UiThreadUtil.runOnUiThread(
        Runnable {
          val window = activity.window ?: return@Runnable
          if (hidden) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
              // Ensure the content extends into the cutout area
              window.attributes.layoutInDisplayCutoutMode =
                WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
              window.setDecorFitsSystemWindows(false)
            }
            window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
            window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN)
          } else {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
              window.attributes.layoutInDisplayCutoutMode =
                WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT
              window.setDecorFitsSystemWindows(true)
            }
            window.addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN)
            window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
          }
        })
  }
```

**_Note: This will work above Android 11 and above_**

Pull Request resolved: #46086

Test Plan:
- Tested by author of this issue
- Sharing here the videos of before and after fix

Device Detail:
Oneplus9 5G OS 11
**Before fix:**
https://github.com/user-attachments/assets/589098ff-a3fa-4962-a15b-ceacbfd03d2d

**After fix:**
https://github.com/user-attachments/assets/a87dd8e4-3624-4e09-99da-a14f9e19fcc6

Reviewed By: cipolleschi

Differential Revision: D61509889

Pulled By: alanleedev

fbshipit-source-id: 733962a3bed2efba71588a4d2fdf7c9c386bc3b4
@shubhamguptadream11
Copy link
Collaborator

@jordanjuras This is fixed in above linked PR.
We can mark this closed now.

@cortinico cortinico added Resolution: Fixed A PR that fixes this issue has been merged. and removed Needs: Triage 🔍 labels Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Newer Patch Available Platform: Android Android applications. Resolution: Fixed A PR that fixes this issue has been merged.
Projects
None yet
Development

No branches or pull requests

8 participants