-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
115 lines (102 loc) · 3.23 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
import React from 'react';
import { Image } from 'react-native';
import { Font, Asset, AppLoading } from 'expo';
import { createDrawerNavigator, createAppContainer } from 'react-navigation';
import * as firebase from 'firebase';
import HomeScreen from './screens/HomeScreen';
import MapView from './screens/Map';
import FFList from './screens/FFList';
import Acknowledgements from './screens/Acknowledgements';
import References from './screens/References';
import CommitteeMessage from './screens/CommitteeMessage';
import Introduction from './screens/Introduction';
import History from './screens/History';
const firebaseConfig = {
apiKey: "AIzaSyBqqlRStr494376E0fE4Fg17LATiUYxNCI",
authDomain: "hci-biodiversity.firebaseapp.com",
databaseURL: "https://hci-biodiversity.firebaseio.com",
storageBucket: "hci-biodiversity.appspot.com"
};
const firebaseApp = firebase.initializeApp(firebaseConfig);
function cacheImages(images) {
return images.map(image => {
if (typeof image === 'string') {
console.log("Attempting prefetch");
return Image.prefetch(image);
} else {
return Asset.fromModule(image).downloadAsync();
}
});
}
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
dataLoaded: false,
data: {},
markers: {}
}
this.datastoreRef = firebaseApp.database().ref();
}
saveMarkers(markers) {
if (Object.keys(markers).length > Object.keys(this.state.markers).length) this.setState({markers})
}
fetchFromFirebase(datastoreRef) {
let data = {}
return datastoreRef.once("value", datastore => {
datastore.forEach(element => {
data[element.key] = element.val();
});
}).then(() => {
this.setState({data})
}).catch(() => {
console.log('Failed to fetch data from firebase')
})
}
async loadData(){
let fontAssets = Font.loadAsync({
'Roboto': require('native-base/Fonts/Roboto.ttf'),
'Roboto_medium': require('native-base/Fonts/Roboto_medium.ttf'),
'Lato': require('./assets/Lato-Regular.ttf'),
'Lato-Italic': require('./assets/Lato-Italic.ttf'),
'Precious': require('./assets/Precious.ttf')
});
let imageAssets = cacheImages([
require('./assets/fauna.jpg'),
require('./assets/flora.jpg'),
require('./assets/homeimage.jpg')
]);
let dataAssets = this.fetchFromFirebase(this.datastoreRef);
return Promise.all([dataAssets, ...imageAssets, fontAssets])
}
render() {
if (!this.state.dataLoaded) {
return (
<AppLoading
startAsync={() => this.loadData()}
onFinish={() => this.setState({ dataLoaded: true })}
onError={console.log}
/>
);
}
return <RootDrawer screenProps={{
data: this.state.data,
markers: this.state.markers,
saveMarkers: m => this.saveMarkers(m),
}} />;
}
}
const RootDrawer = createAppContainer(createDrawerNavigator({
Home: HomeScreen,
Introduction: Introduction,
Map: MapView,
'Flora and Fauna': FFList,
'Historical Photos': History,
'Message from Committee': CommitteeMessage,
Acknowledgements: Acknowledgements,
References: References
},
{
initialRouteName: 'Home',
titleOffset: 50,
}));