Giter VIP home page Giter VIP logo

react-native-navbar's Introduction

Customizable navbar for react-native

react-native-side-menu demo

Content

Examples

Getting started

  • Install react-native-navbar:

    • By using yarn:
      $ yarn add react-native-navbar
      
    • By using npm:
      $ npm install react-native-navbar --save
      
  • Import it in the file where you want to use it:

    import NavigationBar from 'react-native-navbar';
  • Add it to your React element tree:

const styles = {
  container: {
    flex: 1,
  },
};

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

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

function ComponentWithNavigationBar() {
  return (
    <View style={styles.container}>
      <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
  • containerStyle - (Object) - Style object for styling navbar container
  • tintColor - (String) - NavigationBar's 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's title
    • tintColor - (String) - Button's text color
    • style - (Object, Array) - Style object or array of style objects
    • handler - (Function) - onPress function handler
    • disabled - (Boolean) - If true, disable interactions for this button.
    • accessible - (Boolean) - Indicates that the view is an accessibility element
    • accessibilityLabel - (String, React Element) - Overrides the text that's read by the screen reader for the button.
  • 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's title
    • style - (Object, Array, Number) - Style object or array of style objects
    • tintColor - (String) - Title's text color
    • ellipsizeMode - ('head', 'middle', 'tail', 'clip') - How to display the text
    • numberOfLines - (Number) - How to truncate the text

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 ping me on twitter If you want to report a bug, please submit an issue!

react-native-navbar's People

Contributors

alinz avatar bilalbudhani avatar chenxsan avatar chirag04 avatar doxiaodong avatar grabbou avatar iroachie avatar jamesnocentini avatar jeremybarbet avatar jonasjonny avatar jonathanwi avatar kh0r avatar kujohn avatar kureev avatar leemarreros avatar lucianomlima avatar markdowney avatar michbil avatar mirza-s avatar mokto avatar morenoh149 avatar mwilc0x avatar naturalclar avatar nhducit avatar robrichard avatar skevy avatar taf2 avatar vincent178 avatar voronianski avatar xing-zheng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-navbar's Issues

nextTitle doen't work

Hi,

I'm using the following code

navigationBar:<NavigationBar title={app.name} prevTitle="asdasd" nextTitle="asdasd"/>,

The prevTitle take effect as shown 'asdasd', however the next title doesn't appear on the bar.
Is there anything wrong with my usage? Thanks a lot in advance.

Back Button on Initial Route

there is a back button on initial route even if i send null to the customPrev. it's null on the chrome debugger on too but's there is a "back button".

screen shot 2015-04-06 at 01 34 58

Call toggle from parent navigator

Hi

First of all thank you for creating this plugin.

One question, is there a way to call this.props.menuActions from parent component? I want to add an icon on top bar (right side) to open/close side menu.

Would you please help?

Thanks

Austin

How do you set custom actions for buttons on the initial route?

Since i am setting my initial route in index.ios.js i dont want to have any business logic in that file, I want all of the logic in the component that is being rendered in that initial route. I cannot see and example where the button actions are set after the initial route is rendered.

Maybe I am not understanding the proper patterns for using this component, any help would be appreciated.

render() {
    return (
        <Navigator
            ref="nav"
            style={styles.container}
            renderScene={this.renderScene}
            configureScene={(route) => {
                if (route.sceneConfig) {
                    return route.sceneConfig;
                }
                return Navigator.SceneConfigs.FloatFromRight;
            }}
            initialRoute={{
                component: SessionList,
                rightButtonTitle: 'New Session',
                navigationBar: <NavigationBar
                    onNext = {() => this.addNewSession()} //<== I want to do this in the SessionList component
                    nextTitle = "Create Session"
                    title ='Tutor Manager' />
            }} />
    );
}

Can't build the examples

When I try to build the basic example I get this:

screen shot 2015-08-25 at 09 02 02

And when I try to build the custom elements I get this:

screen shot 2015-08-25 at 09 02 21

borderBottom prop

Would it be possible to provide a property to allow styling of the bottom border of the navbar?

In my case, I would like to "hide" the navbar from a particular view, while still leaving the customPrev button visible.

CustomPrevButton - Image with Text

it seems like right now, using , one can only have a single element as the custom back btn ('Back', or a single image)

I would like to have a back arrow image with the text 'Back' next to it, and would prefer not to use an image containing the text. is it possible for this to be accomplished?

Errors with 0.7.1 release.

Unable to resolve module NavigatorNavigationBarStyles from /Users/kartikeychauhan/Documents/testcodes/react-native-test/HelloTest/node_modules/react-native-navbar/index.js
Unable to resolve module StaticContainer.react from /Users/kartikeychauhan/Documents/testcodes/react-native-test/HelloTest/node_modules/react-native-navbar/index.js
Unable to resolve module NavigatorNavigationBarStyles from /Users/kartikeychauhan/Documents/testcodes/react-native-test/HelloTest/node_modules/react-native-navbar/index.js
Unable to resolve module StaticContainer.react from /Users/kartikeychauhan/Documents/testcodes/react-native-test/HelloTest/node_modules/react-native-navbar/index.js

Did a fresh new project with react-native-cli and tried integrating the react-native-navbar. It gives me above error.

AND

screen shot 2015-07-16 at 5 33 25 pm

Having issues with accessing navigator object

In this code, this.props.navigator.pop() is undefined. Same with this.refs.nav.navigator.pop(). How do I access navigator object? Thanks for your time. Jeff

 <Navigator
    ref="nav"
    style={styles.navigator}
    renderScene={this.renderScene}
    initialRoute={{
      component: Search,
       navigationBar: <NavigationBar 
        titleColor="#ffffff"
        title="Global Search"
        backgroundStyle={{backgroundColor:'#424242'}}
        onPrev={() => this.props.navigator.pop()}
        prevTitle="Back"
        />
    }}
  />

Doesnt work with ListView

Trying to modify the basic example to use the 'AwesomeProject' component from the react native tutorial. Im mainly trying to see how the navbar works with a listview.

    <Navigator
        style={styles.navigator}
        renderScene={this.renderScene}
        initialRoute={{
          component: AwesomeProject,
          navigationBar: <NavigationBar
            title="Initial View"
            onNext={this.handleNext}
          />
        }}
      />

However, when I scroll down it seems that the ListView gets 'stuck' and wont let me scroll down.

navbar_listview

Maybe it will be helpful to include an example with a ListView?

Thanks.

How do I create a normal push animation where the nav bar does not move?

Here's a video with how my code runs right now. The first 14 seconds are without passing a navigation bar to the new route. The second half is with a new nav bar.
screen_recording_-_youtube

Code for reference:

class PeopleTab extends Component {
render () {
    return (
        <Navigator
            ref='navigator'
            style={styles.container}
            initialRoute={{
                name: "people",
                component: PeopleList,
                navigationBar: (<NavigationBar hidePrev={true} title="home" shouldUpdate={false} />),
            }}
            renderScene={this.renderScene.bind(this)}
            />
    );
}

renderScene(route, nav) {

    var Component = route.component;
    var navBar = route.navigationBar;

    if (navBar) {
        navBar = React.addons.cloneWithProps(navBar, {
            navigator: navigator,
            route: route
        });

    }
    console.log(route);

    switch (route.name) {
        case 'people':
            return (
                <View style={{ flex: 1, }}>
                    {navBar}
                    <Component navigator={nav} route={route} onNext={this.onNext.bind(this)} />
                </View>
            );
        case 'person':
            return (
                <View style={{ flex: 1, }}>
                    {navBar}
                    <Component navigator={nav} route={route} person={route.person} />
                </View>
            );
        default:
            return (<View/>);
    }
}

onNext(person) {
    this.refs.navigator.push({
        name: "person",
        component: PersonDetail,
        person: person,
        navigationBar: (<NavigationBar title="People" />), // Only in 2nd half of video
    });
}

}

How can I get the navigator with your nav bar to do a push with the nav bar not moving?

CustomPrevButton - Image with Text

it seems like right now, using , one can only have a single element as the custom back btn ('Back', or a single image)

I would like to have a back arrow image with the text 'Back' next to it, and would prefer not to use an image containing the text. is it possible for this to be accomplished?

NavigationBar has 2 required props, WHY?

Thanks for this extension.
Why did you make navigator and route props required? How would you set these arguments? None of the examples are setting these values. :(

Both Side Menu

I want create left and right menu. please teach me how to do?

Hide navigation bar on scroll down

Hi @Kureev is there currently any way to hide the navigation bar when the user begins scrolling down the page then show it again based either on a timer or when the user starts scrolling back up?

Doesn't work with React-native 0.4

Hello and thanks for the great component.

I've tried your component and it doesn't seem to work with new version. It does compile but I got blank screen.

Any help would be appreciated.

Warnings in console log for required properties?

Warning: Failed propType: Required prop `navbar` was not specified in `NavigationBar`. Check the render method of `ReactParseExample`.
Warning: Failed propType: Required prop `route` was not specified in `NavigationBar`. Check the render method of `ReactParseExample`.

Don't see how they make sense for the initial route based on the information provided in the documentation

Aboute Animation

When I was through the Navigator push a New View, animations and native IOS not the same

Errors when requiring react-native-navbar on 0.4.2

Not sure if this is user error or library error, so documenting/querying this here in case it's a library issue:

When running the packager through webpack, I'm getting the following errors:

ERROR in ./~/react-native-navbar/index.js
Module not found: Error: Cannot resolve module 'NavigatorNavigationBarStyles' in ~/HOME/dev/mobileios/node_modules/react-native-navbar
 @ ./~/react-native-navbar/index.js 11:35-74

ERROR in ./~/react-native-navbar/index.js
Module not found: Error: Cannot resolve module 'StaticContainer.react' in ~/HOME/dev/mobileios/node_modules/react-native-navbar
 @ ./~/react-native-navbar/index.js 12:22-54

Any ideas?

On new route push the animation is slow when having a MapView

Hi there,
Probably not strictly related to this, but I am pushing a new Screen with two MapViews, and the transition to that screen is not smooth at all, I am not sure in which other cases this may happen, anyone has faced the same issue?

Regards

Default Prev ("Back") and Next don't appear after update

After updating from version 0.7.3 to 0.8.2 I can no longer see the "Back".

When I switch back to 0.7.3 the "Back" appears again like it should. What went wrong?

P.s. The customBack on the other hand shows up when I try to use that, but I'd prefer just using the default functionality for now.

componentWillUnmount and componentDidUnmount not working for renderScene components

Hi Kureev, I have a component for the renderScene called Settings

this.props.navigate({
            component: Settings,
            navigationBar: <NavigationBar
                title="Settings"
                customPrev={<MenuIcon/>}
                customNext={<ProfileIcon/>}
                />  
});

Every time I try to use the componentDidMount and componentWillUnmount functions for the Settings component itself it doesn't work.

var Settings = React.createClass({
   getInitialState() {
        return {
            phrase: "Hello"
        };
   },
    [...]
  componentDidMount() {
     console.log('Did Mount');
   },
  componentWillUnmount() {
     console.log('Will Unmount');
   },
  componentDidUnmount() {
    console.log('Did Unmount');
   },
    render() {
        return (
          <View style={styles.container}>
            <View style={styles.section}>
                <Text>{this.state.phrase}</Text>
            </View>
          </View>
        );
    }
});

as you can imagine, the componentDidUnmount and componentDidUnmount functions don't work for settings or any of the other components rendered with renderScene.
Any insights?

I am using react-native v0.7.1 and react-native-navbar v0.6.0. Thanks

onNext to another component

Hi,

I want to handleNext to push to another component like this

var JobScreen = React.createClass({
    renderScene: function(route, navigator) {
        var Component = route.component;
        var navBar = route.navigationBar;

        if (navBar) {
            navBar = React.addons.cloneWithProps(navBar, {navigator, route});
        }
        return (
            <View style={styles.view}>
                {navBar}
                <Component navigator={navigator} route={route} />
            </View>
        );
   },

   handleNext: function() {
        this.props.navigator.push({
            component: PostJobScreen,
            navigationBar: <NavigationBar title="Post a Job"/>
        });
   },


    render: function() {
        return(
        <Navigator
                ref="nav"
                style={styles.navigator}
                renderScene={this.renderScene}
                configureScene={(route) => {
                    if (route.sceneConfig) {
                        return route.sceneConfig;
                    }
                    return Navigator.SceneConfigs.FloatFromBottom;
                }}
                initialRoute={{
                  component: JobList,
                  navigationBar: <NavigationBar
                    title="Jobs"
                    nextTitle="Post Job"
                    hidePrev='true'
                    onNext={this.handleNext}/>
                }}/>
        );
    }
});

I kept getting

 undefined is not an object (evaluating 'this.props.navigator.push')"

customTitle doesn't show

I'm using react-native-navbar to load an app logo to the navbar.
The customTitle attribute doesn't work either to show an <View /> component on the navbar.

Using this demo:

/* index.ios.js */
...

<Navigator
    renderScene={this._renderScene}
    initialRoute={{
        component: FacebookConnectPage,
        navigationBar:
            <NavigationBar
                customTitle={LogoNavTitle}
                backgroundColor="#00605e"
            />
    }}
/>
/* LogoNavTitle.js */
...

<View style={{ flexDirection: 'row', height: 60, backgroundColor: '#fff' }}>
</View>

I'm trying to just show an view with white background to check if it works and that don't render either.

Disable multi-touch?

I'd like to disable multi-touch, particularly to avoid corrupting my navigation when the user accidentally double taps and the same view gets pushed twice. Is this possible?

NavBarHidden is work ?

The NavBar can set hidden ?? i can not work for me .. BTW where can you find this document?

passProps seem doesn't work

I call this.props.navigator.push to the next scene, and pass some props to the next scene, and caught an error, the passed prop is undefined in the next view,it seems passProps doesn't work,and code is below:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'use strict';

var React = require('react-native');
var Product = require('./product');
var Adapt = require('./adapt');

var mdskip = require('./data/mock-mdskip');
var context = require('./data/mock-context');
var NavigationBar = require('react-native-navbar');

var Detail = require("./ui/detail");
var styles = require("./ui/style");
var {
  Navigator,
  NavigatorIOS,
  AppRegistry,
  View,
  Text,
  StyleSheet,
  TouchableHighlight,
  ScrollView
} = React;

var product = new Product();
product.set("context", context.ModuleDatas);
product.set("config", context.TDetail);
product.set("mdskip", Adapt.transform(mdskip));
product.set("deviceType", "phone");

var RootComponent = React.createClass({
  getInitialState: function(){
    return {};
  },
  componentDidMount: function() {
    var self = this;
  },
  renderScene: function(route, navigator) {
    var product = this.state.product;

    var Component = route.component;
    var navBar = route.navigationBar;

    if (navBar) {
      navBar = React.addons.cloneWithProps(navBar, {
        navigator: navigator,
        route: route
      });
    }

    return (
      <View style={styles.navigator}>
        {navBar}
        <Component navigator={navigator} route={route} product={product} />
      </View>
    );
  },
  render: function() {

    if(context){
      return (
        <Navigator
        style={styles.navigator}
        renderScene={this.renderScene}
        initialRoute={{
          component: Entrance,
          navigationBar: <NavigationBar
            title="Initial View"
            onNext={this.handleNext}
          />
        }}
      />
      );
    }else{
      return (
        <View></View>
      )
    }
  }
});

var Entrance = React.createClass({
  render: function(){
    return (
      <View style={styles.clickMe}>
        <TouchableHighlight onPress={this.onPress} underlayColor="#B5B5B5">
          <Text style={styles.clickMeText}>็‚นๆˆ‘็œ‹่ฏฆๆƒ…</Text>
        </TouchableHighlight>
      </View>
    );
  },
  componentDidMount(){
    var self = this;
    product.onLoad(["context", "config", "mdskip"], function(context, config, mdskip){
      self.setState({
        "context": context,
        "config": config,
        "mdskip": mdskip
      });
    })
  },
  onPress: function(){
    var context = this.state.context;
    var config = this.state.config;
    var mdskip = this.state.mdskip;
    var product = this.props.product;

    this.props.navigator.push({
      title: context.title.itemTitle,
      component: DetailMain,
      backButtonTitle: 'Back',
      passProps: { config: config, mdskip: mdskip, product: product, context: context}
    });
  }
});

var DetailMain = React.createClass({
  getInitialState: function(){
    return {
      loading: false
    };
  },
  render: function(){
    return (
      <Detail config={this.props.config} mdskip={this.props.mdskip} product={this.props.product} context={this.props.context} navigator={this.props.navigator}/>
    )
  }
})

AppRegistry.registerComponent('DetailNative', () => RootComponent);

Translucent Property.

I want to make the navigation bar translucent. What do you recommend should be the best way to make the bar translucent. I know <NavigatorIOS /> have a property of translucent which one can use but we have <Navigator /> and I don't know about translucent property, seems like it doesn't have that property.

screen shot 2015-07-23 at 2 45 29 pm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.