-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
executable file
·174 lines (159 loc) · 5.38 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
import React from 'react';
import * as firebase from 'firebase';
import * as Font from 'expo-font';
import { SafeAreaView, Text, AsyncStorage } from 'react-native';
import { createAppContainer } from 'react-navigation';
import { Notifications } from 'expo';
import * as Permissions from 'expo-permissions';
import * as Constants from 'expo-constants';
import * as BackgroundFetch from "expo-background-fetch";
import * as TaskManager from "expo-task-manager";
import { createStackNavigator } from 'react-navigation-stack';
import Buildings from './views/Buildings/view';
import Welcome from './views/Welcome/view';
import Login from './views/Login/view';
import DayNight from './views/DayNight/view';
import Subscription from './views/Subscription/view';
import SetMonday from './views/SetMonday/view';
import SetTuesday from './views/SetTuesday/view';
import FinalSetup from './views/FinalSetup/view';
import Home from './views/Home/view';
import Schedule from './views/Schedule/view';
import Settings from './views/Settings/view';
import Articles from './views/Articles/view';
import TabBarNavigator from './views/TabBarNavigator/view';
import Transitions from './assets/Transitions';
import Data from './Data';
const firebaseConfig = {
apiKey: "AIzaSyCkMVXbgG-8l_vPXo5EoHDw3lB2HXKm4Y4",
authDomain: "uts-portal-293.firebaseapp.com",
databaseURL: "https://uts-portal-293.firebaseio.com",
projectId: "uts-portal-293",
storageBucket: "uts-portal-293.appspot.com",
messagingSenderId: "367766824243",
};
firebase.initializeApp(firebaseConfig);
//background fetch
BackgroundFetch.setMinimumIntervalAsync(1);
const taskname = "updateDataNotif";
TaskManager.defineTask(taskname, async () => {
await Data.updateAll();
await Data.scheduleNotifications();
console.warn("fetch successful");
return BackgroundFetch.Result.NewData;
});
const handleTransitions = ({scenes}) => {
const next = scenes[scenes.length - 1].route.routeName;
switch(next)
{
case 'Welcome': return Transitions.fadeIn(1000);
case 'Login': return Transitions.fadeOut(1000);
case 'DayNight': return Transitions.fromRight(300);
case 'Subscriptions': return Transitions.fromRight(500);
case 'SetMonday': return Transitions.fromRight(500);
case 'SetTuesday': return Transitions.fromRight(500);
case 'FinalSetup': return Transitions.fromRight(500);
case 'Home': return Transitions.fadeIn(200);
default: return Transitions.fadeIn(300);
}
}
const gNavigator = createStackNavigator({
Buildings,
Welcome,
Login,
DayNight,
Subscription,
SetMonday,
SetTuesday,
FinalSetup,
TabBarNavigator,
},
{
initialRouteName: 'Buildings',
headerMode: 'none',
navigationOptions: {
gesturesEnabled: false,
swipeEnabled: false,
},
transitionConfig: (nav) => handleTransitions(nav)
});
const GlobalContainer = createAppContainer(gNavigator);
class App extends React.Component
{
constructor()
{
super();
this.state = {
firstTime: null,
notification: {}
}
}
async registerBackgroundTask ()
{
await BackgroundFetch.registerTaskAsync(taskname);
}
//copy pasted
async registerForPushNotificationsAsync ()
{
// let result = await Permissions.askAsync(Permissions.NOTIFICATIONS);
// if (Constants.isDevice && result.status === 'granted') {
// console.log('Notification permissions granted.')
// }
if (Constants.isDevice)
{
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);
let finalStatus = existingStatus;
if (existingStatus !== 'granted')
{
const { status } = await Permissions.askAsync(
Permissions.NOTIFICATIONS
);
finalStatus = status;
}
if (finalStatus !== 'granted')
{
alert('Failed to get push token for push notification!');
return;
}
let token = await Notifications.getExpoPushTokenAsync();
console.log(token);
}
else
{
alert('Must use physical device for Push Notifications');
}
Notifications.addListener (this.handleNotifications);
Data.scheduleNotifications();
};
handleNotifications ()
{
console.warn ("notification received");
}
async componentDidMount()
{
Promise.all([
Data.setDefaults(),
this.registerBackgroundTask(),
Data.updateAll(),
this.registerForPushNotificationsAsync(),
Font.loadAsync({
'gilroy': require('./assets/fonts/gilroy.ttf'),
'gilroy-bold': require('./assets/fonts/gilroy-bold.ttf'),
'montserrat': require('./assets/fonts/Montserrat.ttf'),
'montserrat-bold': require('./assets/fonts/Montserrat-Bold.ttf')
})
]).then(() => this.setState({firstTime: true}))
//Notifications
}
render()
{
if (this.state.firstTime == null)
return (<Text>{null}</Text>);
return (
<GlobalContainer/>
);
}
}
export default App;