[BREAKGLASS] React Native component to change bottom bar/navigation bar color on Android
Go to file
Welington da Silva Martins 8f83d5055f updated docs
2020-03-01 01:28:46 -03:00
.github/workflows Update npmpublish.yml 2019-10-15 11:42:25 -04:00
android Update NavigationBarColorModule.java 2019-10-15 10:43:36 -04:00
screenshots readme 2018-05-22 21:32:19 -04:00
src Update index.js 2019-10-15 10:45:39 -04:00
.gitignore Update README 2018-10-14 12:58:01 -04:00
index.d.ts Update index.d.ts 2019-10-15 10:41:45 -04:00
index.js hide and show Nav bar 2018-05-23 08:07:40 -04:00
LICENSE Initial commit 2018-05-22 20:47:02 -04:00
package.json Update package.json 2019-10-15 10:39:54 -04:00
README.md updated docs 2020-03-01 01:28:46 -03:00

React Native Navigation Bar Color Change

FOSSA Status

React Native Navigation Bar Color Change is a React Native library for change color of navigation/Bottom bar on Android.

Android Only

Table of Contents

Installation

react-native >= 0.60.0

1 - Install the package:

$ yarn add react-native-navigation-bar-color

or

$ npm install react-native-navigation-bar-color --save

That's is all!

react-native <= 0.59.0

1 - Install the package:

$ yarn add react-native-navigation-bar-color

or

$ npm install react-native-navigation-bar-color --save

2 - Configure package:

  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add import com.thebylito.navigationbarcolor.NavigationBarColorPackage; to the imports at the top of the file
  • Add new NavigationBarColorPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-navigation-bar-color'
    project(':react-native-navigation-bar-color').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation-bar-color/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
    implementation project(':react-native-navigation-bar-color')
    

Example

Android Implementation

import React, { Component } from 'react';
import { View, Text, Button } from 'react-native';
import changeNavigationBarColor, {
  HideNavigationBar,
  ShowNavigationBar,
} from 'react-native-navigation-bar-color';

export default class Mynewapp extends Component {
  setNavigationColor = (color) => {
    changeNavigationBarColor(color);
  };
  hideNavigation() {
    HideNavigationBar();
  };

  showNavigation() {
    ShowNavigationBar();
  };

  render() {
    return (
      <View
        style={{
          flex: 1,
          justifyContent: 'space-around',
          alignContent: 'center',
          alignItems: 'center',
          backgroundColor: 'white'
        }}
      >
        <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>
    );
  }
}

API

changeNavigationBarColor(color, Boolean(light icon color), Boolean(animated - default is true)): (Android)

Change color of Navigation/Bottom bar. color can be a HEX color, or name. ex: green, blue, #80b3ff, #ffffff....

Light is true? icons will be dark.

  • Returns a Promise
  example = async () => {
      try{
          const response = await changeNavigationBarColor('#80b3ff');
          console.log(response)// {success: true}
      }catch(e){
          console.log(e)// {success: false}
      }

  };

OR

  example = async () => {
      try{
          const response = await changeNavigationBarColor('#80b3ff', true);
          console.log(response)// {success: true}
      }catch(e){
          console.log(e)// {success: false}
      }
    
  };

HideNavigationBar(): (Android)

Hide Navigation Bar

  import { HideNavigationBar } from 'react-native-navigation-bar-color';
 ...
  hide = () => {
      HideNavigationBar();
  };

ShowNavigationBar(): (Android)

Show Navigation Bar

  import { ShowNavigationBar } from 'react-native-navigation-bar-color';
 ...
  show = () => {
      ShowNavigationBar();
  };

License

MIT

FOSSA Status