feat: allow setting light mode on bars
This commit is contained in:
parent
5f98a64f7a
commit
503ec8b034
|
@ -4,7 +4,7 @@ import android.app.Activity;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.view.View;
|
||||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||||
import com.facebook.react.bridge.Callback;
|
import com.facebook.react.bridge.Callback;
|
||||||
import com.facebook.react.bridge.ReadableMap;
|
import com.facebook.react.bridge.ReadableMap;
|
||||||
|
@ -27,7 +27,7 @@ public class RNNavBarColorModule extends ReactContextBaseJavaModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void setColor(final String color) {
|
public void setColor(final String color, final boolean isLight) {
|
||||||
final Activity activity = getCurrentActivity();
|
final Activity activity = getCurrentActivity();
|
||||||
final int colorInt = Color.parseColor(color);
|
final int colorInt = Color.parseColor(color);
|
||||||
if(activity == null)
|
if(activity == null)
|
||||||
|
@ -36,6 +36,16 @@ public class RNNavBarColorModule extends ReactContextBaseJavaModule {
|
||||||
activity.runOnUiThread(new Runnable() {
|
activity.runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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);
|
activity.getWindow().setNavigationBarColor(colorInt);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
4
index.js
4
index.js
|
@ -8,9 +8,9 @@ module.exports = {
|
||||||
return NavigationBar.apiLevel;
|
return NavigationBar.apiLevel;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setColor: (color) => {
|
setColor: (color, isLight) => {
|
||||||
if (Platform.OS == 'android' && NavigationBar.apiLevel >= 21) {
|
if (Platform.OS == 'android' && NavigationBar.apiLevel >= 21) {
|
||||||
return NavigationBar.setColor(color);
|
return NavigationBar.setColor(color, isLight);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setStatusBarColor: (color, animation) => {
|
setStatusBarColor: (color, animation) => {
|
||||||
|
|
Loading…
Reference in New Issue