From 503ec8b03430a07ce69cbfd7952af21e26144a80 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Fri, 17 Apr 2020 16:13:38 -0400 Subject: [PATCH] feat: allow setting light mode on bars --- .../bhavan/RNNavBarColor/RNNavBarColorModule.java | 14 ++++++++++++-- index.js | 6 +++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/android/src/main/java/com/bhavan/RNNavBarColor/RNNavBarColorModule.java b/android/src/main/java/com/bhavan/RNNavBarColor/RNNavBarColorModule.java index e204142..a1d91d6 100644 --- a/android/src/main/java/com/bhavan/RNNavBarColor/RNNavBarColorModule.java +++ b/android/src/main/java/com/bhavan/RNNavBarColor/RNNavBarColorModule.java @@ -4,7 +4,7 @@ import android.app.Activity; import android.view.Window; import android.graphics.Color; import android.os.Build; - +import android.view.View; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.Callback; import com.facebook.react.bridge.ReadableMap; @@ -27,7 +27,7 @@ public class RNNavBarColorModule extends ReactContextBaseJavaModule { } @ReactMethod - public void setColor(final String color) { + public void setColor(final String color, final boolean isLight) { final Activity activity = getCurrentActivity(); final int colorInt = Color.parseColor(color); if(activity == null) @@ -36,6 +36,16 @@ public class RNNavBarColorModule extends ReactContextBaseJavaModule { activity.runOnUiThread(new Runnable() { @Override public void run() { + int flags = activity.getWindow().getDecorView().getSystemUiVisibility(); + if(isLight){ + flags = flags | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; + flags = flags | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; + activity.getWindow().getDecorView().setSystemUiVisibility(flags); + } else { + flags = flags ^ View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; + flags = flags ^ View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; + activity.getWindow().getDecorView().setSystemUiVisibility(flags); + } activity.getWindow().setNavigationBarColor(colorInt); } }); diff --git a/index.js b/index.js index f0aeedc..a9cea1d 100644 --- a/index.js +++ b/index.js @@ -8,9 +8,9 @@ module.exports = { return NavigationBar.apiLevel; } }, - setColor: (color) => { + setColor: (color, isLight) => { if (Platform.OS == 'android' && NavigationBar.apiLevel >= 21) { - return NavigationBar.setColor(color); + return NavigationBar.setColor(color, isLight); } }, setStatusBarColor: (color, animation) => { @@ -29,4 +29,4 @@ module.exports = { return StatusBar.setBarStyle('default', animation); } } -} \ No newline at end of file +}