Compare commits
No commits in common. "master" and "doc-update" have entirely different histories.
master
...
doc-update
3
.github/workflows/npmpublish.yml
vendored
3
.github/workflows/npmpublish.yml
vendored
@ -1,6 +1,9 @@
|
||||
name: Node.js Package
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
125
README.md
125
README.md
@ -20,9 +20,6 @@ React Native Navigation Bar Color Change is a [React Native](http://facebook.git
|
||||
- [API](#api)
|
||||
- [License](#license)
|
||||
|
||||
## Support
|
||||
<a href="https://www.buymeacoffee.com/thebylito"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" target="_blank"></a>
|
||||
|
||||
## Installation
|
||||
|
||||
<details>
|
||||
@ -70,81 +67,76 @@ or
|
||||
|
||||
## Example
|
||||
|
||||
<details>
|
||||
<summary>**Android Implementation**</summary>
|
||||
|
||||
**Android Implementation**
|
||||
```javascript
|
||||
import React from 'react';
|
||||
import {View, Text, Button} from 'react-native';
|
||||
import React, { Component } from 'react';
|
||||
import { View, Text, Button } from 'react-native';
|
||||
import changeNavigationBarColor, {
|
||||
hideNavigationBar,
|
||||
showNavigationBar,
|
||||
HideNavigationBar,
|
||||
ShowNavigationBar,
|
||||
} from 'react-native-navigation-bar-color';
|
||||
|
||||
export default function App() {
|
||||
const setNavigationColor = color => {
|
||||
export default class Mynewapp extends Component {
|
||||
setNavigationColor = (color) => {
|
||||
changeNavigationBarColor(color);
|
||||
};
|
||||
const hideNavigation = () => {
|
||||
hideNavigationBar();
|
||||
hideNavigation() {
|
||||
HideNavigationBar();
|
||||
};
|
||||
|
||||
const showNavigation = () => {
|
||||
showNavigationBar();
|
||||
showNavigation() {
|
||||
ShowNavigationBar();
|
||||
};
|
||||
|
||||
const testSetTranslucent = () => {
|
||||
changeNavigationBarColor('translucent', false);
|
||||
};
|
||||
|
||||
const testSetTransparent = () => {
|
||||
changeNavigationBarColor('transparent', true);
|
||||
};
|
||||
|
||||
return (
|
||||
<View
|
||||
style={{
|
||||
flex: 1,
|
||||
justifyContent: 'space-around',
|
||||
alignContent: 'center',
|
||||
alignItems: 'center',
|
||||
backgroundColor: 'cyan',
|
||||
}}>
|
||||
<Button title="Set transparent" onPress={testSetTransparent} />
|
||||
<Button title="Set translucent" onPress={testSetTranslucent} />
|
||||
<Button
|
||||
title="Set color red"
|
||||
onPress={() => {
|
||||
setNavigationColor('red');
|
||||
render() {
|
||||
return (
|
||||
<View
|
||||
style={{
|
||||
flex: 1,
|
||||
justifyContent: 'space-around',
|
||||
alignContent: 'center',
|
||||
alignItems: 'center',
|
||||
backgroundColor: 'white'
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
title="Set color blue"
|
||||
onPress={() => {
|
||||
setNavigationColor('blue');
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
title="Set color ligth"
|
||||
onPress={() => {
|
||||
changeNavigationBarColor('#ffffff', true);
|
||||
}}
|
||||
/>
|
||||
<Button title="Hide bar" onPress={hideNavigation} />
|
||||
<Button title="Show bar" onPress={showNavigation} />
|
||||
<Text>Hello Word!</Text>
|
||||
</View>
|
||||
);
|
||||
>
|
||||
<Button
|
||||
title="Set color red"
|
||||
onPress={() => {
|
||||
this.setNavigationColor('red');
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
title="Set color blue"
|
||||
onPress={() => {
|
||||
this.setNavigationColor('blue');
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
title="Set color ligth"
|
||||
onPress={() => {
|
||||
changeNavigationBarColor('#ffffff', true);
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
title="Hide bar"
|
||||
onPress={this.hideNavigation}
|
||||
/>
|
||||
<Button
|
||||
title="Show bar"
|
||||
onPress={this.showNavigation}
|
||||
/>
|
||||
<Text>Hello Word!</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
## API
|
||||
|
||||
### `changeNavigationBarColor(color, Boolean(light icon color), Boolean(animated - default is true))`: (Android)
|
||||
Change color of Navigation/Bottom bar.
|
||||
color can be a "translucent" | "transparent" | HEX color, or name.
|
||||
|
||||
color can be a HEX color, or name.
|
||||
ex: green, blue, #80b3ff, #ffffff....
|
||||
|
||||
Light is true? icons will be dark.
|
||||
@ -177,25 +169,25 @@ Light is true? icons will be dark.
|
||||
};
|
||||
```
|
||||
|
||||
### `hideNavigationBar()`: (Android)
|
||||
### `HideNavigationBar()`: (Android)
|
||||
Hide Navigation Bar
|
||||
|
||||
```javascript
|
||||
import { hideNavigationBar } from 'react-native-navigation-bar-color';
|
||||
import { HideNavigationBar } from 'react-native-navigation-bar-color';
|
||||
...
|
||||
hide = () => {
|
||||
hideNavigationBar();
|
||||
HideNavigationBar();
|
||||
};
|
||||
```
|
||||
|
||||
### `showNavigationBar()`: (Android)
|
||||
### `ShowNavigationBar()`: (Android)
|
||||
Show Navigation Bar
|
||||
|
||||
```javascript
|
||||
import { showNavigationBar } from 'react-native-navigation-bar-color';
|
||||
import { ShowNavigationBar } from 'react-native-navigation-bar-color';
|
||||
...
|
||||
show = () => {
|
||||
showNavigationBar();
|
||||
ShowNavigationBar();
|
||||
};
|
||||
```
|
||||
|
||||
@ -203,4 +195,5 @@ Show Navigation Bar
|
||||
|
||||
MIT
|
||||
|
||||
|
||||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fthebylito%2Freact-native-navigation-bar-color?ref=badge_large)
|
||||
|
||||
@ -16,12 +16,12 @@ def DEFAULT_MIN_SDK_VERSION = 16
|
||||
def DEFAULT_TARGET_SDK_VERSION = 26
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.has('compileSdkVersion') ? rootProject.ext.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
|
||||
buildToolsVersion rootProject.ext.has('buildToolsVersion') ? rootProject.ext.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION
|
||||
compileSdkVersion rootProject.ext.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
|
||||
buildToolsVersion rootProject.ext.hasProperty('buildToolsVersion') ? rootProject.ext.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.has('minSdkVersion') ? rootProject.ext.minSdkVersion : DEFAULT_MIN_SDK_VERSION
|
||||
targetSdkVersion rootProject.ext.has('targetSdkVersion') ? rootProject.ext.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
|
||||
minSdkVersion rootProject.ext.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : DEFAULT_MIN_SDK_VERSION
|
||||
targetSdkVersion rootProject.ext.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
}
|
||||
@ -37,4 +37,4 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
api 'com.facebook.react:react-native:+'
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,34 +2,32 @@
|
||||
|
||||
package com.thebylito.navigationbarcolor;
|
||||
|
||||
|
||||
import android.animation.ArgbEvaluator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.TargetApi;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.app.Activity;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import androidx.annotation.UiThread;
|
||||
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.Promise;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.UiThreadUtil;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.facebook.react.uimanager.IllegalViewOperationException;
|
||||
|
||||
import static com.facebook.react.bridge.UiThreadUtil.runOnUiThread;
|
||||
|
||||
public class NavigationBarColorModule extends ReactContextBaseJavaModule {
|
||||
public static final String REACT_CLASS = "NavigationBarColor";
|
||||
private static final String ERROR_NO_ACTIVITY = "E_NO_ACTIVITY";
|
||||
private static final String ERROR_NO_ACTIVITY_MESSAGE = "Tried to change the navigation bar while not attached to an Activity";
|
||||
private static final String ERROR_API_LEVEL = "API_LEVEl";
|
||||
private static final String ERROR_API_LEVEL_MESSAGE = "Only Android Oreo and above is supported";
|
||||
private static ReactApplicationContext reactContext = null;
|
||||
private static final int UI_FLAG_HIDE_NAV_BAR = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
@ -47,11 +45,13 @@ public class NavigationBarColorModule extends ReactContextBaseJavaModule {
|
||||
if (activity != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
Window window = activity.getWindow();
|
||||
int flags = window.getDecorView().getSystemUiVisibility();
|
||||
|
||||
if (light) {
|
||||
flags |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
|
||||
} else {
|
||||
flags &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
|
||||
}
|
||||
|
||||
window.getDecorView().setSystemUiVisibility(flags);
|
||||
}
|
||||
}
|
||||
@ -76,67 +76,59 @@ public class NavigationBarColorModule extends ReactContextBaseJavaModule {
|
||||
|
||||
@ReactMethod
|
||||
public void changeNavigationBarColor(final String color, final Boolean light, final Boolean animated, final Promise promise) {
|
||||
final WritableMap map = Arguments.createMap();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (getCurrentActivity() != null) {
|
||||
try {
|
||||
final Window window = getCurrentActivity().getWindow();
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (color.equals("transparent") || color.equals("translucent")) {
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
|
||||
if (color.equals("transparent")) {
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
|
||||
} else {
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
|
||||
}
|
||||
setNavigationBarTheme(getCurrentActivity(), light);
|
||||
map.putBoolean("success", true);
|
||||
promise.resolve(map);
|
||||
return;
|
||||
try {
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (getCurrentActivity() != null) {
|
||||
final Window window = getCurrentActivity().getWindow();
|
||||
|
||||
if (!animated) {
|
||||
window.setNavigationBarColor(Color.parseColor(String.valueOf(color)));
|
||||
} else {
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
|
||||
}
|
||||
if (animated) {
|
||||
Integer colorFrom = window.getNavigationBarColor();
|
||||
Integer colorTo = Color.parseColor(String.valueOf(color));
|
||||
//window.setNavigationBarColor(colorTo);
|
||||
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
|
||||
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animator) {
|
||||
window.setNavigationBarColor((Integer) animator.getAnimatedValue());
|
||||
}
|
||||
});
|
||||
colorAnimation.start();
|
||||
} else {
|
||||
window.setNavigationBarColor(Color.parseColor(String.valueOf(color)));
|
||||
Integer colorFrom = window.getNavigationBarColor();
|
||||
Integer colorTo = Color.parseColor(String.valueOf(color));
|
||||
//window.setNavigationBarColor(colorTo);
|
||||
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
|
||||
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animator) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
window.setNavigationBarColor((Integer) animator.getAnimatedValue());
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
colorAnimation.start();
|
||||
}
|
||||
|
||||
setNavigationBarTheme(getCurrentActivity(), light);
|
||||
|
||||
WritableMap map = Arguments.createMap();
|
||||
map.putBoolean("success", true);
|
||||
promise.resolve(map);
|
||||
}
|
||||
});
|
||||
} catch (IllegalViewOperationException e) {
|
||||
map.putBoolean("success", false);
|
||||
promise.reject("error", e);
|
||||
|
||||
} else {
|
||||
promise.reject("NOT_SUPPORTED", new Throwable("Not Supported"));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
promise.reject(ERROR_NO_ACTIVITY, new Throwable(ERROR_NO_ACTIVITY_MESSAGE));
|
||||
|
||||
}
|
||||
} else {
|
||||
promise.reject(ERROR_API_LEVEL, new Throwable(ERROR_API_LEVEL_MESSAGE));
|
||||
} catch (IllegalViewOperationException e) {
|
||||
WritableMap map = Arguments.createMap();
|
||||
map.putBoolean("success", false);
|
||||
promise.reject("error", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void hideNavigationBar(Promise promise) {
|
||||
public void HideNavigationBar(Promise promise) {
|
||||
try {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
@ -155,14 +147,16 @@ public class NavigationBarColorModule extends ReactContextBaseJavaModule {
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void showNavigationBar(Promise promise) {
|
||||
public void ShowNavigationBar(Promise promise) {
|
||||
try {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (getCurrentActivity() != null) {
|
||||
View decorView = getCurrentActivity().getWindow().getDecorView();
|
||||
|
||||
int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
|
||||
|
||||
decorView.setSystemUiVisibility(uiOptions);
|
||||
}
|
||||
}
|
||||
|
||||
7
index.d.ts
vendored
7
index.d.ts
vendored
@ -1,8 +1,7 @@
|
||||
declare module "react-native-navigation-bar-color" {
|
||||
function changeNavigationBarColor(color: string, light: boolean, animated: boolean): void;
|
||||
function hideNavigationBar(): boolean;
|
||||
function showNavigationBar(): boolean;
|
||||
function HideNavigationBar(): boolean;
|
||||
function ShowNavigationBar(): boolean;
|
||||
|
||||
export default changeNavigationBarColor;
|
||||
export { hideNavigationBar, showNavigationBar };
|
||||
export { changeNavigationBarColor, HideNavigationBar, ShowNavigationBar };
|
||||
}
|
||||
|
||||
8
index.js
8
index.js
@ -1,8 +1,4 @@
|
||||
import {
|
||||
changeNavigationBarColor,
|
||||
hideNavigationBar,
|
||||
showNavigationBar,
|
||||
} from './src';
|
||||
import { changeNavigationBarColor, HideNavigationBar, ShowNavigationBar } from './src';
|
||||
|
||||
export default changeNavigationBarColor;
|
||||
export {hideNavigationBar, showNavigationBar};
|
||||
export { HideNavigationBar, ShowNavigationBar };
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-navigation-bar-color",
|
||||
"version": "2.0.1",
|
||||
"version": "1.0.0",
|
||||
"description": "React Native component to change bottom bar/navigation bar color on Android",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
|
||||
27
src/index.js
27
src/index.js
@ -1,30 +1,25 @@
|
||||
import {NativeModules, Platform} from 'react-native';
|
||||
import { NativeModules, Platform } from 'react-native';
|
||||
|
||||
const {NavigationBarColor} = NativeModules;
|
||||
const { NavigationBarColor } = NativeModules;
|
||||
|
||||
const changeNavigationBarColor = (
|
||||
color = String,
|
||||
light = false,
|
||||
animated = true,
|
||||
) => {
|
||||
if (Platform.OS === 'android') {
|
||||
const changeNavigationBarColor = (color = String, light = false, animated = true) => {
|
||||
if(Platform.OS === 'android') {
|
||||
const LightNav = light ? true : false;
|
||||
NavigationBarColor.changeNavigationBarColor(color, LightNav, animated);
|
||||
}
|
||||
};
|
||||
const hideNavigationBar = () => {
|
||||
if (Platform.OS === 'android') {
|
||||
return NavigationBarColor.hideNavigationBar();
|
||||
const HideNavigationBar = () => {
|
||||
if(Platform.OS === 'android') {
|
||||
return NavigationBarColor.HideNavigationBar();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
const showNavigationBar = () => {
|
||||
if (Platform.OS === 'android') {
|
||||
NavigationBarColor.showNavigationBar();
|
||||
const ShowNavigationBar = () => {
|
||||
if(Platform.OS === 'android') {
|
||||
NavigationBarColor.ShowNavigationBar();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export {changeNavigationBarColor, hideNavigationBar, showNavigationBar};
|
||||
export { changeNavigationBarColor, HideNavigationBar, ShowNavigationBar };
|
||||
|
||||
Loading…
Reference in New Issue
Block a user