Skip to content

Instantly share code, notes, and snippets.

@callmephilip
Created May 18, 2016 16:06
Show Gist options
  • Save callmephilip/5215aec285df0ef2c61d001c45c197fa to your computer and use it in GitHub Desktop.
Save callmephilip/5215aec285df0ef2c61d001c45c197fa to your computer and use it in GitHub Desktop.
import { View, NavigationExperimental } from 'react-native';
import React, { Component } from 'react';
import styles from './styles';
import { connect } from 'react-redux';
import Items from '../Items';
import ItemDetails from '../ItemDetails';
const { CardStack: NavigationCardStack } = NavigationExperimental;
class Feed extends Component {
render() {
return (
<NavigationCardStack
direction={'horizontal'}
navigationState={this.props.navigation}
onNavigate={this._onNavigate}
renderScene={this._renderScene.bind(this)}
style={styles.main}
/>
);
}
_renderScene(props) {
if (props.scene.navigationState.key === 'list') {
return (
<View style={{marginTop: NavigationHeader.HEIGHT}}>
<Items onSelectItem={this._onSelectItem.bind(this)} />
</View>
);
}
if (props.scene.navigationState.key === 'details') {
return (
<View style={{marginTop: NavigationHeader.HEIGHT}}>
<ItemDetails />
</View>
);
}
}
_onAddItem() {
this.props.onNavigate({
type: 'push',
route: {
key: 'new',
title: 'Main Screen',
showBackButton: true
}
});
}
_onSelectItem() {
this.props.onNavigate({
type: 'push',
route: {
key: 'details',
title: 'Item details',
showBackButton: true
}
});
}
}
function mapDispatchToProps(dispatch) {
return {
dispatch,
onNavigate: (action) => {
dispatch(action);
}
};
}
function mapStateToProps(state) {
return {
navigation: state.get('feed')
};
}
export default connect(mapStateToProps, mapDispatchToProps)(Feed);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment