-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSplashScreen.js
118 lines (111 loc) · 3.57 KB
/
SplashScreen.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
import React, { Component } from 'react';
import {
AsyncStorage,
Image,
Platform,
ScrollView,
StyleSheet,
Text,
TouchableOpacity,
Dimensions,
View,
BackHandler
} from 'react-native';
import {
StackNavigator,
} from 'react-navigation';
import * as firebase from 'firebase';
import {LoginPage} from './login.js';
import {fbapp} from './login.js';
import LocationServicesDialogBox from "react-native-android-location-services-dialog-box";
var HomeScreen = require('./home.js');
const FBSDK = require('react-native-fbsdk');
const {
AccessToken,
GraphRequest,
} = FBSDK;
export default class SplashScreen extends React.Component {
constructor(props) {
super(props);
this.state = {isLoggedIn: false}
}
static navigationOptions = {
header: null,
};
componentDidMount() {
console.log(this.state.isLoggedIn);
LocationServicesDialogBox.checkLocationServicesIsEnabled({
message: "<h2>Use Location?</a>",
ok: "YES",
cancel: "NO",
enableHighAccuracy: true, // true => GPS AND NETWORK PROVIDER, false => ONLY GPS PROVIDER
showDialog: true, // false => Opens the Location access page directly
openLocationServices: true // false => Directly catch method is called if location services are turned off
}).then(function(success) {
// success => {alreadyEnabled: true, enabled: true, status: "enabled"}
navigator.geolocation.getCurrentPosition((position) => {
let initialPosition = JSON.stringify(position);
this.setState({ initialPosition });
}, error => console.log(error), { enableHighAccuracy: false, timeout: 20000, maximumAge: 1000 });
}.bind(this)
).catch((error) => {
console.log(error.message);
});
BackHandler.addEventListener('hardwareBackPress', () => {
LocationServicesDialogBox.forceCloseDialog();
});
}
componentWillUnmount() {
}
render() {
const { navigate } = this.props.navigation;
firebase.auth().onAuthStateChanged( function(user) {
if (user) {
AccessToken.getCurrentAccessToken().then((data) => {
if (data == null){
navigate('Login');
}
const { accessToken } = data;
fetch('https://graph.facebook.com/v2.5/me?fields=email,name,friends&access_token=' + accessToken)
.then((response) => response.json())
.then((json) => {
var testPath = "/user/" + json.id + "/details/" + "/setup";
firebase.database().ref(testPath).on("value", (snap) => {
console.log('yuhhhhhhh');
console.log(snap.val());
if (snap.val()==true){
navigate("HomeScreen");
}
else{
navigate('Login');
}
});
} )
});
} else {
navigate('Login');
}});
return (
<View style={styles.container}>
<Image style = {styles.splashPhoto}
source={require('./dingotransparent.png')}
/>
</View> );
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
backgroundColor: '#191979',
},
splashPhoto: {
position: 'absolute',
width: 68,
height: 101,
alignItems: 'center',
justifyContent: 'center',
marginTop: 250,
}
});
module.exports = SplashScreen;