diff --git a/android/src/main/java/com/bhavan/RNNavBarColor/RNNavBarColorModule.java b/android/src/main/java/com/bhavan/RNNavBarColor/RNNavBarColorModule.java index 3502342..7cc5951 100644 --- a/android/src/main/java/com/bhavan/RNNavBarColor/RNNavBarColorModule.java +++ b/android/src/main/java/com/bhavan/RNNavBarColor/RNNavBarColorModule.java @@ -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 getConstants() { + HashMap constants = new HashMap(); + 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); - } - }); - } } \ No newline at end of file diff --git a/index.js b/index.js index 9be739c..2cab9c1 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,30 @@ -import { NativeModules } from 'react-native' +import { Platform, StatusBar, NativeModules } from 'react-native' -export default NativeModules.RNNavBarColor \ No newline at end of file +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); + } + } +} \ No newline at end of file