-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
184 lines (166 loc) · 5.24 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
"use strict";
import React, { useState, useRef } from "react";
import { AuthProvider } from "redvest/contexts/AuthContext";
import { AssetsProvider } from "redvest/contexts/AssetsContext";
import { OrdersProvider } from "redvest/contexts/OrdersContext";
import { PositionsProvider } from "redvest/contexts/PositionsContext";
import { DataProvider } from "redvest/contexts/DataContext";
import { AlpacaAccountInfoProvider } from "redvest/contexts/AlpacaAccountInfoContext";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { colors } from "redvest/util/styles";
import { LogBox, StatusBar } from "react-native";
import * as SplashScreen from "expo-splash-screen";
import NavigationContainer from "redvest/navigators/NavigationContainer";
import {
useFonts,
Poppins_400Regular,
Poppins_500Medium,
Poppins_600SemiBold,
Poppins_700Bold,
} from "@expo-google-fonts/poppins";
import firebase from "firebase";
import {
API_KEY,
AUTH_DOMAIN,
DATABASE_URL,
PROJECT_ID,
STORAGE_BUCKET,
MESSAGING_SENDER_ID,
APP_ID,
MEASUREMENT_ID,
} from "@env";
import Constants from "expo-constants";
import * as Notifications from "expo-notifications";
const FIREBASE_CONFIG = {
apiKey: API_KEY,
authDomain: AUTH_DOMAIN,
databaseURL: DATABASE_URL,
projectId: PROJECT_ID,
storageBucket: STORAGE_BUCKET,
messagingSenderId: MESSAGING_SENDER_ID,
appId: APP_ID,
measurementId: MEASUREMENT_ID,
};
!firebase.apps.length
? firebase.initializeApp(FIREBASE_CONFIG)
: firebase.app();
SplashScreen.preventAutoHideAsync().catch(() =>
LogBox.ignoreLogs([
"Unhandled promise rejection: Error: Native splash screen is already hidden.",
])
);
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: false,
shouldSetBadge: false,
}),
});
function App() {
// useEffect(() => {
// registerForPushNotificationsAsync().then((token) =>
// setExpoPushToken(token)
// );
// // This listener is fired whenever a notification is received while the app is foregrounded
// notificationListener.current = Notifications.addNotificationReceivedListener(
// (notification) => {
// setNotification(notification);
// }
// );
// // This listener is fired whenever a user taps on or interacts with a notification (works when app is foregrounded, backgrounded, or killed)
// responseListener.current = Notifications.addNotificationResponseReceivedListener(
// (response) => {
// console.log(response);
// }
// );
// return () => {
// Notifications.removeNotificationSubscription(
// notificationListener.current
// );
// Notifications.removeNotificationSubscription(responseListener.current);
// };
// }, []);
async function sendPushNotification(expoPushToken) {
const message = {
to: expoPushToken,
sound: "default",
title: "Original Title",
body: "And here is the body!",
data: { someData: "goes here" },
};
await fetch("https://exp.host/--/api/v2/push/send", {
method: "POST",
headers: {
Accept: "application/json",
"Accept-encoding": "gzip, deflate",
"Content-Type": "application/json",
},
body: JSON.stringify(message),
});
}
async function registerForPushNotificationsAsync() {
let token;
if (Constants.isDevice) {
const {
status: existingStatus,
} = await Notifications.getPermissionsAsync();
let finalStatus = existingStatus;
if (existingStatus !== "granted") {
const { status } = await Notifications.requestPermissionsAsync();
finalStatus = status;
}
if (finalStatus !== "granted") {
alert("Failed to get push token for push notification!");
return;
}
token = (await Notifications.getExpoPushTokenAsync()).data;
console.log(token);
} else {
alert("Must use physical device for Push Notifications");
}
if (Platform.OS === "android") {
Notifications.setNotificationChannelAsync("default", {
name: "default",
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: "#FF231F7C",
});
}
return token;
}
const [fontsLoaded] = useFonts({
Poppins_400Regular,
Poppins_500Medium,
Poppins_600SemiBold,
Poppins_700Bold,
});
const [expoPushToken, setExpoPushToken] = useState("");
const [notification, setNotification] = useState(false);
const notificationListener = useRef();
const responseListener = useRef();
if (!fontsLoaded) {
return null;
}
return (
<AuthProvider>
<AssetsProvider>
<DataProvider>
<AlpacaAccountInfoProvider>
<PositionsProvider>
<OrdersProvider>
<SafeAreaProvider>
<StatusBar
barStyle={"light-content"}
backgroundColor={colors.darkBackground}
/>
<NavigationContainer />
</SafeAreaProvider>
</OrdersProvider>
</PositionsProvider>
</AlpacaAccountInfoProvider>
</DataProvider>
</AssetsProvider>
</AuthProvider>
);
}
export default App;