Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a297817
Showing
10 changed files
with
310 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Android/IJ | ||
.DS_Store | ||
.idea/workspace.xml | ||
.idea/libraries | ||
.gradle | ||
local.properties | ||
*.iml | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Android/IJ | ||
.idea/workspace.xml | ||
.idea/libraries | ||
.gradle | ||
local.properties | ||
*.iml | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Nishanth Shankar | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# React Native Android Status bar | ||
|
||
|
||
|
||
A react native android module to control the android statusbar. | ||
|
||
## Setup | ||
|
||
* install module | ||
|
||
This module is currently inactive | ||
```bash | ||
# npm i --save react-native-android-statusbar | ||
``` | ||
|
||
* `android/settings.gradle` | ||
|
||
```gradle | ||
... | ||
include ':react-native-android-statusbar' | ||
project(':react-native-android-statusbar').projectDir = new File(settingsDir, '../node_modules/react-native-android-statusbar') | ||
``` | ||
|
||
* `android/app/build.gradle` | ||
|
||
```gradle | ||
... | ||
dependencies { | ||
... | ||
compile project(':react-native-android-statusbar') | ||
} | ||
``` | ||
|
||
* register module (in MainActivity.java) | ||
|
||
```java | ||
import me.neo.react.StatusBarPackage; // <--- import | ||
|
||
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler { | ||
|
||
...... | ||
private static Activity mActivity = null; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
mReactRootView = new ReactRootView(this); | ||
|
||
mActivity = this; | ||
mReactInstanceManager = ReactInstanceManager.builder() | ||
.setApplication(getApplication()) | ||
.setBundleAssetName("index.android.bundle") | ||
.setJSMainModuleName("index.android") | ||
.addPackage(new MainReactPackage()) | ||
.addPackage(new StatusBarPackage()) // <------- add package | ||
.setUseDeveloperSupport(BuildConfig.DEBUG) | ||
.setInitialLifecycleState(LifecycleState.RESUMED) | ||
.build(); | ||
|
||
mReactRootView.startReactApplication(mReactInstanceManager, "ExampleRN", null); | ||
|
||
setContentView(mReactRootView); | ||
} | ||
|
||
//Add this static function | ||
public static Activity getActivity(){ | ||
Activity activity = new Activity(); | ||
activity = mCurrentActivity; | ||
return activity; | ||
} | ||
|
||
...... | ||
|
||
} | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
var StatusBarAndroid = require('react-native-android-statusbar'); | ||
|
||
|
||
StatusBarAndroid.hideStatusBar() // Does not reflect on versions before 16 | ||
StatusBarAndroid.showStatusBar() // Does not reflect on versions before 16 | ||
StatusBarAndroid.setRGB(int red, int green, int blue);// Does not reflect on versions before 21 | ||
StatusBarAndroid.setARGB(int alpha,int red, int green, int blue);// Does not reflect on versions before 21 | ||
StatusBarAndroid.setHexColor('#AB1223'); // Does not reflect on versions before 21 | ||
/*Supported formats are: #RRGGBB #AARRGGBB | ||
or one of the following names: 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray', 'grey', 'lightgrey', 'darkgrey', 'aqua', 'fuchsia', 'lime', 'maroon', 'navy', 'olive', 'purple', 'silver', 'teal'.*/ | ||
|
||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
buildscript { | ||
repositories { | ||
jcenter() | ||
} | ||
|
||
dependencies { | ||
classpath 'com.android.tools.build:gradle:1.1.3' | ||
} | ||
} | ||
|
||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion 23 | ||
buildToolsVersion "23.0.1" | ||
|
||
defaultConfig { | ||
minSdkVersion 16 | ||
targetSdkVersion 22 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
lintOptions { | ||
abortOnError false | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
compile 'com.facebook.react:react-native:0.11.+' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
var { NativeModules } = require('react-native'); | ||
module.exports = NativeModules.StatusBarAndroid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "react-native-android-statusbar", | ||
"description": "A react native android package to control the status bar.", | ||
"version": "0.1.0", | ||
"main": "index.android.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:NishanthShankar/react-native-android-statusbar.git" | ||
}, | ||
"author": "Nishanth Shankar <NishanthShankr@gmail.com>", | ||
"license": "MIT", | ||
"homepage": "", | ||
"peerDependencies": { | ||
"react-native": "^0.11.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="me.neo.react" > | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package me.neo.react; | ||
|
||
import android.app.Activity; | ||
import android.graphics.Color; | ||
import android.os.Build; | ||
import android.view.View; | ||
import android.view.Window; | ||
import android.view.WindowManager; | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.facebook.react.bridge.ReadableArray; | ||
|
||
/** | ||
* Created by Nishanth Shankar on 9/24/15. | ||
*/ | ||
public class StatusBarModule extends ReactContextBaseJavaModule { | ||
Activity mActivity = null; | ||
public StatusBar(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
mActivity = MainActivity.getActivity(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "StatusBarAndroid"; | ||
} | ||
|
||
@ReactMethod | ||
public void setHexColor(String hex){ | ||
int color = Color.parseColor(hex); | ||
setStatusColor(color); | ||
} | ||
|
||
@ReactMethod | ||
public void setRGB(int r, int g, int b){ | ||
int color = Color.rgb(r,g,b); | ||
setStatusColor(color); | ||
} | ||
|
||
@ReactMethod | ||
public void setARGB(int a,int r, int g, int b){ | ||
int color = Color.argb(a, r, g, b); | ||
setStatusColor(color); | ||
} | ||
|
||
void setStatusColor(final int color){ | ||
mActivity.runOnUiThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
if(Build.VERSION.SDK_INT >= 21){ | ||
Window window = mActivity.getWindow(); | ||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | ||
window.setStatusBarColor(color); | ||
|
||
} | ||
|
||
} | ||
}); | ||
|
||
} | ||
|
||
|
||
@ReactMethod | ||
public void hideStatusBar(){ | ||
mActivity.runOnUiThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
View decorView = mActivity.getWindow().getDecorView(); | ||
// Hide the status bar. | ||
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; | ||
decorView.setSystemUiVisibility(uiOptions); | ||
} | ||
}); | ||
} | ||
|
||
@ReactMethod | ||
public void showStatusBar(){ | ||
mActivity.runOnUiThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
if(Build.VERSION.SDK_INT < 16) | ||
return; | ||
View decorView = mActivity.getWindow().getDecorView(); | ||
// Hide the status bar. | ||
int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE; | ||
decorView.setSystemUiVisibility(uiOptions); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package me.neo.react; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.JavaScriptModule; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by Nishanth Shankar on 9/23/15. | ||
*/ | ||
public class StatusBarPackage implements ReactPackage { | ||
@Override | ||
public List<NativeModule> createNativeModules(ReactApplicationContext reactApplicationContext) { | ||
List<NativeModule> modules = new ArrayList<>(); | ||
modules.add(new StatusBarModule(reactApplicationContext)); | ||
return modules; | ||
} | ||
|
||
@Override | ||
public List<Class<? extends JavaScriptModule>> createJSModules() { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public List<ViewManager> createViewManagers(ReactApplicationContext reactApplicationContext) { | ||
return Arrays.<ViewManager>asList(); | ||
} | ||
} |