Skip to content

Commit 9a826ff

Browse files
committed
Add deck detail navigation screen
1 parent bc730b6 commit 9a826ff

File tree

4 files changed

+94
-21
lines changed

4 files changed

+94
-21
lines changed

App.js

+43-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,54 @@
11
import React from 'react';
2-
import { StyleSheet, Text, View } from 'react-native';
3-
import { TabNavigator } from 'react-navigation';
2+
import { StyleSheet, Text, View, Platform } from 'react-native';
3+
import { TabNavigator, StackNavigator } from 'react-navigation';
44
import DecksList from './components/DecksList';
5+
import DeckDetail from './components/DeckDetail';
56
import AddDeck from './components/AddDeck';
67
import { getCurrentRouteName } from './utils/helpers';
8+
import { black, white } from './utils/colors';
79

8-
const DecksNavigator = TabNavigator({
9-
AddDeck: {
10-
screen: AddDeck,
11-
navigationOptions: {
12-
tabBarLabel: 'NEW DECK'
10+
const DecksNavigator = TabNavigator(
11+
{
12+
DecksList: {
13+
screen: DecksList,
14+
navigationOptions: {
15+
tabBarLabel: 'DECKS'
16+
}
17+
},
18+
AddDeck: {
19+
screen: AddDeck,
20+
navigationOptions: {
21+
tabBarLabel: 'NEW DECK'
22+
}
1323
}
1424
},
15-
Decks: {
16-
screen: DecksList,
25+
{
26+
tabBarOptions: {
27+
activeTintColor: Platform.OS === 'ios' ? black : white,
28+
style: {
29+
height: 56,
30+
backgroundColor: Platform.OS === 'ios' ? white : black,
31+
shadowColor: 'rgba(0, 0, 0, 0.24)',
32+
shadowOffset: {
33+
width: 0,
34+
height: 3
35+
},
36+
shadowRadius: 6,
37+
shadowOpacity: 1
38+
}
39+
}
40+
}
41+
);
42+
43+
const MainNavigator = StackNavigator({
44+
DeckTabs: {
45+
screen: DecksNavigator,
1746
navigationOptions: {
18-
tabBarLabel: 'DECKS'
47+
header: null
1948
}
49+
},
50+
DeckDetail: {
51+
screen: DeckDetail
2052
}
2153
});
2254

@@ -26,7 +58,7 @@ export default class App extends React.Component {
2658
render() {
2759
return (
2860
<View style={styles.container}>
29-
<DecksNavigator
61+
<MainNavigator
3062
onNavigationStateChange={(prevState, currentState) => {
3163
const currentScreen = getCurrentRouteName(currentState);
3264
const prevScreen = getCurrentRouteName(prevState);

components/AddDeck.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class AddDeck extends React.Component {
1212
onSubmit = () => {
1313
const title = this.state.title;
1414
this.setState({ title: '' }, () =>
15-
saveDeckTitle(title).then(() => this.props.navigation.navigate('Decks'))
15+
saveDeckTitle(title).then(() => this.props.navigation.navigate('DecksList'))
1616
);
1717
};
1818

@@ -43,7 +43,8 @@ const styles = StyleSheet.create({
4343
container: {
4444
flex: 1,
4545
justifyContent: 'center',
46-
alignItems: 'center'
46+
alignItems: 'center',
47+
backgroundColor: white
4748
},
4849
heading: {
4950
fontSize: 22,

components/DeckDetail.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import { StyleSheet, Text, View } from 'react-native';
3+
import { black, white } from '../utils/colors';
4+
5+
export default class DeckDetail extends React.Component {
6+
static navigationOptions = ({ navigation }) => ({
7+
headerTintColor: white,
8+
headerStyle: {
9+
backgroundColor: black
10+
},
11+
title: navigation.state.params.deckId
12+
});
13+
14+
render() {
15+
return (
16+
<View style={styles.container}>
17+
<Text style={styles.deckTitle}>Details - {this.props.navigation.state.params.deckId}</Text>
18+
</View>
19+
);
20+
}
21+
}
22+
23+
const styles = StyleSheet.create({
24+
container: {
25+
flex: 1,
26+
justifyContent: 'center',
27+
alignItems: 'center'
28+
},
29+
deckTitle: {
30+
fontSize: 20
31+
}
32+
});

components/DecksList.js

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
2-
import { View, Text, StyleSheet, FlatList } from 'react-native';
3-
import { gray, black } from '../utils/colors';
2+
import { View, Text, StyleSheet, FlatList, TouchableOpacity } from 'react-native';
3+
import { gray, black, white } from '../utils/colors';
44
import { getAllDecks } from '../api';
55

66
export default class DecksList extends React.Component {
@@ -9,8 +9,12 @@ export default class DecksList extends React.Component {
99
this.state = { decks: [] };
1010
}
1111

12+
componentDidMount() {
13+
this.loadDecks();
14+
}
15+
1216
componentWillReceiveProps(nextProps) {
13-
if (nextProps.screenProps.currentScreen === 'Decks') {
17+
if (nextProps.screenProps.currentScreen === 'DecksList') {
1418
this.loadDecks();
1519
}
1620
}
@@ -23,17 +27,20 @@ export default class DecksList extends React.Component {
2327
style={styles.container}
2428
data={this.state.decks}
2529
keyExtractor={(item, index) => index}
26-
renderItem={({ item }) => <Deck key={item.title} {...item} />}
30+
renderItem={({ item }) => <Deck key={item.title} {...item} screenProps={{ ...this.props }} />}
2731
/>
2832
);
2933
}
3034
}
3135

3236
const Deck = props => (
33-
<View style={styles.deck}>
37+
<TouchableOpacity
38+
style={styles.deck}
39+
onPress={() => props.screenProps.navigation.navigate('DeckDetail', { deckId: props.title })}
40+
>
3441
<Text style={styles.deckTitle}>{props.title}</Text>
3542
<Text style={styles.deckCards}>{props.questions.length} Cards</Text>
36-
</View>
43+
</TouchableOpacity>
3744
);
3845

3946
const styles = StyleSheet.create({
@@ -44,8 +51,9 @@ const styles = StyleSheet.create({
4451
height: 100,
4552
justifyContent: 'center',
4653
alignItems: 'center',
47-
borderBottomWidth: 2,
48-
borderBottomColor: black
54+
borderBottomWidth: 1,
55+
borderBottomColor: gray,
56+
backgroundColor: white
4957
},
5058
deckTitle: {
5159
fontSize: 20

0 commit comments

Comments
 (0)