This repository has been archived by the owner on Apr 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
197 lines (151 loc) · 5.05 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
185
186
187
188
189
190
191
192
193
194
195
196
import React from 'react';
import { View, Text, AsyncStorage } from 'react-native'
import { Notifications, ScreenOrientation, AppLoading } from 'expo'
import { createStackNavigator, createAppContainer, StackActions } from 'react-navigation'
import { useScreens } from 'react-native-screens'
import Constants from 'expo-constants'
import * as Permissions from 'expo-permissions'
import { Asset } from 'expo-asset'
import * as Font from 'expo-font';
import { firebaseApp } from './firebase-config'
import HomeScreen from './screens/HomeScreen';
import AboutScreen from './screens/AboutScreen';
import HighlightsTourPreview from './screens/HighlightsTourPreview';
import TourNavigationScreen from './screens/TourNavigationScreen';
import ShowOnMapScreen from './screens/ShowOnMapScreen';
import TourStopScreen from './screens/TourStopScreen';
import ExitScreen from './screens/ExitScreen';
import ImageGalleryScreen from './screens/ImageGalleryScreen'
import TodayAtUMMNHScreen from './screens/TodayAtUMMNHScreen'
import EndOfTourScreen from './screens/EndOfTourScreen'
const YOUR_PUSH_TOKEN = '';
useScreens()
changeScreenOrientation()
cacheFonts = (fonts) => {
console.log('trying to load fonts...')
return fonts.map(font => Font.loadAsync(font))
}
cacheImages = (images) => {
return images.map(image => {
return Asset.fromModule(image).downloadAsync()
})
}
export default class App extends React.Component {
state = {
notification: {},
isReady: false,
}
constructor(props){
super(props)
if(Text.defaultProps == null){
Text.defaultProps = {}
}
Text.defaultProps.allowFontScaling = false;
}
componentDidMount(){
this.registerForPushNotificationsAsync()
this.checkForFirstLaunch()
}
checkForFirstLaunch = async () => {
AsyncStorage.getItem("hasLaunched").then(value => {
if(value == null){
AsyncStorage.setItem("hasLaunched", "true")
let targetDB = firebaseApp.database().ref('analytics/')
let incrementValue = targetDB.once('value').then(function(snapshot){
//Get current count
let currentValue = snapshot.val()['first-launch']
console.log(currentValue, typeof currentValue)
//Increment by one
let newValue = currentValue += 1
console.log(newValue)
//Set as new DB value
targetDB.update({
['first-launch']: newValue
})
})
} else {
console.log('not first launch')
}
})
}
registerForPushNotificationsAsync = async () => {
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'){
console.log('access not granted for push notifs')
}
let token = await Notifications.getExpoPushTokenAsync()
let deviceID = Constants.installationId
let targetDB = firebaseApp.database().ref('pushTokens/' + deviceID)
console.log('device id:', deviceID)
console.log('expo push token:', token)
targetDB.set({
pushToken: token
})
} else {
//alert('Must use physical device for Push Notifications')
}
}
render(){
if(!this.state.isReady){
return (
<AppLoading
startAsync = { this._loadAssetsAsync }
onFinish = { () => this.setState({ isReady: true })}
onError = { console.warn }
/>
)
}
return (
<AppContainer />
);
}
_loadAssetsAsync = async () => {
const fontAssets = cacheFonts([
{ 'whitney-black' : require ('./assets/fonts/Whitney-Black.otf') },
{ 'whitney-medium' : require ('./assets/fonts/Whitney-Medium.otf') },
{ 'whitney-semibold' : require ('./assets/fonts/Whitney-Semibold.otf') },
{ 'whitney-medium-italic': require ('./assets/fonts/Whitney-MediumItal.otf') },
{ 'whitney-black-italic': require('./assets/fonts/Whitney-BlackItal.otf') },
])
const imageAssets = cacheImages([
require('./assets/img/home_message.png'),
require('./assets/img/home_background.png'),
require('./assets/img/HeroImage_Doli.png'),
//Hero Images
//Gallery Images
//Navigation Images
])
await Promise.all([...fontAssets, ...imageAssets])
}
}
const RootStack = createStackNavigator(
{
Home: HomeScreen,
About: AboutScreen,
Tours: HighlightsTourPreview,
Navigation: TourNavigationScreen,
ShowOnMap: ShowOnMapScreen,
TourStop: TourStopScreen,
Exit: ExitScreen,
ImageGallery: ImageGalleryScreen,
TodayAtUMMNH: TodayAtUMMNHScreen,
EndOfTour: EndOfTourScreen,
},
{
initialRouteName: 'Home'
}
);
const AppContainer = createAppContainer(RootStack)
async function changeScreenOrientation(){
await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT_UP)
}