Change Room’s back button text to previews screen title (#112)

Closes #108
This commit is contained in:
Rodrigo Nascimento 2017-11-23 17:12:06 -02:00 committed by Guilherme Gazzo
parent 9dc16c8adb
commit ed1448b864
2 changed files with 5 additions and 19 deletions

View File

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { Platform } from 'react-native'; import { Platform } from 'react-native';
import { StackNavigator, DrawerNavigator, NavigationActions, HeaderBackButton } from 'react-navigation'; import { StackNavigator, DrawerNavigator } from 'react-navigation';
import Sidebar from '../../containers/Sidebar'; import Sidebar from '../../containers/Sidebar';
import DrawerMenuButton from '../../presentation/DrawerMenuButton'; import DrawerMenuButton from '../../presentation/DrawerMenuButton';
@ -13,14 +13,6 @@ import SelectUsersView from '../../views/SelectUsersView';
const drawerPosition = 'left'; const drawerPosition = 'left';
const drawerIconPosition = 'headerLeft'; const drawerIconPosition = 'headerLeft';
const backToScreen = (navigation, routeName) => {
const action = NavigationActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName })]
});
navigation.dispatch(action);
};
const AuthRoutes = StackNavigator( const AuthRoutes = StackNavigator(
{ {
RoomsList: { RoomsList: {
@ -36,13 +28,7 @@ const AuthRoutes = StackNavigator(
screen: RoomView, screen: RoomView,
navigationOptions({ navigation }) { navigationOptions({ navigation }) {
return { return {
title: navigation.state.params.title || 'Room', title: navigation.state.params.title || 'Room'
headerLeft: (
<HeaderBackButton
title='Back'
onPress={() => backToScreen(navigation, 'RoomsList')}
/>
)
// [drawerIconPosition]: (<DrawerMenuButton navigation={navigation} />)÷ // [drawerIconPosition]: (<DrawerMenuButton navigation={navigation} />)÷
}; };
} }

View File

@ -193,7 +193,7 @@ export default class RoomsListView extends React.Component {
_onPressItem = (id, item = {}) => { _onPressItem = (id, item = {}) => {
const navigateToRoom = (room) => { const navigateToRoom = (room) => {
this.props.navigation.navigate('Room', { room }); this.props.navigation.navigate('Room', { room, title: room.name });
}; };
const clearSearch = () => { const clearSearch = () => {
@ -220,7 +220,7 @@ export default class RoomsListView extends React.Component {
} }
}); });
})) }))
.then(sub => navigateToRoom({ sid: sub._id })) .then(sub => navigateToRoom({ sid: sub._id, name: sub.name }))
.then(() => clearSearch()); .then(() => clearSearch());
} else { } else {
clearSearch(); clearSearch();
@ -229,7 +229,7 @@ export default class RoomsListView extends React.Component {
return; return;
} }
navigateToRoom({ sid: id, ...item }); navigateToRoom({ sid: id, name: item.name });
clearSearch(); clearSearch();
} }