-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
135 lines (121 loc) · 4.79 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
import React from 'react';
import {View, SafeAreaView, Platform, Text} from 'react-native';
import MasterView from './MasterView.js';
import * as firebase from 'firebase';
import 'firebase/firestore';
import styles from './styles.js';
import { GeoFirestore} from 'geofirestore';
import * as Location from 'expo-location';
import ErrorPage from './ErrorPage'
import {AdMobInterstitial} from 'expo-ads-admob';
import PrivacyPolicyButton from './PrivacyPolicyButton.js';
import { YellowBox } from 'react-native';
import { SplashScreen } from 'expo';
import CheckIfFirstLaunch from './CheckIfFirstLaunch';
import { AsyncStorage } from 'react-native';
import * as FacebookAds from 'expo-ads-facebook';
// FacebookAds.AdSettings.addTestDevice(FacebookAds.AdSettings.currentDeviceHash);
// Initialize Firebase
global.firebaseConfig = {
apiKey: "AIzaSyD2YhfO1TBYNOAWSxGwXQocAikqLuCRl7Q",
authDomain: "testing-617da.firebaseapp.com",
databaseURL: "https://testing-617da.firebaseio.com",
projectId: "testing-617da",
storageBucket: "testing-617da.appspot.com",
//messagingSenderId: "862420802331"
};
global.apiKey = /*Platform.OS === 'ios'? */'AIzaSyD2YhfO1TBYNOAWSxGwXQocAikqLuCRl7Q'/* : 'AIzaSyD9M9o4soakpTJXdLojSWEst6VL3ppGKi8'*/;
// set API key for location
Location.setApiKey(apiKey)
firebase.initializeApp(firebaseConfig);
global.db = firebase.firestore();
const geofirestore = new GeoFirestore(db);
global.hubs = geofirestore.collection('hubs')
console.ignoredYellowBox = ['Setting a timer'];
export default class App extends React.Component {
constructor(props) {
YellowBox.ignoreWarnings(['Setting a timer']);
super(props);
this.state = {
isFirstLaunch: false,
hasCheckedAsyncStorage: false,
pageErrorState: false,
pageErrorMessage: "Oops! We can't seem to reach our servers. Please check your connection and try again.",
tabState:false,
};
this.pageErrorHandler = this.pageErrorHandler.bind(this);
this.componentDidMount = this.componentDidMount.bind(this);
this.componentWillUnmount = this.componentWillUnmount.bind(this);
this.tabOpenHandler = this.tabOpenHandler.bind(this);
this.showInterstitialAd = this.showInterstitialAd.bind(this);
}
showInterstitialAd = async() => {
await AdMobInterstitial.requestAdAsync()
await AdMobInterstitial.showAdAsync()
}
async componentDidMount() {
SplashScreen.preventAutoHide();
const isFirstLaunch = await CheckIfFirstLaunch();
this.setState({isFirstLaunch,hasCheckedAsyncStorage: true});
AdMobInterstitial.setAdUnitID(Platform.OS === 'ios' ? 'ca-app-pub-9088719879244214/4527962867' : 'ca-app-pub-9088719879244214/6250276442');
// AdMobInterstitial.setTestDeviceID('EMULATOR');
AdMobInterstitial.addEventListener("interstitialDidLoad", ()=> console.log("interstitialDidLoad"));
AdMobInterstitial.addEventListener("interstitialDidFailToLoad", (error)=> {
console.log(error)
setTimeout(() => {
SplashScreen.hide();
}, 500);
});
AdMobInterstitial.addEventListener("interstitialDidOpen", ()=> console.log("interstitialDidOpen"));
AdMobInterstitial.addEventListener("interstitialDidClose", ()=> {
SplashScreen.hide();
console.log("interstitialDidClose");
});
AdMobInterstitial.addEventListener("interstitialWillLeaveApplication", ()=> console.log("interstitialWillLeaveApplication"));
if (!isFirstLaunch) {
this.showInterstitialAd();
// AsyncStorage.removeItem('hasLaunched', console.log("removed"));
} else {
SplashScreen.hide();
}
}
componentWillUnmount() {
AdMobInterstitial.removeAllListeners();
}
pageErrorHandler(someValue) {
this.setState({
pageErrorState: someValue.state
});
this.setState({
pageErrorMessage: someValue.message
});
}
tabOpenHandler(someValue) {
this.setState({
tabState: someValue
});
}
// renders the onscreen info
render() {
return (
<View style = {styles.bigContainer}>
{this.state.pageErrorState && <ErrorPage
error={this.state.pageErrorMessage}
/>}
{!this.state.pageErrorState && <MasterView
pageErrorHandler={this.pageErrorHandler}
showInterstitialAd={this.showInterstitialAd}
tabOpenHandler={this.tabOpenHandler}
tabState={this.state.tabState}
isFirstLaunch={this.state.isFirstLaunch}
hasCheckedAsyncStorage={this.state.hasCheckedAsyncStorage}
/>}
{!this.state.pageErrorState && !this.state.tabState && <SafeAreaView style={{flex:1,backgroundColor:'transparent',position:'absolute',top:'92%',height:'8%',width:'100%'}}>
<View style= {{height:'100%',width:'100%'}}>
<PrivacyPolicyButton/>
</View>
</SafeAreaView>}
</View>
);
}
}