-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.js
168 lines (160 loc) · 4.94 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import { StatusBar } from "expo-status-bar";
import React, { useEffect, useState } from "react";
import {
NavigationContainer,
DarkTheme,
DefaultTheme,
} from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import HomeScreen from "./app/screens/HomeScreen";
import Schedule from "./app/screens/Schedule";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import Favourite from "./app/screens/Favourite";
import Setting from "./app/screens/Setting";
import { Icon } from "react-native-elements";
import {
PopularContext,
ScheduleContext,
DarkContext,
} from "./app/context/AnimeContext";
import axios from "axios";
import Search from "./app/screens/Search";
import Details from "./app/screens/Details";
import Episode from "./app/screens/Episode";
import * as Updates from "expo-updates";
import { Alert } from "react-native";
export default function App() {
const Tab = createBottomTabNavigator();
const Stack = createNativeStackNavigator();
const [popular, setPopular] = useState([]);
const [schedule, setSchedule] = useState({});
const [darkMode, setDarkMode] = useState(true);
const Theme = darkMode ? DarkTheme : DefaultTheme;
const getPopular = () => {
axios
.get("https://animeworldz.herokuapp.com/api/v1/anime/popular/1")
.then((res) => {
setPopular(res.data);
})
.catch((err) => console.log(err));
};
const getSchedule = () => {
axios
.post("https://animeworldz.herokuapp.com/api/v1/schedule", { day: "" })
.then((res) => {
setSchedule(res.data);
})
.catch((err) => console.log(err));
};
const fetchUpdates = async () => {
try {
const update = await Updates.checkForUpdateAsync();
if (update.isAvailable) {
await Updates.fetchUpdateAsync();
Alert.alert("Update Available! Restarting");
setTimeout(async () => {
await Updates.reloadAsync();
}, 2000);
}
} catch (e) {
console.log(e);
}
};
useEffect(() => {
getPopular();
getSchedule();
fetchUpdates();
}, []);
return (
<DarkContext.Provider value={{ darkMode, setDarkMode }}>
<PopularContext.Provider value={{ popular }}>
<ScheduleContext.Provider value={{ schedule }}>
<NavigationContainer theme={Theme}>
<Stack.Navigator>
<Stack.Screen name="Home" options={{ headerShown: false }}>
{(props) => <Home {...props} Tab={Tab} darkMode={darkMode} />}
</Stack.Screen>
<Stack.Screen
name="Details"
component={Details}
options={({ route }) => ({ title: route.params.title })}
/>
<Stack.Screen
name="Episode"
component={Episode}
options={({ route }) => ({ title: route.params.title })}
/>
</Stack.Navigator>
<StatusBar style={darkMode ? "light" : "dark"} />
</NavigationContainer>
</ScheduleContext.Provider>
</PopularContext.Provider>
</DarkContext.Provider>
);
}
function Home({ Tab, darkMode }) {
return (
<Tab.Navigator>
<Tab.Screen
name="HomScreen"
component={HomeScreen}
options={{
title: "ANIMEWORLD-Z",
tabBarLabel: "Home",
tabBarIcon: ({ color }) => (
<Icon color={color} type="octicon" name="home" />
),
tabBarActiveTintColor: darkMode ? "#fff" : "#000",
}}
/>
<Tab.Screen
name="Search"
component={Search}
options={{
title: "ANIMEWORLD-Z",
tabBarLabel: "Search",
tabBarIcon: ({ color }) => (
<Icon color={color} type="material" name="search" />
),
tabBarActiveTintColor: darkMode ? "#fff" : "#000",
}}
/>
<Tab.Screen
name="Favourite"
component={Favourite}
options={{
title: "ANIMEWORLD-Z",
tabBarLabel: "Favourite",
tabBarIcon: ({ color }) => (
<Icon color={color} type="octicon" name="heart" />
),
tabBarActiveTintColor: darkMode ? "#fff" : "#000",
}}
/>
<Tab.Screen
name="Schedule"
component={Schedule}
options={{
title: "ANIMEWORLD-Z",
tabBarLabel: "Schedule",
tabBarIcon: ({ color }) => (
<Icon color={color} type="material" name="schedule" />
),
tabBarActiveTintColor: darkMode ? "#fff" : "#000",
}}
/>
<Tab.Screen
name="Setting"
component={Setting}
options={{
title: "ANIMEWORLD-Z",
tabBarLabel: "Settings",
tabBarIcon: ({ color }) => (
<Icon color={color} type="material" name="settings" />
),
tabBarActiveTintColor: darkMode ? "#fff" : "#000",
}}
/>
</Tab.Navigator>
);
}