• Stars
    star
    104
  • Rank 330,604 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Redux actions and reducers for React Native experimental navigation

React Native Navigation Redux helpers

Build Status Code Climate Dependency Status devDependency Status

Reducers and actions to implement navigation in React Native applications (RN 0.28.0+)

When to use this

  • you are using RN ExperimentalNavigation
  • you are using Redux
  • you do not want to write and re-write your own actions and reducers for navigation

Getting started

npm install --save react-native-navigation-redux-helpers

Card navigation

Define your card reducer

import { cardStackReducer } from 'react-native-navigation-redux-helpers';

const initialState = {
  key: 'global',
  index: 0,
  routes: [
    {
	  key: 'applicationSection1',
      index: 0
    },
  ],
};

module.exports = cardStackReducer(initialState);

Use this reducer in NavigationCardStack in your component

import { NavigationExperimental } from 'react-native';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { actions } from 'react-native-navigation-redux-helpers';

const {
  popRoute,
  pushRoute,
} = actions;

const {
  CardStack: NavigationCardStack
} = NavigationExperimental;

class GlobalNavigation extends Component {
	render() {
		return (
      <NavigationCardStack
        navigationState={this.props.navigation}
        renderOverlay={this._renderOverlay}
        renderScene={this._renderScene}
      />
		);
	}

  /* ... */

	onGoBack() {
    const { dispatch, navigation } = this.props;
    dispatch(popRoute(navigation.key));
	}

  onGoSomewhere() {
    const { dispatch, navigation } = this.props;
    dispatch(pushRoute({ key: 'sowhere else' }, navigation.key));
  }
}

function mapDispatchToProps(dispatch) {
	return {
		dispatch
	};
}

function mapStateToProps(state) {
	return {
	    // XX: assuming you've registered the reducer above under the name 'cardNavigation'
		navigation: state.cardNavigation
	};
}

export default connect(mapStateToProps, mapDispatchToProps)(GlobalNavigation);

Tab navigation

Define your tab reducer

import { tabReducer } from 'react-native-navigation-redux-helpers';

const tabs = {
  routes: [
    { key: 'feed', title: 'Items' },
    { key: 'notifications', title: 'Notifications' },
    { key: 'settings', title: 'Settings' }
  ],
  key: 'ApplicationTabs',
  index: 0
};

module.exports = tabReducer(tabs);

And now put it to good use inside your component

import { TabBarIOS } from 'react-native';
import React, { Component } from 'react';
import Feed from '../Feed';
import { connect } from 'react-redux';
import { actions as navigationActions } from 'react-native-navigation-redux-helpers';

const { jumpTo } = navigationActions;

class ApplicationTabs extends Component {
	_renderTabContent(tab) {
		if (tab.key === 'feed') {
			return (
				<Feed />
			);
		}

		/* ... */
	}

	render() {
		const { dispatch, navigation } = this.props;
		const children = navigation.routes.map( (tab, i) => {
			return (
				<TabBarIOS.Item key={tab.key}
						icon={tab.icon}
						selectedIcon={tab.selectedIcon}
						title={tab.title} onPress={ () => dispatch(jumpTo(i, navigation.key)) }
						selected={this.props.navigation.index === i}>
						{ this._renderTabContent(tab) }
				</TabBarIOS.Item>
			);
		});
		return (
			<TabBarIOS tintColor="black">
				{children}
			</TabBarIOS>
		);
	}
}

function mapDispatchToProps(dispatch) {
	return {
		dispatch
	};
}

function mapStateToProps(state) {
	return {
		// XX: assuming your tab reducer is registered as 'tabs'
		navigation: state.tabs
	};
}
export default connect(mapStateToProps, mapDispatchToProps)(ApplicationTabs);

Supported actions

cardStackReducer

  • pushRoute
  • popRoute
  • jumpTo
  • reset
  • replaceAt
  • replaceAtIndex
  • jumpToIndex
  • back
  • forward

tabReducer

  • jumpTo
  • jumpToIndex

Complete examples

More Repositories

1

meteor-devtools

âš¡Chrome Dev tools extension for Meteorjs apps
JavaScript
249
star
2

todomvc-react-native

TodoMVC using React Native + Redux + Parse Server + GraphQL
JavaScript
151
star
3

react-native-complex-nav

Example using RN experimental navigation with Redux
JavaScript
118
star
4

baker

Mobile MVP Toolkit
JavaScript
105
star
5

parse-graphql-server

GraphQL integration for Parse Server
JavaScript
59
star
6

RNNavigationExperimentalRedux

Using ReactNative NavigationExperimental with Redux
JavaScript
47
star
7

pokemon-map

React Native based application to locate Pokemon around you
JavaScript
29
star
8

meteor-spotting

Discover and spot web applications running Meteorjs. Collect your discoveries and compete with other explorers.
CSS
21
star
9

meteorday

Meteor Day Checkin system
JavaScript
21
star
10

archer

Episode transcripts for Archer
JavaScript
17
star
11

openmic

React + Redux + Sagas + Sounds + Images
JavaScript
16
star
12

parse-graphql-client

GraphQL client for apps using Parse Server
JavaScript
14
star
13

doctor-jekyll

Documentation generator
CSS
12
star
14

waldo

Meteor + Cordova - Checkin app
CSS
11
star
15

rust-micrograd

Micrograd in Rust
Rust
10
star
16

generator-rn

DEPRECATED in favor of Baker
JavaScript
9
star
17

meteor-cordova-native-map

Native map component for Meteor Cordova based projects
JavaScript
6
star
18

meteor-collection-csv

Serialize collections to CSV strings
JavaScript
4
star
19

baker-js

JavaScript
4
star
20

meteor-ipgeocoder

IP geocoder for Meteor
JavaScript
3
star
21

gifatar

When an avatar is just not enough
JavaScript
3
star
22

baker-docs

Documentation for Baker
CSS
3
star
23

meteor-seo-heroku

Meteor + Phantomjs + Spiderable on Heroku
JavaScript
2
star
24

react-native-baker

React Native Boilerplate - WIP
JavaScript
1
star
25

actions-cargo-get-version

JavaScript
1
star
26

onair

Play good music. On air.
JavaScript
1
star
27

actions-esp-rs-build

GH action for building Rust ESP32 projects
Shell
1
star
28

geogit

Automatically geolocate your commits
JavaScript
1
star
29

kuya-ios

mobile utility app that helps you learn new languages
Objective-C
1
star
30

twitter-lists

Create twitter lists out of csv files
JavaScript
1
star
31

can-i-haz-good-js

Slides for "Modern client side javascript" talk
JavaScript
1
star
32

redux-form-issue

JavaScript
1
star
33

tidy.surf

JavaScript
1
star
34

rivescript-sublimetext

Rivescript syntax definition for Sublime Text
1
star