forked from aKn1ghtOut/Breeze.ReactNative
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
185 lines (165 loc) · 5.61 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
import { AppLoading, Notifications } from "expo";
import * as Permissions from 'expo-permissions';
import { Asset } from "expo-asset";
import * as Font from "expo-font";
import React, { useState, Component } from "react";
import {
Platform,
StatusBar,
StyleSheet,
View,
ImageBackground,
Image,
AsyncStorage
} from "react-native";
import { Ionicons, AntDesign } from "@expo/vector-icons";
import AppNavigator from "./navigation/AppNavigator";
import { Provider, connect } from "react-redux";
import store from "./redux/store";
class ImageBG extends Component {
constructor(props) {
super(props);
this.BGRef = React.createRef();
}
backgroundImages = {
home_bg: require("./assets/images/backgrounds/home_bg.png"),
cultural_bg: require("./assets/images/backgrounds/cultural_bg.png"),
sports_bg: require("./assets/images/backgrounds/sports_bg.png"),
technical_bg: require("./assets/images/backgrounds/technical_bg.png"),
cultural_categories: require("./assets/images/backgrounds/cultural_categories.png")
};
componentDidMount()
{
this.registerDevice();
}
async registerDevice()
{
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
if (status !== 'granted') {
// console.log('No notification permissions!');
return;
}
let token = await Notifications.getExpoPushTokenAsync();
try {
const value = await AsyncStorage.getItem('registered');
// console.log(`Value : ${value}`);
if (value !== null)
return; //Already registered
const formData = new FormData();
formData.append("entry.1354444817", token);
var res = await fetch(
"https://docs.google.com/forms/d/e/1FAIpQLSdoidrJK7AD6GN-yIKzMtv2sVVBvalijAiaS06woJbA1qINQQ/formResponse",
{
method: "POST",
body: formData
}
);
var resp = res.body;
// console.log(resp);
await AsyncStorage.setItem('registered', 'done.');
} catch (error) {
// console.log(error);
}
}
render() {
return (
<ImageBackground
style={styles.container}
source={
this.props.background
? this.backgroundImages[this.props.background]
: require("./assets/images/backgrounds/home_bg.png")
}
ref={this.BGRef}
>
<View style={styles.container}>
{Platform.OS === "ios" && <StatusBar barStyle="default" />}
<AppNavigator />
</View>
</ImageBackground>
);
}
}
const MapStateToProps = state => ({
background: state.UI.background
});
ImageBGComp = connect(MapStateToProps, null)(ImageBG);
export default function App(props) {
const [isLoadingComplete, setLoadingComplete] = useState(false);
if (!isLoadingComplete && !props.skipLoadingScreen) {
return (
<AppLoading
startAsync={loadResourcesAsync}
onError={handleLoadingError}
onFinish={() => handleFinishLoading(setLoadingComplete)}
/>
);
} else {
return (
<Provider store={store}>
<ImageBGComp />
</Provider>
);
}
}
async function loadResourcesAsync() {
await Promise.all([
Asset.loadAsync([
require("./assets/images/Logo.png"),
require("./assets/images/backgrounds/home_bg.png"),
require("./assets/images/backgrounds/cultural_bg.png"),
require("./assets/images/backgrounds/cultural_categories.png"),
require("./assets/images/backgrounds/sports_bg.png"),
require("./assets/images/backgrounds/technical_bg.png"),
require("./assets/images/events_bg/cultural.png"),
require("./assets/images/events_bg/technical.png"),
require("./assets/images/events_bg/sports_mob.png"),
require("./assets/sponsors/townscript.png"),
require("./assets/sponsors/duassassins.png"),
require("./assets/sponsors/duexpress.png"),
require("./assets/sponsors/dubeat.jpg"),
require("./assets/sponsors/ed.png"),
require("./assets/sponsors/ATKT.png"),
require("./assets/sponsors/social-rush.jpg"),
require("./assets/sponsors/fiesto_nobg.png"),
require("./assets/sponsors/duvibes.jpg"),
require("./assets/sponsors/education-tree.png"),
require("./assets/sponsors/noidadiary.png"),
require("./assets/sponsors/newsaurchai.png"),
require("./assets/sponsors/insider.png"),
require("./assets/sponsors/GrabOn.png"),
require("./assets/sponsors/bme.jpg"),
require("./assets/sponsors/rani.jpg"),
require("./assets/sponsors/Cornitos.png"),
require("./assets/sponsors/brewhouse.png"),
require("./assets/sponsors/longshot-2.jpg"),
require("./assets/pronights/Moctave.png"),
require("./assets/pronights/RahulSubramanium.png"),
require("./assets/pronights/Nalayak.png"),
require("./assets/pronights/NikhilDsouza.jpeg"),
require("./assets/pronights/ProgBrothers.png")
]),
Font.loadAsync({
// This is the font that we are using for our tab bar
...Ionicons.font,
// We include SpaceMono because we use it in HomeScreen.js. Feel free to
// remove this if you are not using it in your app
"space-mono": require("./assets/fonts/SpaceMono-Regular.ttf"),
"just-fist": require("./assets/fonts/PatuaOne-Regular.ttf"),
"axiforma-bold": require("./assets/fonts/Axiforma_Bold.otf")
})
]);
}
function handleLoadingError(error) {
// In this case, you might want to report the error to your error reporting
// service, for example Sentry
console.warn(error);
}
function handleFinishLoading(setLoadingComplete) {
setLoadingComplete(true);
}
const styles = StyleSheet.create({
container: {
flex: 1
}
});