react-native-navigation-bar-color: Looks like setting buttons color does not work

I’m trying to set white natigation bar color with dark buttons:

import changeNavigationBarColor from 'react-native-navigation-bar-color';
...
changeNavigationBarColor('#ffffff', false);

But looks like it does not work - the buttons are always white. screenshot_1527586464

Just in case I’ve tried to set changeNavigationBarColor(‘#ffffff’, true); Nothing changed.

I’ve tested it on androids from 6 to 8.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 25 (8 by maintainers)

Most upvoted comments

On API 33 if theme is changed (ie. light to dark or dark to light), while the app is open in the background, the navigation bar color scheme isn’t being picked up as far as button foreground color is concerned when the app is brought to foreground… (I think this behaviour likely started with API 30+ because that’s when SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR got deprecated)

When I update setNavigationBarTheme function as follows it seems to work better (ie. app picks up light <-> dark theme changes as far as button color is concerned without needing to be restarted):

 public void setNavigationBarTheme(Activity activity, Boolean light) {
        if (activity != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            Window window = activity.getWindow();
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
                int flags = window.getDecorView().getSystemUiVisibility();            
                if (light) {
                    flags |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
                } else {
                    flags &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
                }
                window.getDecorView().setSystemUiVisibility(flags);
            } 
            else {
                WindowInsetsController insetsController = window.getInsetsController();
                if (light) {
                    insetsController.setSystemBarsAppearance(
                        WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS,
                        WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS
                    );
                }
                else {
                    insetsController.setSystemBarsAppearance(
                        0,
                        WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS
                    );
                }
            }
        }
    }

Maybe it’s worthwhile updating the package with something similar to the above ?

add setTimeout(() => { changeNavigationBarColor('white', true); }, 1000); works fine