1.0.1 • Published 6 years ago

react-native-fancy-navigation-bar v1.0.1

Weekly downloads
3
License
GPL-3.0
Repository
github
Last release
6 years ago

react-native-fancy-navigation-bar

Here is a fully customizable navigation bar in React-Native. You can set the global unified style of navigation bar and add it as a react component in each page.

Install

Install by Yarn:

yarn add react-native-fancy-navigation-bar

Install by NPM:

npm install --save react-native-fancy-navigation-bar

Usage

First import in the file:

import NaviBar from 'react-native-fancy-navigation-bar';

Then add component in render() function:

render() {
  return (
    <View style={{flex: 1}}>
      <NaviBar
        title='CustomTitle'
        {/* other properties if you want to specify it */}
      />
      {/* other components */}
    </View>
  );
}

If you want to hide or show navigation bar dynamiclly, you can write these code:

render() {
  return (
    <View style={{flex: 1}}>
      {this.state.showNaviBar && (
        <NaviBar
          title='CustomTitle'
          {/* other properties if you want to specify it */}
        />
      )}
      {/* other components */}
    </View>
  );
}

This navigation bar is only a component with 'relative' position, not 'absolute' position. If you want to use absolute position, please use the 'style' property in following section.

Constant

You can import navigation bar height constant like this:

import {STATUSBAR_HEIGHT} from 'react-native-fancy-navigation-bar';

All constant about navigation bar height list below:

NameiOS (X)iOS (not X)AndroidDescription
STATUSBAR_HEIGHT44200Only status bar height
NAVBAR_HEIGHT444444Only navigation bar height
TOTALBAR_HEIGHT886444Total height of status bar and navigation bar

Other constant:

NameDescription
GOBACK_BUTTONAn identifier when you set 'leftElement' or 'rightElement' to identify the button as GoBack button

Global Settings

You can change the navigation bar settings at the startup, include navigation bar style, GoBack button image and function.

First, you should import methed from library:

import {setCustomStyle} from 'react-native-fancy-navigation-bar';

All the method list below (no return value):

NameDescriptionParam Format
setCustomStyleSet all the style include bar or button or title(key, style):key: A style key which you can see the following 'Style' sectionstyle: A style object created by StyleSheet or only an javascript object
setGlobalGobackFuncSet GoBack button function(func):func: A function with no param and no return value
setGlobalGobackImageSet GoBack button image(image):image: A number which means a local image or a string which is a remote image url

Custom Setting

You can control the action or style of navigation bar by passing 'props'.

PropNameTypeDefaultValueDescription
titlestring or element''Title view of text style or user custom view
titleCenterbooltrueTitle is must at center or not
hasSeperatorLinebooltrueBottom of navigation bar has a seperator line or not
leftElementstring or element or arrayGOBACK_BUTTONLeft buttons, a string means a button of text style, an element means a button view, an array of string means an array of button which maybe text or custom view
rightElementstring or string array or elementnullRight buttons, same format as 'leftElement'
onLeftfunctionundefinedLeft button click function, param is button index in 'leftElement', from 0 on. If return is false and button is goback button, then do not call the default goback action
onRightfunctionundefinedRight button click function, same format as 'onLeft'
autoCloseKeyboardbooltrueAuto dismiss keyboard when click button or not
navigationnavigation objectnullA stack navigation object used for goback action
stylestyle object{}A custom style which has highest priority, object's key is in following 'Style' section

Style

The component style is consist of three part:

  • User custom style, passed by component props, is highest level.
  • Global setting style, set by method in 'Global Settings' sections, is medium level, can be override by User custom style.
  • Inner style, written in library code, is lowest level, can be override by the two styles above.

All the key you can customize in Global or Custom settings list below:

KeyDescriptionDefaultValue
containerThe whole navigation barjustifyContent: 'space-between'flexDirection: 'row'alignItems: 'center'paddingTop: STATUSBAR_HEIGHTheight: TOTALBAR_HEIGHTbackgroundColor: 'white'
seperatorSeperator line at the bottomborderBottomWidth: StyleSheet.hairlineWidthborderBottomColor: '#e6e6ea'
titleInner title textfontSize: 18color: '#394352'textAlign: 'center'overflow: 'hidden'
titleContainerTitle container off centerflex: 1justifyContent: 'center'alignItems: 'center'
titleCenterContainerTitle container at centerposition: 'absolute'left: 0right: 0top: STATUSBAR_HEIGHTbottom: 0justifyContent: 'center'alignItems: 'center'
buttonViewText-type button touchable viewjustifyContent: 'center'alignItems: 'center'minWidth: minWidthheight: NAVBAR_HEIGHTpaddingHorizontal: 8
buttonTextText-type button textcolor: '#394352'fontSize: 17
leftViewLeft view contains all left buttonsflexDirection: 'row'justifyContent: 'center'alignItems: 'flex-start'
rightViewRight view contains all right buttonsflexDirection: 'row'justifyContent: 'center'alignItems: 'flex-end'
gobackViewGoback button touchable viewminWidth: minWidthheight: NAVBAR_HEIGHTjustifyContent: 'center'paddingHorizontal: 16
gobackImageGoback button imagewidth: 18height: 16

Credits

This Is A Slightly Modified Version React Native fancy Navigation Bar, All Credits To Gaoxiaosong