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

react-simple-navigation

v0.2.2

Published

A simple navigation router for React-Native

Downloads

5

Readme

React Simple Navigation

React Simple Navigation provides an easy to get started solution to navigation in react and react-native.

Version: 0.2.1 This is project is a work in progress and contributions/pull requests are welcome.


Getting Started

To get started run npm i react-simple-navigation.

Navigation

Navigation runs from a Component called a Connected Router Component.

// Create a component called AppContainer.js

import { createConnectedRouterContainer } from '../../SimpleRouter';

const Routes = {
	RouteOne: RouteOneComponent,
	RouteTwo: RouteTwoComponent
};

const Options = {
	initialRoute: 'RouteOne'
}

const AppContainer = createConnectedRouterContainer(Routes, Options);

export default AppContainer;

The Connected Router Component takes to arguments. The first is Routes, a list of components we use to form the navigator. The Key is the Route name and the Value is the relevant Component such as { RouteName: RouteComponent }. The second is Options where we pass the initial route that we like to render.

In our App.js file add:

import React, { Component } from 'react';
import AppContainer from './src/Navigators/AppContainer';

export default class App extends Component {
	render() {
		return <AppContainer />;
	}
}

That's it. Starting adding Route Names and Components to our Routes object and we've built our navigator.

Controlling the navigator

But wait, how do we use the Connected Router Component to navigate through our apps?

Well, Connected Router Component passes navigation functions and parameters to props to the components directly underneath them.

this.props.navigation handles all navigation, including mix-ins.

pushRoute adds a route to the history array.

switchRoute starts a clean array with the route.

state.history shows the history array.

state.route shows the current route.

goBack returns to the previous route in the history array by removing the current route.

A second parameter is available to pass parameters to the next route on the navigation props object.


Mix-ins

What is a mix-in?

A mix-in is simply a plugin to add different types of navigation controllers. They are called mix-ins as they are designed to be passed to Components before being added to the Routes object of createConnectedRouterContainer. This allows simplicity across the app but also the most customisabilty for everyone.

Available Mix-ins

Version 0.2.0

TabNavigator:

The Tab Navigator mix-in is used in react-native to add a Tab Bar at the bottom of the view.

import { createTabNavigator } from 'react-simple-navigation';
import MainMenuComponent from './MainMenuComponent'
import MainMenuComponent2 from './MainMenuComponent2'

const TabBarNavigator = createTabNavigator({
	MainMenu: MainMenuComponent,
	MainMenu2: MainMenuComponent2
});

export default TabBarNavigator;

Here we create routes in a similar style to how we create a routes object using the Connected Router Container. This time however we use the createTabNavigator to produce a TabBarNavigator component.

To use this navigator in our app we must "mix-in" the component to our Connected Router Container. In the AppContainer.js file we modify the Routes object to look like this:


// Create a component called AppContainer.js

import { createConnectedRouterContainer } from '../../SimpleRouter';
import TabBarNavigator from './TabBarNavigator';

const Routes = {
...TabBarNavigator,
RouteOne: RouteOneComponent,
RouteTwo: RouteTwoComponent
};

const Options = {
initialRoute: 'MainMenu'
}

const AppContainer = createConnectedRouterContainer(Routes, Options);

export default AppContainer;

Here we have successfully mixed in our TabBarNavigator to our Connected Router Container and assigned the initialRoute in Options to a Component from the TabBarNavigator.


In-development

There are a number of plans for the package in the future:

  • Better error handling
  • Additional Mix-ins
  • Community Mix-ins
  • Example Application