Skip to content

setBarStyle can miss modern status-bar appearance on Android 12+ #80

Description

@huxinhai

Environment

  • react-native-system-navigation-bar: 3.0.0
  • React Native: 0.85.0
  • AndroidX Core resolved by the app: 1.18.0
  • Device: Xiaomi Mi 10S, Android 12 / API 31
  • targetSdkVersion: 36

Reproduction

  1. Render content behind a transparent status bar.
  2. Call setBarStyle('dark', 'status') so the light background uses dark status-bar icons.
  3. Remove the app from recents and launch it again from the launcher.

On this device the icons become white after relaunch. The same sequence did not reproduce on an Android emulator.

Expected behavior

The status-bar icons remain dark after setBarStyle('dark', 'status') resolves.

Actual behavior and diagnostics

The promise resolves, and WindowInsetsControllerCompat.isAppearanceLightStatusBars reads back true, but the icons remain white.

WindowManager showed only the legacy flag:

vsysui=... LIGHT_STATUS_BAR

The app window did not have the corresponding modern appearance:

apr=LIGHT_STATUS_BARS

The readback is therefore a false positive on this path. AndroidX's API 30 implementation reads and writes systemUiVisibility whenever the compat controller was constructed with a Window, which is the path used by WindowCompat.getInsetsController(window, window.decorView):

https://github.com/androidx/androidx/blob/androidx-main/core/core/src/main/java/androidx/core/view/WindowInsetsControllerCompat.java#L660-L710

React Native's Android 12+ status-bar implementation instead calls the platform WindowInsetsController.setSystemBarsAppearance API directly:

https://github.com/facebook/react-native/blob/v0.85.0/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.kt#L125-L160

Proposed fix

For API levels above Android 11, use window.insetsController.setSystemBarsAppearance(...) directly with a mask for the requested status/navigation bar. Keep the current compat implementation on Android 11 and below.

I tested that change on the affected Xiaomi device. The same remove-from-recents and launcher-reopen sequence produced:

apr=LIGHT_STATUS_BARS

and the icons remained dark through two fresh-process relaunches. Calls targeting only the status bar continued to leave the navigation-bar appearance untouched.

I can send a focused PR with this change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions