-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathApp.tsx
executable file
·126 lines (111 loc) · 3.48 KB
/
App.tsx
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
/**
* Scaler School of Technology Application
* @format
*/
import mobileAds, {
BannerAd,
BannerAdSize,
MaxAdContentRating,
} from 'react-native-google-mobile-ads';
import React, {useEffect, useState, useRef} from 'react'; // importing react module
import {PermissionsAndroid, Text} from 'react-native';
import FlashMessage from 'react-native-flash-message'; // module to flash messages on device screen
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import DidContext from './src/contexts/DidContext';
import UserContext from './src/contexts/UserContext';
import DeviceInfo from 'react-native-device-info';
import SignInScreen from './src/screens/SignInScreen';
const HomeScreen = React.lazy(() => import('./src/screens/CurrentClassScreen'));
import {
requestUserPermission,
NotificationListener,
} from './src/utils/pushnotification_helper';
import SplashScreen from 'react-native-splash-screen';
const Stack = createNativeStackNavigator();
mobileAds()
.initialize()
.then(() => {});
export default function App(): JSX.Element {
const [did, setdid] = useState('');
const [userInfo, setUserInfo] = useState({});
const navigationRef = useRef(null);
useEffect(() => {
DeviceInfo.getUniqueId().then(uniqueId => {
setdid(uniqueId);
});
}, []);
useEffect(() => {
mobileAds()
.setRequestConfiguration({
maxAdContentRating: MaxAdContentRating.G,
tagForChildDirectedTreatment: true,
tagForUnderAgeOfConsent: true,
})
.then(() => {
// setAdError(null);
})
.catch(() => {
// setAdError('Problem configuring add');
});
}, []);
useEffect(() => {
try {
PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
{
title: 'Allow Scaler School of Technology to send you notifications',
message: 'Notification access required.',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
},
);
// if (granted === PermissionsAndroid.RESULTS.GRANTED) {
// } else {
// }
} catch (err) {}
requestUserPermission();
NotificationListener();
}, []);
useEffect(() => {
SplashScreen.hide();
}, []);
function onSuccessRegister(initResponse) {
setUserInfo({
userName: initResponse.name,
userEmail: initResponse.mail,
});
navigationRef.current.navigate('CurrentClassScreen');
}
return (
<DidContext.Provider value={did}>
<UserContext.Provider
value={{...userInfo, onSuccessRegister: onSuccessRegister}}>
<NavigationContainer ref={navigationRef}>
<Stack.Navigator initialRouteName="Home">
<Stack.Screen
name="Home"
component={SignInScreen}
options={{
headerShown: false,
}}
/>
<Stack.Screen
name="CurrentClassScreen"
component={HomeScreen}
options={{headerShown: false}}
/>
</Stack.Navigator>
<FlashMessage position="bottom" style={{marginBottom: '5%'}} />
</NavigationContainer>
<BannerAd
size={BannerAdSize.BANNER}
unitId="ca-app-pub-5607953789101029/2705802773"
onAdLoaded={() => {}}
onAdFailedToLoad={() => {}}
/>
</UserContext.Provider>
</DidContext.Provider>
);
}