/react-native-navbar

Navbar component for React Native

Primary LanguageJavaScriptMIT LicenseMIT

Customizable navbar for react-native [iOS only]

react-native-side-menu demo

Content

Installation

npm i react-native-navbar --save

Examples

Getting started

First of all, I assume you've already made a react-native project by running react-native init project-name and installed react-native-navbar component by npm.

In your index.ios.js file require react-native-navbar component:

var NavigationBar = require('react-native-navbar');

or, if you use ES2015 syntax:

import NavigationBar from 'react-native-navbar';

Inside your component's render method, use NavigationBar:

render: function() {
  var rightButtonConfig = {
    title: 'Next',
    handler: function onNext() {
      alert('hello!');
    }
  };

  var titleConfig = {
    title: 'Hello, world',
  };

  return (
    <View style={{ flex: 1, }}>
      <NavigationBar
        title={titleConfig}
        rightButton={rightButtonConfig} />
    </View>
  );
}

or, if you use ES2015:

render() {
  const rightButtonConfig = {
    title: 'Next',
    handler: () => alert('hello!'),
  };

  const titleConfig = {
    title: 'Hello, world',
  };

  return (
    <View style={{ flex: 1, }}>
      <NavigationBar
        title={titleConfig}
        rightButton={rightButtonConfig} />
    </View>
  );
}

That's it, you're ready to go!

API

  • style - (Object, Array) - Style object or array of style objects
  • tintColor - (String) - Navigation bar tint color
  • statusBar - (Object):
    • style - ('light-content' or 'default') - Style of statusBar
    • hidden - (Boolean)
    • tintColor - (String) - Status bar tint color
    • hideAnimation - ('fade', 'slide', 'none') - Type of statusBar hide animation
    • showAnimation - ('fade', 'slide', 'none') - Type of statusBar show animation
  • leftButton / rightButton - (Object, React Element) - Either plain object with configuration, or React Element which will be used as a custom left/right button element. Configuration object has following keys:
    • title - (String) - Button title
    • style - (Object, Array) - Style object or array of style objects
    • handler - (Function) - onPress function handler
  • title - (Object, React Element) - Either plain object with configuration, or React Element which will be used as a custom title element. Configuration object has following keys:
    • title - (String) - Button title
    • tintColor - (String) - Title tint color

Usage with Webpack

This module uses JSX syntax and requires a compiler such as babel. React Native's packager runs this automatically but if you use Webpack be sure to compile this module from your dependencies

loaders: [{
  test: /\.js$/,
   include: [
     path.resolve(__dirname, "src"),
     path.resolve(__dirname, "node_modules/react-native-navbar")
   ],
  loader: 'babel',
  query: { stage: 0, plugins: [] }
}]

Questions?

Feel free to contact me via

  • Twitter
  • Slack (@kureev on #reactiflux channel)

If you want to report a bug, please submit an issue!