-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
118 lines (110 loc) · 3.25 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { StatusBar } from 'expo-status-bar';
import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createStackNavigator } from '@react-navigation/stack';
import Constants from 'expo-constants';
import { store, getDecks, setLocalNotification } from './utils/helpers';
import DeckList from './components/DeckList';
import NewDeck from './components/NewDeck';
import Deck from './components/Deck';
import Quiz from './components/Quiz';
import Result from './components/Result';
import AddCard from './components/AddCard';
function MyStatusBar({ backgroundColor, ...props }) {
return (
<View style={{ backgroundColor, height: Constants.statusBarHeight }}>
<StatusBar translucent backgroundColor={backgroundColor} {...props} />
</View>
)
}
const Tab = createBottomTabNavigator();
function Tabs(props) {
const { data, fetchData } = props;
return (
<Tab.Navigator
tabBarOptions={{
activeTintColor: 'white',
style: {
height: 56,
backgroundColor: '#fe5a37',
shadowColor: 'rgba(0, 0, 0, 0.24)',
shadowOffset: {
width: 0,
height: 3
},
shadowRadius: 6,
shadowOpacity: 1,
},
tabStyle: {
justifyContent: 'center'
},
labelStyle: {
fontSize: 17,
}
}}>
<Tab.Screen
name="Decks"
options={{ headerShown: false }}>
{props => <DeckList {...props} data={data} />}
</Tab.Screen>
<Tab.Screen
name="New Deck"
options={{ headerShown: false }}>
{props => <NewDeck {...props} fetchData={fetchData} />}
</Tab.Screen>
</Tab.Navigator>
)
}
const Stack = createStackNavigator();
export default class App extends Component {
state = {
flashCards: {}
}
componentDidMount() {
setLocalNotification();
store()
.then(() => this.fetchData());
}
fetchData = () => {
return getDecks()
.then((flashCards) => {
this.setState(() => ({
flashCards
}))});
}
render() {
const { flashCards } = this.state;
return (
<NavigationContainer>
<View style={{ flex: 1 }}>
<MyStatusBar backgroundColor='#fe5a37' barStyle='light-content' />
<Stack.Navigator>
<Stack.Screen
name="Decks">
{props => <Tabs {...props} data={flashCards} fetchData={this.fetchData} />}
</Stack.Screen>
<Stack.Screen
name="Deck"
component={Deck}
options={({ route }) => ({
title: route.params.title,
})} />
<Stack.Screen
name="Quiz"
component={Quiz}
initialParams={{ correctCount: 0 }} />
<Stack.Screen
name="Result"
component={Result} />
<Stack.Screen
name="AddCard">
{props => <AddCard {...props} fetchData={this.fetchData} />}
</Stack.Screen>
</Stack.Navigator>
</View>
</NavigationContainer>
)
}
}