Giter VIP home page Giter VIP logo

react-navigation-mobx-helpers's Introduction

react-navigation-mobx-helpers

React-Navigation bindings for MobX

Installation

npm install react-navigation-mobx-helpers --save

Usage

import React from 'react';
import { Provider, inject, observer } from 'mobx-react';
import { StackNavigator } from 'react-navigation';
import NavigationStore from 'react-navigation-mobx-helpers';

const RootNavigator = StackNavigator(RouteConfigs);

const rootNavigation = new NavigationStore();

class Root extends React.Component {
  render() {
    return (
      <Provider rootNavigation={rootNavigation}>
        <App />
      </Provider>
    );
  }
}

@inject('rootNavigation')
@observer
class App extends React.Component {
  render() {
    const { rootNavigation } = this.props;
    return <RootNavigator ref={rootNavigation.createRef} />;
  }
}

API

Action Parameter Description
createRef ref: React.Component Save an instance of navigation to store
dispatch action: NavigationAction Send an action to router
getParam paramName: string, fallback?: NavigationParams Get a specific param with fallback
setParams newParams: NavigationParams Make changes to route's params
navigate { routeName: string, params?: NavigationParams, action?: NavigationAction, key?: string } OR routeName: string, params?: NavigationParams, action?: NavigationAction Go to another screen, figures out the action it needs to take to do it
push routeName: string, params?: NavigationParams, action?: NavigationAction Navigate forward to new route in stack
replace routeName: string, params?: NavigationParams, action?: NavigationAction Replace the current route with a new one
goBack routeKey?: string | null Close active screen and move back in the stack
pop n?: number, params?: { immediate?: boolean } Go back in the stack
popToTop params?: { immediate?: boolean } Go to the top of the stack

react-navigation-mobx-helpers's People

Contributors

el-psy-k avatar dimous avatar seventhunders07 avatar

Stargazers

Peter Chow avatar RenderCoder avatar Dmitry Zakharov avatar Fabrizio avatar Earl Ferguson avatar Brady Caspar avatar Florian Klenk avatar Hubert Pietrusiak avatar fan.li avatar zgatrying avatar Abdullah Al Mamun avatar Jolene Engo avatar Darcy Turk avatar MarcusLee avatar Haitao Lee avatar Thupi Ceylons avatar Hu avatar Dustin Swan avatar Theo avatar Vitor L Cavalcanti avatar Warlock avatar David Stoker avatar Takeo Asai avatar  avatar Garrett Wolf avatar Vlad Trukhin avatar Patrick Luzolo avatar

Watchers

Patrick Luzolo avatar Theo avatar  avatar

react-navigation-mobx-helpers's Issues

React navigation v3 support

Hi,

I use your package with Expo an I have to upgrade to React Navigation v3.
Do you plan to support this version ?

Regards.

Can't use typescript with this library

When I use typescript with this library, the error occurs due type definition is not correct. So I workaround by changing from:

import NavigationStore from 'react-navigation-mobx-helpers';
to
import NavigationStore from 'react-navigation-mobx-helpers/dist';

I think when you combine the index.js & index.d.ts inside dist folder. So please add in package.json configure where type definition.

  "main": "index.js",
  "types": "index.d.ts",

(Question) Using my store

Thank you for this library!

How can I inject my store so that I can access it via this.props.store (or something similar) in my components?

I'd appreciate any help on this. Thanks!

this.Navigator error in index.js

Hi there,
I am new to React native and Mobx so feel free to tell me if i'm not doing it right...

I installed your helper via yarn.
In myApp/node_modules/react-navigation-mobx-helpers/dist/ i get a compiled JS version of your TS file.
While setting new NavigationStore(RootNavigator) i got an error saying that "router" is undefined in line 12 of index.js.

To fix i manually moved "this.Navigator = Navigator;" from line 108 to the top...

Is there an error while compiling to JS or am i doing it wrong ?

screen shot 2018-02-26 at 13 16 51

Flow types?

Hello,
This has been super helpful! Have created flow-type definitions for this file?
Thanks!

Sometimes I get "s.getChildNavigation is not a function"

Sometimes (rarely) after auth when I redirect user from my auth backed to app via deeplink, I get error catched by Sentry:

TypeError: TypeError: TypeError: s.getChildNavigation is not a function. (In 's.getChildNavigation(t.key)', 's.getChildNavigation' is undefined)

This error is located at:
    in k
    in T
    in v
    in RCTView
    in RCTView
    in l
    in RCTView
    in l
    in RCTView
    in n
    in h
    in k
    in v
    in l
    in k
    in L
    in RCTView
    in n
    in inject-n-with-mainState
    in n
    in n
    in S
    in RCTView
    in RCTView
    in f

This error is located at:
    in L
    in RCTView
    in n
    in inject-n-with-mainState
    in n
    in n
    in S
    in RCTView
    in RCTView
    in f
  at forEach([native code])
  at value([native code])

I think this may be related with this problem react-navigation/react-navigation#4481
Due to react-navigation version 3.0.9 update.

Main packages what I use:

    "expo": "^32.0.0",
    "mobx": "^4.5.0",
    "mobx-react": "^5.2.8",
    "mobx-sync": "^1.0.0",
    "react": "16.5.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
    "react-navigation": "^3.0.9",
    "react-navigation-mobx-helpers": "^2.0.0",
    "sentry-expo": "~1.9.0",

I will be glad to any help. Because error report not informative.

Open drawer not working

Hi,

The action navigationStore.navigate('DrawerOpen') doesn't open the drawer.

Can you try it in your side ?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.