forked from smfriady/mobile-attend.co
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
86 lines (79 loc) · 2.51 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
import { Provider } from "react-redux";
import store from "./src/store";
import { NavigationContainer } from "@react-navigation/native";
import MainNavigation from "./src/navigations/MainNavigation";
import { LogBox } from "react-native";
import * as TaskManager from "expo-task-manager";
import * as Location from "expo-location";
import { useEffect } from "react";
import { ToastProvider } from "react-native-toast-notifications";
export default function App() {
LogBox.ignoreLogs([
"Warning: Failed prop type: Invalid prop `textStyle` of type `array` supplied to `Cell`, expected `object`.",
]);
const locationPermission = async () => {
const { status: foregroundStatus } =
await Location.requestForegroundPermissionsAsync();
if (foregroundStatus === "granted") {
const { status: backgroundStatus } =
await Location.requestBackgroundPermissionsAsync();
if (backgroundStatus === "granted") {
await Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, {
accuracy: Location.Accuracy.Balanced,
});
} else {
// setErrorMsg("Permission to access Background location was denied");
}
} else {
// setErrorMsg("Permission to access Foreground location was denied");
}
};
useEffect(() => {
locationPermission();
}, []);
let region = {
identifier: 1,
latitude: 51.5572754,
longitude: -0.2702119,
radius: 10,
};
Location.startGeofencingAsync("LOCATION_GEOFENCE", [region]);
TaskManager.defineTask(
"LOCATION_GEOFENCE",
({ data: { eventType, region }, error }) => {
if (error) {
// check `error.message` for more details.
return;
}
if (eventType === Location.GeofencingEventType.Enter) {
alert("enter in region!");
console.log("You've entered region:", region);
} else if (eventType === Location.GeofencingEventType.Exit) {
console.log("You've left region:", region);
}
}
);
return (
<Provider store={store}>
<ToastProvider
placement="bottom"
duration={3000}
animationType="slide-in | zoom-in"
animationDuration={250}
successColor="green"
dangerColor="red"
warningColor="orange"
normalColor="gray"
textStyle={{ fontSize: 20 }}
offset={50}
offsetTop={30}
offsetBottom={40}
swipeEnabled={true}
>
<NavigationContainer>
<MainNavigation />
</NavigationContainer>
</ToastProvider>
</Provider>
);
}