Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatted code snippets in Readme #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 53 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,54 +47,53 @@ import React, { Component } from 'react';
import { connect } from 'react-redux';
import { actions } from 'react-native-navigation-redux-helpers';

const {
popRoute,
pushRoute,
} = actions;
const { popRoute, pushRoute } = actions;

const {
CardStack: NavigationCardStack
} = NavigationExperimental;
const { CardStack: NavigationCardStack } = NavigationExperimental;

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

/* ... */

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

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

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

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

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

```

### Tab navigation
Expand Down Expand Up @@ -129,50 +128,46 @@ import { actions as navigationActions } from 'react-native-navigation-redux-help
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>
);
}
_renderTabContent(tab) {
if (tab.key === 'feed') {
return <Feed />;
}

/* ... */
}

render() {
const { dispatch, navigation } = this.props;
const children = navigation.routes.map((tab, i) => (
<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
};
return {
dispatch,
};
}

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

```

## Supported actions
Expand Down