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

reactigation

v6.1.2

Published

React-only Navigation for React Native.

Downloads

29

Readme

Reactigation

npm codesandbox

Navigation for React Native using only JavaScript.

Installation

npm i reactigation

Usage

A minimal setup with two screens looks like this.

import React from 'react'
import { AppRegistry, Text, Button } from 'react-native'
import Reactigation, { register, go, back } from 'reactigation'

const FirstScreen = (props) => (
  <>
    <Text>{props.title} Screen</Text>
    <Button title="go to Second Screen" onPress={() => go('Second')} />
  </>
)

const SecondScreen = (props) => (
  <>
    <Text>{props.title} Screen</Text>
    <Button title="go back" onPress={() => back()} />
  </>
)

register(<FirstScreen />, 'First')
register(<SecondScreen />, 'Second')

AppRegistry.registerComponent('NavigationApp', () => Reactigation)

Navigating to a Screen

At runtime it's possible to navigate to any of the registered screens. A transition is how the switch between two screens looks like. For each navigation the transition can be configured.

go(screen: string, transition?: Transition, props?: object)

import { go, Transition } from 'reactigation'

go('HelloWorld', 'modal')
go('AboutScreen', Transition.fast)
// Pass props to screen and use default screen transition.
go('DetailPage', null, { id: 5 })

Available transitions: regular, slow, fast, none, opacity, modal & peek can all be imported as Transition.

Going Back

Returning to the previous screen is simple. Unless defined otherwise the animation defined by go will be applied in reverse. On Android when the user clicks the system back button this function is also called.

back(transition?: Transition)

import { back, Transition } from 'reactigation'

back()
back('fast')
back(Transition.slow)

Registering Screens

At least one screen needs to be registered before Reactigation is initialized. The register function takes any React Component (preferably resembling a screen) and a title for the screen which is required. Optionally the default transition for this screen can be set during registration. It is also the possible to register screens after Reactigation was rendered.

register(Component: React.ReactNode, title: string, { transition?: Transition, background?: string, initial?: boolean })

import { register } from 'reactigation'

const screen = () => (
  <View style={{ flex: 1 }}>
    <Text>Hello World</Text>
  </View>
)

register(screen, 'HelloWorld')
register(screen, 'HelloModal', {
  transition: 'modal',
  background: 'transparent',
})

Configuring the Initial Screen

By default the first registered screen will appear initially. To use another screen initially, pass the initial option as the third argument to register or call initial() with the name of a previously registered screen.

import { register, initial } from 'reactigation'

register(screen, 'FirstScreen')
register(screen, 'SecondScreen', { initial: true })
register(screen, 'ThirdScreen')

initial('SecondScreen')

Accessing the Current Screen

To conditionally render elements based on the current screen use the following React hook that will rerender the component with the new currentScreen each time a navigation occurs.

import { useCurrentScreen } from 'reactigation'

export const Footer = () => {
  const currentScreen = useCurrentScreen()

  if (currentScreen !== 'Overview') {
    return null
  }

  ...
}

If you don't need a rerender to be triggered use the variable import { currentScreen } from 'reactigation'.

Static Parts

In order for some components to always be rendered simply add another view next to the navigation.

export default () => (
  <>
    <Reactigation />
    <View style={styles.tabs}>
      {...}
    </View>
  </>
)

When you need to wrap <Reactigation /> in a view make sure to add <View style={{ flex: 1 }}> in order for the navigation to be visible.

Custom Transitions

It's possible to configure some variables for the base animations.

import { CustomTransition } from 'reactigation'

const AlmostFullPeek = CustomTransition.peek(20) // 20% backdrop visible.
const SuperSlow = CustomTransition.regular(5000) // 5 seconds duration.
const SuperFastOpacity = CustomTransition.opacity(50) // 50 ms duration of opacity blur.

register(<FirstScreen />, 'First', { transition: AlmostFullPeek })
go('First', SuperSlow)
back(SuperFastOpacity)

Headless Mode for Testing

Headless mode will automatically be enabled in a testing environment process.env.NODE === 'test'. It's also possible to control this mode manually on the main component.

import Reactigation from 'reactigation'

const App = () => <Reactigation headless={false} />
AppRegistry.registerComponent('NavigationApp', () => App)

Running the Example App

The example app shown on top is found in the repository. Run it by cloning this repository and then executing the following commands inside the main directory.

npm install
npm run app --silent
cd app
react-native run-ios

Development

To develop the plugin further generate and run the example app. After that npm run watch in the main directory will copy over changes made in the src folder directly to the app. There are also a few static tests in the test folder which can be run with npm test.

Inspiration

The idea for the plugin came after experiencing some issues with native dependencies for an existing React Native navigation plugin.