-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
69 lines (62 loc) · 2.14 KB
/
App.tsx
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
import { Lato_400Regular, useFonts } from "@expo-google-fonts/lato";
import Constants from "expo-constants";
import "expo-dev-client";
import { StatusBar } from "expo-status-bar";
import React from "react";
import { SafeAreaProvider } from "react-native-safe-area-context";
import useCachedResources from "./src/hooks/useCachedResources";
import useColorScheme from "./src/hooks/useColorScheme";
import Navigation from "./src/navigation";
import LocationService from "./src/services/LocationService";
import { NotificationService } from "./src/services/NotificationService";
import Store from "./src/services/Store";
import {
setUpBackgroundTasks,
startBackgroundTasks,
stopBackgroundTasks,
} from "./src/services/background";
export default function App(): JSX.Element | null {
const isLoadingComplete = useCachedResources();
const colorScheme = useColorScheme();
const [areFontsLoaded] = useFonts({
Lato_400Regular,
});
Store.initializeStorage();
// LocationService.setEnabled(false);
if (!Constants.platform) return null;
if (Constants.platform.web) {
LocationService.requestPermission().then((granted) => {
if (granted) LocationService.getLocationAsync();
});
// Notifications and background tasks not supported in web
} else if (Constants.platform.android || Constants.platform.ios) {
// Wait for permissions before setting up background tasks
Promise.all([
LocationService.requestPermission().then((granted) => {
if (granted) LocationService.getLocationAsync();
return granted;
}),
NotificationService.requestPermission(),
]).then((values) => {
if (values.every(Boolean)) {
// if has all permissions
setUpBackgroundTasks().then(() => {
Store.retrieveProfile().then((profile) => {
if (profile?.alert.enabled) startBackgroundTasks();
else stopBackgroundTasks();
});
});
}
});
}
if (!isLoadingComplete || !areFontsLoaded) {
return null;
} else {
return (
<SafeAreaProvider>
<Navigation colorScheme={colorScheme} />
<StatusBar />
</SafeAreaProvider>
);
}
}