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

Light & Animated Flag not working in 2.0.2 #62

Open
mcritter42 opened this issue Apr 10, 2023 · 1 comment
Open

Light & Animated Flag not working in 2.0.2 #62

mcritter42 opened this issue Apr 10, 2023 · 1 comment

Comments

@mcritter42
Copy link

on version 2.0.2 the light flag nor the animated flag are working as expected, would always revert to the defaults.
experienced on android 13 pixel 6 using react-native 0.70.6.

changeNavigationBarColor(
'#FFFFFF',
true
true,
);

    would result in white icons and a while background.
    downgraded to 2.0.1 and this issue was not present. 
@Off2Race
Copy link

Off2Race commented Oct 5, 2024

Hi, @mcritter42 – The issue you're experiencing is due to a change in the Android APIs. The method used by this library to change the nav bar icons from light to dark doesn't seem to work for API level 30 (Android 11) or greater.

I was able to fix the issue by applying the following patch:

diff --git a/node_modules/react-native-navigation-bar-color/android/src/main/java/com/thebylito/navigationbarcolor/NavigationBarColorModule.java b/node_modules/react-native-navigation-bar-color/android/src/main/java/com/thebylito/navigationbarcolor/NavigationBarColorModule.java
index b3edac7..fe7602c 100644
--- a/node_modules/react-native-navigation-bar-color/android/src/main/java/com/thebylito/navigationbarcolor/NavigationBarColorModule.java
+++ b/node_modules/react-native-navigation-bar-color/android/src/main/java/com/thebylito/navigationbarcolor/NavigationBarColorModule.java
@@ -11,6 +11,7 @@ import android.app.Activity;
 import android.view.View;
 import android.view.Window;
 import android.view.WindowManager;
+import android.view.WindowInsetsController;
 import androidx.annotation.UiThread;
 import com.facebook.react.bridge.Arguments;
 import com.facebook.react.bridge.Promise;
@@ -44,6 +45,17 @@ public class NavigationBarColorModule extends ReactContextBaseJavaModule {
     }
 
     public void setNavigationBarTheme(Activity activity, Boolean light) {
+        if (activity != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+            Window window = activity.getWindow();
+            int lightNavBarFlag = WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
+            if (light) {
+                window.getDecorView().getWindowInsetsController().setSystemBarsAppearance(lightNavBarFlag, lightNavBarFlag);
+            } else {
+                window.getDecorView().getWindowInsetsController().setSystemBarsAppearance(0, lightNavBarFlag);
+            }
+            return;
+        }
+
         if (activity != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
             Window window = activity.getWindow();
             int flags = window.getDecorView().getSystemUiVisibility();

@thebylito – I'm happy to submit a PR for this change if you're interested in doing a new release. Just let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants