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

mobx-react-navigation-store

v1.4.4

Published

a simple solution for nested navigators in react native.

Downloads

177

Readme

text

Welcome

This project is simple solution for nested navigators in react native with optional navigation state presistence.

you use it almost like you use react-navigation, with a few changes.

if you want to contribute you can

  • see the Contributing section and then you can
    • open issues with ideas for improvments
    • help with documantion
    • forks and PRs are most welcome

of course you don't have to contribute to enjoy this package, so enjoy!

Change log

  • version 1.4.4 - DOCS ARE UP TO DATE! - if there are any issues with the doc let me know
  • version 1.4.3 - added debug support - to allow console logs on dev enviorment - Jul 2, 2018
  • versions 1.4.1-2 - bug fixes
  • version 1.4.0 - now supports nested navigation via reactions - Jun 27, 2018
  • versions 1.3.5-6 - fixed crash caused by on change state handlers
  • version 1.3.4 - added app state on change handlers to navigators implementation - Jun 13, 2018
  • version 1.3.3 - added try catch blocks to handle react-navigation errors - Jun 13, 2018
  • version 1.3.2 - changed timeouts durations - Jun 7, 2018
  • version 1.3.1 - fixed logout - Jun 4, 2018
  • version 1.2.0 - added reset object to doneHydrating params - May 26, 2018

older versions will be added soon...

Why?

while working with react native I found that I need to use quite often with nested navigators and keeping the navigation state when the user closes the app. after many times implementing an app specific navigation store using mobx, so this project aspires to be a generic navigation state mangment store which supports navigation presisitence.

Working example - the example is not up to date and will work only with older versions of the package

WILL UPDATE EXAMPLE SOON!

you can check out the very simple react native example app just click here and follow the instructions enjoy!

Installation

yarn add mobx-react-navigation-store

or with npm

npm install mobx-react-navigation-store --save

npm page - https://www.npmjs.com/package/mobx-react-navigation-store

This project depends on other project so if you're using any of the following packages:

  • mobx
  • mobx-persist
  • mobx-react
  • react-navigation

Note that this packages are installed automatically when installing mobx-react-navigation-store with the following versions:

  • "mobx": "^3.4.1",
  • "mobx-persist": "^0.4.1",
  • "mobx-react": "^4.4.1",
  • "react-navigation": "^1.1.2"

Usage

Note that more info on the specific methods and fields will be added later in another section this is just general usage instructions

to see full docs press here

import

this package exports a singelton so every where you import will have the same data inside

import NavigationStore from 'mobx-react-navigation-store'

to import navigators , you should use these insted of the ones in 'react-navigation' these navigators wrap the react-navigation navigators to work with the store

import { DrawerNavigator, StackNavigator, TabNavigator  } from 'mobx-react-navigation-store'

hydrate store and set navigators

the hydration should happen in the component that renders the main navigator this code is from the react native example app, so assume usage of three navigators called: Main,NavOne,NavTwo where Main is the parent of NavOne and NavOne is the parent of NavTwo and NavTwo is not persistent. you must remember to also import create from mobx-persist like so:

import { create } from 'mobx-persist'
const hydrate = create({
    storage: AsyncStorage //this is since I'm using react native
})
    componentWillMount() {
        hydrate('navigation', NavigationStore).then(() => {
             NavigationStore.setNavigators({
                MainDrawer: {
                    type: 'drawer', //default value : 'stack'
                    initRoute:'Home' //required
                    nested: { NestedNavigatorTabs: 'MainTabs' }, //default value : null
                    parent: null, //default value : null
                    shouldPersist: true, //default value : true
                    routes:null //default value : null
                },
                MainTabs: {
                    type: 'tab',
                    initRoute:'Home'
                    parent: 'MainDrawer',
                    nested: { NestedNavigatorMain: 'Main' },
                    shouldPersist: true,
                    routes: ['Home', 'Two', 'NestedNavigatorMain'],
                },
                Main: {
                    type: 'stack',
                    nested: { NestedNavigator: 'NavOne' },
                    parent: 'MainTabs',
                    initRoute:'MainFirst'
                },
                NavOne: {
                    type: 'stack',
                    parent: 'Main',
                    nested: { NestedNavigator: 'NavTwo' },
                    initRoute:'NavOneFirst'
                },
                NavTwo: {
                    type: 'tab',
                    parent: 'NavOne',
                    routes: ['NavTwoFirst', 'NavTwoSecond'],
                    initRoute:'NavTwoFirst'
                }
            },{
                initialNavigatorName: 'MainDrawer',//the initial navigator name, required
                order:['MainDrawer', 'MainTabs', 'Main', 'NavOne', 'NavTwo']//order of nesting of navigators, required
            })
            setTimeout(() => NavigationStore.doneHydrating(), 1000)
            NavigationStore.StartedStoreHydration()
        }).catch(error => console.log(error))
    }

example stack navigator

right now in order to make a screen marked as a nested navigator you must give it a name including the string: 'NestedNavigator' it can be anything including this string for example : 'NestedNavigator1' or 'NestedNavigator_Chat' or 'NestedNavigatorOne' etc.

import { StackNavigator } from 'mobx-react-navigation-store'

const Main = StackNavigator(
    'Main',
    {
        MainFirst: { screen: ScreenOne },
        MainSecond: { screen: ScreenTwo },
        MainThird: { screen: ScreenThree },
        NestedNavigator: { screen: NavigatorOne },
    }, {
        headerMode: 'none',
        initialRouteName: 'MainFirst',
    }
)

then inside render function , where needed

render(){
    /*render code*/
    <Main screenProps={/* this prop will get passed to the screen components as this.props.screenProps */}/>
    /*render code*/
}

passing the navigator store via mobx provider

Although as mentioned above, you can just import the navigation store at any screen and it will stay concurrent, you can also pass it via props or via the mobx provider like so:

import { Provider } from 'mobx-react/native'
const stores = { NavigationStore /*add any other stores you want to provide*/ } //assuming you imported NavigationStore

this is inside the render function of the component and as you can see inside the provider is the main navigator and now all of his screens and nested navigators will recieve NavigationStore as a prop

<Provider {...stores}> 
    <Main /> 
</Provider>

notice that in order to react to changes in observables you need the component getting the store to be an observer, and have @inject('NavigationStore')

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the MIT License

Acknowledgments

this package uses the packages mentioned above, which are great packages that are open source for more info on these packages and how to use them so you can make greater benefit of this package use the links below:

Big thanks to all the people responsible for these projects