Skip to content

Commit

Permalink
Step 3.6: Add Messages to Navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
srtucker22 authored and Simon Tucker committed Aug 26, 2018
1 parent 461e028 commit a977f02
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions client/src/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Text, View, StyleSheet } from 'react-native';
import { connect } from 'react-redux';

import Groups from './screens/groups.screen';
import Messages from './screens/messages.screen';

const styles = StyleSheet.create({
container: {
Expand Down Expand Up @@ -45,6 +46,9 @@ const MainScreenNavigator = TabNavigator({

const AppNavigator = StackNavigator({
Main: { screen: MainScreenNavigator },
Messages: { screen: Messages },
}, {
mode: 'modal',
});

// reducer initialization code
Expand Down
25 changes: 24 additions & 1 deletion client/src/screens/groups.screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@ const fakeData = () => _.times(100, i => ({
}));

class Group extends Component {
constructor(props) {
super(props);

this.goToMessages = this.props.goToMessages.bind(this, this.props.group);
}

render() {
const { id, name } = this.props.group;
return (
<TouchableHighlight
key={id}
onPress={this.goToMessages}
>
<View style={styles.groupContainer}>
<Text style={styles.groupName}>{`${name}`}</Text>
Expand All @@ -52,6 +59,7 @@ class Group extends Component {
}

Group.propTypes = {
goToMessages: PropTypes.func.isRequired,
group: PropTypes.shape({
id: PropTypes.number,
name: PropTypes.string,
Expand All @@ -63,9 +71,19 @@ class Groups extends Component {
title: 'Chats',
};

constructor(props) {
super(props);
this.goToMessages = this.goToMessages.bind(this);
}

keyExtractor = item => item.id.toString();

renderItem = ({ item }) => <Group group={item} />;
goToMessages(group) {
const { navigate } = this.props.navigation;
navigate('Messages', { groupId: group.id, title: group.name });
}

renderItem = ({ item }) => <Group group={item} goToMessages={this.goToMessages} />;

render() {
// render list of groups for user
Expand All @@ -80,5 +98,10 @@ class Groups extends Component {
);
}
}
Groups.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func,
}),
};

export default Groups;

0 comments on commit a977f02

Please sign in to comment.