feat: allow setting light mode on bars

This commit is contained in:
Richard Ramos 2020-04-17 16:13:38 -04:00
parent 5f98a64f7a
commit 503ec8b034
No known key found for this signature in database
GPG Key ID: 80D4B01265FDFE8F
2 changed files with 15 additions and 5 deletions

View File

@ -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);
}
});

View File

@ -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);
}
}
}
}