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

navigation

v6.2.0

Published

The data-first JavaScript router

Downloads

1,637

Readme

The Navigation router

Scene-Based Navigation for React and React Native

  • Scene-Based Navigation Native apps have always had scene-based navigation. The Navigation router is the first to bring it to the web. You give the Navigation router a list of your scenes. After you navigate to a scene, the Navigation router gets out of your way so you can build your UI however you want.
  • React and React Native You don't need a different routing library for React and React Native anymore. The Navigation router works on both. What's more, it doesn't compromise the UX. On React Native, the navigation is 100% native on Android and iOS. On React, you can have whatever URLs you want.

React

Define Your States

import { StateNavigator } from 'navigation';

const stateNavigator = new StateNavigator([
  { key: 'hello', route: '' },
  { key: 'world' }
]);

You create one State for each scene (page) in your app. You don't need to define your routes yet. The Navigation router generates interim routes. You can define your real routes at any time without changing any code. With scene-based navigation, there aren't any hard-coded Urls for you to update.

Create Your Scenes

<NavigationHandler stateNavigator={stateNavigator}>
  <SceneView active="hello"><Hello /></SceneView>
  <SceneView active="world"><World /></SceneView>
</NavigationHandler>  

For each State, you create a SceneView component that renders the UI. All the other routers for React force you to think in terms of routes. But this is hard becasue routes can be nested, for example, a master/details page. Scenes, on the other hand, are always flat. The Navigation router still supports nested routes because a Scene can have more than one route.

Navigate to a Scene

import { NavigationLink } from 'navigation-react';

const Hello = () => (
  <NavigationLink
    stateKey="world"
    navigationData={{ size: 20 }}>
    Hello
  </NavigationLink>
);

The NavigationLink component changes scene. You pass the name of the scene and the data. The Navigation router builds the Url. If you've configured more than one route it uses the best match.

Use the Data

import { NavigationContext } from 'navigation-react';

const World = () => {
  const { data } = useContext(NavigationContext);
  return (
    <div style={{ fontSize: data.size }}>
      World
    </div>
  );
};

In the next scene, you access the data from the NavigationContext. The Navigation router passes strongly-typed data. Here, the size is a number.

React Native

Define Your States

import { StateNavigator } from 'navigation';

const stateNavigator = new StateNavigator([
  { key: 'hello' },
  { key: 'world', trackCrumbTrail: true }
]);

You create one State for each scene (screen) in your app. You can think of the stack of scenes as a trail of breadcrumbs. Each scene is one crumb. Like Hansel and Gretel in the fairy story, the Navigation router drops a crumb every time it visits a scene (if you set 'trackCrumbTrail' to true).

Create Your Scenes

<NavigationHandler stateNavigator={stateNavigator}>
  <NavigationStack>
    <Scene stateKey="hello"><Hello /></Scene>
    <Scene stateKey="world"><World /></Scene>
  </NavigationStack>
</NavigationHandler>

For each State, you create a Scene component that renders the UI. The Navigation router provides React components to help you build your scenes. All of these components render to the same native primitives as other native apps. For example, the TabBar component renders to a BottomNavigationView on Android and a UITabBarController on iOS.

Navigate to a Scene

import { NavigationContext } from 'navigation-react';

const Hello = () => {
  const { stateNavigator } = useContext(NavigationContext);
  return (
    <Button title="Hello"
      onPress={() => {
        stateNavigator.navigate('world', { size: 20 });
      }} />
  );
};

You use the stateNavigator from the NavigationContext to change scenes. You pass the name of the scene and the data. The navigation is 100% native on Android and iOS.

Use the Data

import { NavigationContext } from 'navigation-react';

const World = () => {
  const { data } = useContext(NavigationContext);
  return (
    <Text style={{ fontSize: data.size }}>
      World
    </Text>
  );
};

In the next scene, you access the data from the NavigationContext. You can return to the 'hello' scene via the Android back button or swiping/pressing back on iOS.