# react-native-navigation-redux-helpers-compat

> Redux helpers for React Native navigation experimental compat

Latest version **0.6.0** (published 2017-08-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-navigation-redux-helpers-compat
pnpm add react-native-navigation-redux-helpers-compat
yarn add react-native-navigation-redux-helpers-compat
bun add react-native-navigation-redux-helpers-compat
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2017-08-11 |
| First published | 2017-08-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | The Bakery/azundo |
| Maintainers | azundo |

## Links

- npm: https://www.npmjs.com/package/react-native-navigation-redux-helpers-compat
- Repository: https://github.com/azundo/react-native-navigation-redux-helpers-compat
- Issues: https://github.com/azundo/react-native-navigation-redux-helpers-compat/issues
- npm.io page: https://npm.io/package/react-native-navigation-redux-helpers-compat

## Dependencies (1)

- [react-native-navigation-experimental-compat](https://npm.io/package/react-native-navigation-experimental-compat.md) ^1.0.0

## Recent versions

- 0.6.0 (latest) — 2017-08-11

## README

# React Native Navigation Redux helpers

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

```bash
npm install --save react-native-navigation-redux-helpers-compat
```

### Card navigation

Define your card reducer 

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

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

module.exports = cardStackReducer(initialState);
```

Use this reducer in NavigationCardStack in your component

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

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

```javascript
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

```javascript
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-compat';

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

- [Example using RN experimental navigation with Redux](https://github.com/thebakeryio/react-native-complex-nav)
- [TodoMVC React Native](https://github.com/thebakeryio/todomvc-react-native)

---
_Source: https://npm.io/package/react-native-navigation-redux-helpers-compat · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
