npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

projectzerorn-native-router

v0.6.4

Published

Easy to use Navigator for your native app.

Downloads

7

Readme

GB Native Router

Awesome navigation for your React Native app.

NavBar Example

Install

Make sure that you are in your React Native project directory and run:

$ npm install projectzerorn-native-router --save

Usage

var Router = require('projectzerorn-native-router');

The basics:

// The initial page
var HelloPage = React.createClass({
  render: function() {
    return <Text>Hello world!</Text>;
  }
});

// Your route object should contain at least:
// - The name of the route (which will become the navigation bar title)
// - The component object for the page to render
var firstRoute = {
  name: 'Welcome!',
  component: HelloPage
};

// The Router wrapper
var MyApp = React.createClass({
  render() {
    return (
      <Router firstRoute={firstRoute} />
    )
  }
});

AppRegistry.registerComponent('routerTest', () => MyApp);

Boom. That's it.

From the "Hello world!"-page you can then navigate further to a new component by calling this.props.toRoute(). Let's build upon the HelloPage component in our first example:

var HelloPage = React.createClass({

  nextPage: function() {
    this.props.toRoute({
      name: "A new screen",
      component: HelloPage
    });
  },

  render: function() {
    return (
      <View>
        <TouchableHighlight onPress={this.nextPage} underlayColor="transparent">
          <Text>Next page please!</Text>
        </TouchableHighlight>
      </View>
    );
  }
});

Now, when you click on "Next page please!", it will go to the next page (which in this case is still HelloPage but with a new title). Keep in mind that this.props.toRoute() needs to be called from one of the top-level routes, therefore, if your link is deeply nested within multiple components, you need to make sure that the action "bubbles up" until it reaches the parent route, which in turn calls this.props.toRoute().

呼叫 this.props.toBack(),能夠回到上一頁。

Configurations

The <Router \> object used to initialize the navigation can take the following props:

  • firstRoute (required): A React class corresponding to the first page of your navigation
  • headerStyle: Apply a StyleSheet to the navigation bar. You'll probably want to change the backgroundColor for example.
  • titleStyle: Apply a StyleSheet to the navigation bar titles. Useful for changing the font or text color.
  • borderBottomWidth: Apply a bottom border to your navbar.
  • borderColor: Apply a border color to your bottom border.
  • backButtonComponent: By default, the navigation bar will display a simple "Back" text for the back button. To change this, you can specify your own backButton component (like in the Twitter app).
  • rightCorner: If you have the same occuring action buttons on the right side of your navigation bar (like the Twitter "Compose"-button), you can specify a component for that view.
  • customAction: A special callback prop for your action buttons (this can be handy for triggering a side menu for example). The action gets triggered from your custom leftCorner or rightCorner components by calling this.props.customAction("someActionName") from them. It is then picked up like this: <Router customAction={this.doSomething} />.
  • hideNavigationBar: Hide the navigation bar, always
  • noStatusBar: Hide status bar, always, iOS only
  • expensive: If all scenes is expensive, render placeholder to avoid stutter
  • renderPlaceholderView: Override default placeholder for loading expensive scene

The this.props.toRoute() callback prop takes one parameter (a JavaScript object) which can have the following keys:

  • name: The name of your route, which will be shown as the title of the navigation bar unless it is changed.
  • component (required): The React class corresponding to the view you want to render.
  • leftCorner: Specify a component to render on the left side of the navigation bar (like the "Add people"-button on the first page of the Twitter app)
  • rightCorner: Specify a component to render on the right side of the navigation bar
  • titleComponent: Specify a component to replace the title. This could for example be your logo (as in the first page of the Instagram app)
  • headerStyle: Change the style of your header for the new route. You could for example specify a new backgroundColor and the router will automatically make a nice transition from one color to the other!
  • passProps: Takes in an object. Passes each key: value pair to your component as a prop. i.e.
  • trans: If set to a truthy value it will make the navbar transparent and move your component content so that it sits behind the nav.
  • hideNavigationBar: If set to a truthy value will hide the navigationbar out of view, and move the component so that it is at the top of the screen.
  • noStatusBar: Hide status bar, iOS only
  • leftCornerProps: If you set a leftCorner component you can use this property to pass props to that component.
  • rightCornerProps: If you set a rightCorner component you can use this property to pass props to that component.
  • sceneConfig: Control the animation of the route being switched. Possible values are:
    • Navigator.SceneConfigs.FadeAndroid
    • Navigator.SceneConfigs.FloatFromBottom
    • Navigator.SceneConfigs.FloatFromBottomAndroid
    • Navigator.SceneConfigs.FloatFromLeft
    • Navigator.SceneConfigs.FloatFromRight
    • Navigator.SceneConfigs.HorizontalSwipeJump
    • Navigator.SceneConfigs.PushFromRight
    • Navigator.SceneConfigs.VerticalDownSwipeJump
    • Navigator.SceneConfigs.VerticalUpSwipeJump
  • expensive: If the scene is expensive, render placeholder to avoid stutter
  • renderPlaceholderView: Override default placeholder for loading expensive scene

The this.props.replaceRoute takes in an object that can contain the same keys as toRoute(). The difference is that instead of adding a route to your stack, it replaces the route that you're on with the new route that you pass it.

  • This is useful for login or signup screens. If you don't want your user to be able to navigate back to it, then use replaceRoute() rather than toRoute().

The this.props.resetToRoute takes in an object that can contain the same keys as toRoute(). The difference is that instead of adding a route to your stack, it replaces the route that you're on with the new route that you pass it, and empties the navigation stack as well.

  • This is useful for going to an application after a login or signup screens. If you don't want your user to be able to navigate back to it, then use resetToRoute() rather than replaceRoute().

The this.props.setRightProps and this.props.setLeftProps take in an object of props and sends that to your navbar's RightComponent and LeftComponent.

  • This allows you to talk directly to your navbar, because previously you could only talk to it when navigating forward or backward.

Events emitted by the router: didFocus, emits route name You can add a listener to a component as such:

  	this.props.routeEmitter.addListener('didFocus', (name) => {
			//Check if name is the current component, and if it is, act on this focus event.
		});

A more advanced example: Twitter app

To see more of the router in action, you can check out the Twitter example app that comes with the package. Just make sure that you first drag all the images from node_modules/react-native-router/twitter-example/images to your project's Images.xcassets

After that, don't forget to rebuild the app in XCode before you launch the simulator. Then test the app by requiring the TwitterApp component:

var TwitterApp = require('./node_modules/react-native-router/twitter-example');

var {
  AppRegistry
} = React;

AppRegistry.registerComponent('routerTest', () => TwitterApp);