Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-navigation-helpers

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-navigation-helpers

Easy to use React Navigation with these helpers for React Navigation on React Native

  • 2.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
916
decreased by-6.82%
Maintainers
1
Weekly downloads
 
Created
Source
React Navigation Helpers

Battle Tested ✅

Helpers for React Navigation

npm version npm expo-compatible Platform - Android and iOS License: MIT

Installation

Add the dependency:

React Native:

npm i react-navigation-helpers

Peer Dependencies

Works with React Navigation

  • v6
  • v5
  • v4
"@react-navigation/native": ">= 4.x.x"

React Navigation Versions

VersionSupported React Navigation Version
2.0.0 >v6
1.1.1v5
< 0.1.0v4

Usage

Global Level Navigator

Set the global level navigation reference into the NavigationContainer

import { isReadyRef, navigationRef } from "react-navigation-helpers";

useEffect((): any => {
  return () => (isReadyRef.current = false);
}, []);

<NavigationContainer
  ref={navigationRef}
  onReady={() => {
    isReadyRef.current = true;
  }}
>
  {/* Rest of your code */}
</NavigationContainer>;

NavigationService Usage

Navigate Example

import * as NavigationService from "react-navigation-helpers";

NavigationService.navigate("home");

Push Example

import * as NavigationService from "react-navigation-helpers";

NavigationService.push("home");

Pop Example

import * as NavigationService from "react-navigation-helpers";

NavigationService.pop();

PopToTop Example

import * as NavigationService from "react-navigation-helpers";

NavigationService.popToTop();

Back Example

import * as NavigationService from "react-navigation-helpers";

NavigationService.back();

How to pass prop with this library?

The usage does not change. Simply put your prop as the secondary prop as same as React Navigation itself.

Navigate

import * as NavigationService from "react-navigation-helpers";

NavigationService.navigate("home", { data: myData, myId: "d1f01df1" });

Push

import * as NavigationService from "react-navigation-helpers";

NavigationService.push("home", { data: myData, myId: "d1f01df1" });

How to receive the passed props from navigation or push functions?

const { data, id } = this.props.route.params;

Configuration - Props

PropertyTypeDefaultDescription
navigatefunctionfunctionnavigate the selected screen
pushfunctionfunctionpush the selected screen
goBackfunctionfunctionback the previous screen
popfunctionfunctionpop the previous screen
popToTopfunctionfunctionpop the top level of the screen
resetfunctionfunctionreset the navigator

Global Stack Navigator Events

To listen to the Stack navigator events from anywhere, you need to import navigationListenerProps and spread it as props. It is currently limited to a single stack navigator.

import { isReadyRef, navigationRef, navigationListenerProps } from "react-navigation-helpers";

useEffect((): any => {
  return () => (isReadyRef.current = false);
}, []);

<NavigationContainer
  ref={navigationRef}
  onReady={() => {
    isReadyRef.current = true;
  }}
>
  <Stack.Navigator {...navigationListenerProps}>
      {/* Rest of your code */}
  </Stack.Navigator>
</NavigationContainer>;

you can then listen to stack navigation events anywhere in your app.

Example in a component:

import React, {useEffect} from "react"
import {addNavigationListener} from "react-navigation-helpers"
// or as a whole
import * as NavigationService from "react-navigation-helpers";

const MyComponent = () => {
    
    useEffect(() => {
        return addNavigationListener("transitionEnd", () => {
            // transition ended
        })
    })

    // or like this
    useEffect(() => {
        return NavigationService.addNavigationListener("transitionEnd", () => {
            // transition ended
        })
    })
    
    return (
        <Text>Hello world!</Text>
    )
}

Roadmap

  • LICENSE
  • Write an article about the lib on Medium

Author

FreakyCoder, kurayogun@gmail.com

License

React Navigation Helpers Library is available under the MIT license. See the LICENSE file for more info.

Keywords

FAQs

Package last updated on 10 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc