Added Status Bar and Fixed navbar to api level > 21

This commit is contained in:
Bhavan 2018-03-15 10:31:40 +05:30
parent 525bece3cf
commit d096448d48
2 changed files with 57 additions and 20 deletions

View File

@ -3,6 +3,7 @@ package com.bhavan.RNNavBarColor;
import android.app.Activity; 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 com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.Callback; import com.facebook.react.bridge.Callback;
@ -13,6 +14,7 @@ import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.ReactMethod;
import java.util.Map; import java.util.Map;
import java.util.HashMap;
public class RNNavBarColorModule extends ReactContextBaseJavaModule { public class RNNavBarColorModule extends ReactContextBaseJavaModule {
public RNNavBarColorModule(ReactApplicationContext reactContext) { public RNNavBarColorModule(ReactApplicationContext reactContext) {
@ -35,4 +37,12 @@ public class RNNavBarColorModule extends ReactContextBaseJavaModule {
} }
}); });
} }
@Override
public Map<String, Object> getConstants() {
HashMap<String, Object> constants = new HashMap<String, Object>();
constants.put("apiLevel", Build.VERSION.SDK_INT);
return constants;
}
} }

View File

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