-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
124 lines (103 loc) · 4.01 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
119
120
121
122
123
124
import { StatusBar } from 'expo-status-bar';
import { NavigationContainer, useNavigation } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import LandingPage from './screens/LandingPageScreen';
import Timer from './screens/TimerScreen';
import List from './screens/ListScreen';
import { MaterialCommunityIcons } from '@expo/vector-icons';
import { FontAwesome } from '@expo/vector-icons';
import { AntDesign } from '@expo/vector-icons';
import StatsScreen from './screens/StatsScreen';
import { Color } from './constants/Colors';
import AddTask from './screens/AddTask';
import { useEffect } from 'react';
import * as SplashScreen from 'expo-splash-screen'
import { useState } from 'react';
import { init } from './store/database';
import AsyncStorage from '@react-native-async-storage/async-storage';
import LoadingOverlay from './components/LoadingOverlay';
SplashScreen.preventAutoHideAsync(); ///Adding A SplashScreen Initially while data is loaded
const Stack=createNativeStackNavigator();
const Tab=createBottomTabNavigator();
///Above are the navigators used in the application
function ListAdd({navigation})
{
return (
<Stack.Navigator>
<Stack.Screen options={{headerShown:false}} name='List' component={List}></Stack.Screen>
<Stack.Screen options={{}} name='addTask' component={AddTask} ></Stack.Screen>
</Stack.Navigator>
)
}
export function HomePage()
{
return <Tab.Navigator screenOptions={{tabBarItemStyle:{backgroundColor:Color.primary600},headerShown:false,tabBarShowLabel:false,tabBarActiveTintColor:'#6E7DFF'}}>
<Tab.Screen listeners={{tabPress:e=>{e.preventDefault()}}} name='ListAdd' options={{tabBarStyle:{borderTopWidth:0,height:80},tabBarIcon:({color})=><FontAwesome name="th-list" size={30} color={color} />}} component={ListAdd}></Tab.Screen>
<Tab.Screen listeners={{tabPress:e=>{e.preventDefault()}}} name='Timer' options={{tabBarStyle:{borderTopWidth:0,height:80},tabBarIcon:({color})=><MaterialCommunityIcons name="timer" size={30} color={color} />}} component={Timer}></Tab.Screen>
<Tab.Screen name='Stats'options={{tabBarStyle:{borderTopWidth:0,height:80},tabBarIcon:({color})=><AntDesign name="piechart" size={30} color={color} />}} component={StatsScreen}></Tab.Screen>
</Tab.Navigator>
}
export default function App() {
const[dbInitialized,setDbInitialized]=useState(false);
const [firstLaunch,setIsFirstLaunch]=useState(null);
useEffect(()=>{
init().then(()=>{
setDbInitialized(true)
}).catch((err)=>{
console.log(err);
})
},[])
///using this useEffectHook we are fetching data from backend(sqlite)
if(dbInitialized)
{
async function hideScreen()
{
await SplashScreen.hideAsync();
}
hideScreen(); //hiding the splash Screen when data is loaded
}
useEffect(()=>{
AsyncStorage.getItem('alreadyLaunched').then((data)=>{
if(data===null)
{
AsyncStorage.setItem('alreadyLaunched','true');
setIsFirstLaunch(true);
}
else{
setIsFirstLaunch(false);
// navigation.replace('Home');
}
})
},[])
if(firstLaunch===null)
return <LoadingOverlay></LoadingOverlay>
if(firstLaunch===false)
{
return (<>
<StatusBar style="light"></StatusBar>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name='Home' options={{
headerShown:false
}} component={HomePage} ></Stack.Screen>
</Stack.Navigator>
</NavigationContainer>
</>)
}
return (
<>
<StatusBar style="light"></StatusBar>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name='Landing' options={{
headerShown:false
}} component={LandingPage} ></Stack.Screen>
<Stack.Screen name='Home' options={{
headerShown:false
}} component={HomePage} ></Stack.Screen>
</Stack.Navigator>
</NavigationContainer>
</>
);
}