mattermost-mobile/app/navigation/router.js
enahum 81526fbb09 Channel drawer (#154)
* Channel list drawer
* Get channels by category
* Fix and connect websocket
* Fix Select first team using the team members

* create loadMe and fix login actions to loads the teams

* Add android back button handler for the channel drawer

* Channel drawer styling and functionality

* Mark channel as viewed and fixed reset unread counts

* Unread above/below indicators

* Improve performance replacing ScrollView with ListView

* Fix unread indicators

* Addressing review feedback
2017-01-03 19:49:28 -03:00

120 lines
3.1 KiB
JavaScript

// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {goBack} from 'app/actions/navigation';
import {getComponentForScene} from 'app/scenes';
import {Easing, NavigationExperimental, View} from 'react-native';
import FormattedText from 'app/components/formatted_text';
class Router extends React.Component {
static propTypes = {
navigation: React.PropTypes.object,
actions: React.PropTypes.shape({
goBack: React.PropTypes.func
}).isRequired
};
renderTransition = (transitionProps) => {
let title;
if (transitionProps.scene.route.title) {
title = (
<NavigationExperimental.Header
{...transitionProps}
onNavigateBack={this.props.actions.goBack}
renderTitleComponent={this.renderTitle}
/>
);
}
const renderedScenes = transitionProps.scenes.map((scene) => {
const cardProps = {
...transitionProps,
scene
};
return (
<NavigationExperimental.Card
{...cardProps}
style={NavigationExperimental.Card.PagerStyleInterpolator.forHorizontal({
...cardProps
})}
renderScene={this.renderScene}
key={scene.key}
/>
);
});
return (
<View style={{flex: 1, flexDirection: 'column-reverse'}}>
<View style={{flex: 1}}>
{renderedScenes}
</View>
{title}
</View>
);
};
renderTitle = ({scene}) => {
const title = scene.route.title;
if (!title) {
return null;
}
return (
<NavigationExperimental.Header.Title>
<FormattedText
id={title.id}
defaultMessage={title.defaultMessage}
/>
</NavigationExperimental.Header.Title>
);
};
renderScene = ({scene}) => {
const SceneComponent = getComponentForScene(scene.route.key);
return <SceneComponent {...scene.route.props}/>;
};
configureTransition = () => {
return {
duration: 500,
easing: Easing.inOut(Easing.ease)
};
};
render = () => {
return (
<NavigationExperimental.Transitioner
style={{flex: 1}}
navigationState={this.props.navigation}
render={this.renderTransition}
configureTransition={this.configureTransition}
/>
);
};
}
function mapStateToProps(state) {
return {
navigation: state.navigation
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
goBack
}, dispatch)
};
}
export default connect(mapStateToProps, mapDispatchToProps)(Router);