Adding servers to drawer menu, allowing server switch.
This commit is contained in:
parent
3e5032f18e
commit
e76e73bd87
|
@ -1,23 +1,35 @@
|
|||
import { StackNavigator } from 'react-navigation';
|
||||
import React, { Component } from 'react';
|
||||
import { StackNavigator, DrawerNavigator } from 'react-navigation';
|
||||
import { Platform } from 'react-native';
|
||||
|
||||
import Sidebar from '../../containers/Sidebar';
|
||||
import DrawerMenuButton from '../../presentation/DrawerMenuButton';
|
||||
|
||||
import RoomsListView from '../../views/RoomsListView';
|
||||
import RoomView from '../../views/RoomView';
|
||||
import CreateChannelView from '../../views/CreateChannelView';
|
||||
|
||||
const drawerPosition = Platform.OS === 'ios' ? 'right' : 'left';
|
||||
const drawerIconPosition = Platform.OS === 'ios' ? 'headerRight' : 'headerLeft';
|
||||
|
||||
|
||||
const AuthRoutes = StackNavigator(
|
||||
{
|
||||
RoomsList: {
|
||||
screen: RoomsListView,
|
||||
navigationOptions: {
|
||||
title: 'Rooms'
|
||||
navigationOptions({ navigation }) {
|
||||
return {
|
||||
title: 'Rooms',
|
||||
[drawerIconPosition]: (<DrawerMenuButton navigation={navigation} />)
|
||||
};
|
||||
}
|
||||
},
|
||||
Room: {
|
||||
screen: RoomView,
|
||||
navigationOptions({ navigation }) {
|
||||
return {
|
||||
title: navigation.state.params.title || 'Room'
|
||||
title: navigation.state.params.title || 'Room',
|
||||
[drawerIconPosition]: (<DrawerMenuButton navigation={navigation} />)
|
||||
};
|
||||
}
|
||||
},
|
||||
|
@ -32,5 +44,19 @@ const AuthRoutes = StackNavigator(
|
|||
}
|
||||
);
|
||||
|
||||
const Routes = DrawerNavigator({
|
||||
Home: {
|
||||
screen: AuthRoutes,
|
||||
navigationOptions({ navigation }) {
|
||||
return {
|
||||
title: 'Rooms',
|
||||
[drawerIconPosition]: (<DrawerMenuButton navigation={navigation} />)
|
||||
};
|
||||
}
|
||||
}
|
||||
}, {
|
||||
contentComponent: Sidebar,
|
||||
drawerPosition
|
||||
});
|
||||
|
||||
export default AuthRoutes;
|
||||
export default Routes;
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { TouchableOpacity } from 'react-native';
|
||||
import Icon from 'react-native-vector-icons/Ionicons';
|
||||
import Icon from 'react-native-vector-icons/FontAwesome';
|
||||
|
||||
const DrawerMenuButton = ({ navigation }) => (
|
||||
<TouchableOpacity
|
||||
onPress={() => navigation.navigate('DrawerOpen')}
|
||||
>
|
||||
<Icon name='menu' style={{ color: '#ffffff' }} />
|
||||
<Icon name='bars' style={{ padding: 10, marginLeft: 10 }} size={20} color='black' />
|
||||
</TouchableOpacity>
|
||||
);
|
||||
|
||||
|
|
|
@ -84,6 +84,7 @@ export default class ListServerView extends React.Component {
|
|||
this.state = {
|
||||
sections: []
|
||||
};
|
||||
this.redirected = false;
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
|
@ -95,10 +96,15 @@ export default class ListServerView extends React.Component {
|
|||
this.state = this.getState();
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if (this.props.connected && !prevProps.connected &&
|
||||
this.props.server && !this.props.login.token) {
|
||||
componentDidUpdate() {
|
||||
if (this.props.connected &&
|
||||
this.props.server &&
|
||||
!this.props.login.token &&
|
||||
!this.redirected) {
|
||||
this.redirected = true;
|
||||
this.props.navigation.navigate('Login');
|
||||
} else if (!this.props.connected) {
|
||||
this.redirected = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue