Added Status Bar and Fixed navbar to api level > 21
This commit is contained in:
parent
525bece3cf
commit
d096448d48
|
@ -3,6 +3,7 @@ package com.bhavan.RNNavBarColor;
|
|||
import android.app.Activity;
|
||||
import android.view.Window;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
|
@ -13,26 +14,35 @@ import com.facebook.react.bridge.ReactContext;
|
|||
import com.facebook.react.bridge.ReactMethod;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class RNNavBarColorModule extends ReactContextBaseJavaModule {
|
||||
public RNNavBarColorModule(ReactApplicationContext reactContext) {
|
||||
super(reactContext);
|
||||
}
|
||||
public RNNavBarColorModule(ReactApplicationContext reactContext) {
|
||||
super(reactContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "RNNavBarColor";
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return "RNNavBarColor";
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void setColor(final String color) {
|
||||
final Activity activity = getCurrentActivity();
|
||||
final int colorInt = Color.parseColor(color);
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
activity.getWindow().setNavigationBarColor(colorInt);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getConstants() {
|
||||
HashMap<String, Object> constants = new HashMap<String, Object>();
|
||||
constants.put("apiLevel", Build.VERSION.SDK_INT);
|
||||
return constants;
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void setColor(final String color) {
|
||||
final Activity activity = getCurrentActivity();
|
||||
final int colorInt = Color.parseColor(color);
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
activity.getWindow().setNavigationBarColor(colorInt);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
31
index.js
31
index.js
|
@ -1,3 +1,30 @@
|
|||
import { NativeModules } from 'react-native'
|
||||
import { Platform, StatusBar, NativeModules } from 'react-native'
|
||||
|
||||
export default NativeModules.RNNavBarColor
|
||||
let NavigationBar = NativeModules.RNNavBarColor;
|
||||
|
||||
module.exports = {
|
||||
getAPILevel: () => {
|
||||
if (Platform.OS == 'android') {
|
||||
return NavigationBar.apiLevel;
|
||||
}
|
||||
},
|
||||
setColor: (color) => {
|
||||
if (Platform.OS == 'android' && NavigationBar.apiLevel >= 21) {
|
||||
return NavigationBar.setColor(color);
|
||||
}
|
||||
},
|
||||
setStatusBarColor: (color, animation) => {
|
||||
return StatusBar.setBackgroundColor(color, animation);
|
||||
},
|
||||
setStatusBarTheme: (theme, animation) => {
|
||||
if (theme == 'light') {
|
||||
return StatusBar.setBarStyle('light-content', animation);
|
||||
}
|
||||
else if (theme == 'dark') {
|
||||
return StatusBar.setBarStyle('dark-content', animation);
|
||||
}
|
||||
else {
|
||||
return StatusBar.setBarStyle('default', animation);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue