1.0.3 • Published 6 years ago

react-native-navigationbar-obsever v1.0.3

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

React Native navigationbar

Listen to device navigationbar changes in React Native applications on a per screen basis. Works on Android only.

Installing

npm install react-native-navigationbar-obsever --save

Linking Native Dependencies

Automatic Linking

react-native link react-native-navigationbar-obsever

Android

  1. In android/setting.gradle

    ...
    include ':react-native-navigationbar-obsever', ':app'
    project(':react-native-navigationbar-obsever').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigationbar-obsever/android')
  2. In android/app/build.gradle

    ...
    dependencies {
        ...
        compile project(':react-native-navigationbar-obsever')
    }

Usage

import NavigationbarObsever from 'react-native-navigationbar-obsever';
export default class AppScreen extends Component {
  // ...

    componentDidMount() {
      if (Platform.OS === 'android') {
        NavigationbarObsever.isNavigationbarShow((err, isShow) => {
          console.log(err, isShow, 'isShow');
        });
        //if you want to listener,you should bind first.
        NavigationbarObsever.bindListener((err,isOK) => {
          console.log(err, isOK, 'isOK');
        });
        //if you want to listener,you should addListener at second.
        DeviceEventEmitter.addListener('navigationbarDidShowChange', this._navigationDidShowChange);
      }
    }
  
    _navigationDidShowChange = (show) => {
      console.log(show.navigationbarSize, 'navigationbarSize',show.navigationbarShow, 'navigationbarShow');
    }
  
    componentWillUnmount() {
      if (Platform.OS === 'android') {
          //don't forget unbind and remove
        NavigationbarObsever.unbindListener();
        DeviceEventEmitter.removeListener(this._navigationDidShowChange);
        }
    }

  render() {
    // ...

    return (
      // ...
    )
  }
}