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

fix(android): status bar black strip fixed #46086

Closed

Conversation

shubhamguptadream11
Copy link
Collaborator

Summary:

Fixes these issues:

Changelog:

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

setHidden function is responsible for hiding status bar

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:

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

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

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Aug 18, 2024
@facebook-github-bot
Copy link
Contributor

@alanleedev has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@alanleedev
Copy link
Contributor

@shubhamguptadream11 Thanks for fixing this issue. It seems to work great.

@shubhamguptadream11
Copy link
Collaborator Author

@alanleedev Thank you! I'm glad the fix worked well.

@alanleedev
Copy link
Contributor

alanleedev commented Aug 20, 2024

@shubhamguptadream11 I am making minor formatting change and fixing the version check as you used P instead or R.

@shubhamguptadream11
Copy link
Collaborator Author

@alanleedev Ohh okay. Thanks for this.
I forgot to change in PR. Updated my PR description.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Aug 20, 2024
@facebook-github-bot
Copy link
Contributor

@alanleedev merged this pull request in f6b6d00.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @shubhamguptadream11 in f6b6d00

When will my fix make it into a release? | How to file a pick request?

@dgabriele
Copy link

This didn't fix it for me. Running Pixel 8a

@alanleedev
Copy link
Contributor

alanleedev commented Nov 5, 2024

This didn't fix it for me. Running Pixel 8a

@dgabriele How did you test? Which RN version did you use?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants