-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
138 lines (116 loc) · 4.31 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
127
128
129
130
131
132
133
134
135
136
137
138
import { AppState, StyleSheet, View } from 'react-native';
import tw from 'twrnc';
import * as Notifications from 'expo-notifications';
import React, { useEffect, useRef, useState } from 'react';
import { LinearGradient } from 'expo-linear-gradient';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { NavigationContainer } from '@react-navigation/native';
import MainNavigator from './MainNavigator';
import { Audio } from 'expo-av';
import { Provider } from 'react-redux';
import store from './store/store';
import mobileAds, { BannerAd, BannerAdSize } from 'react-native-google-mobile-ads';
import { useKeepAwake } from 'expo-keep-awake';
import { adUnitId, ONBOARDED_KEY } from './constants/globals';
import AsyncStorage from '@react-native-async-storage/async-storage';
// Sentry.init({
// dsn: "https://[email protected]/6376215",
// enableInExpoDevelopment: true,
// // TODO: Set debug to false in production mode
// debug: true // If `true`, Sentry will try to print out useful debugging information if something goes wrong with sending the event. Set it to `false` in production
// });
// mobileAds().setRequestConfiguration({
// tagForUnderAgeOfConsent: true
// })
mobileAds()
.initialize()
.then(() => {
console.log("initialised mobile ads")
}).catch((err) => {
console.error(err)
})
// MobileAds().openAdInspector()
export default function App() {
const appState = useRef(AppState.currentState)
useKeepAwake()
useEffect(() => {
onboardUser()
setupDefaults()
askForPermissions()
}, [])
const [isFirstTime, setIsFirstTime] = useState(true)
const onboardUser = async () => {
// (await AsyncStorage.getItem(ONBOARDED_KEY))
const userFirstTime = (await AsyncStorage.getItem(ONBOARDED_KEY)) == null
setIsFirstTime(userFirstTime)
}
const askForPermissions = async () => {
const settings = await Notifications.getPermissionsAsync()
// console.log(settings)
if(settings.granted || settings.ios?.status === Notifications.IosAuthorizationStatus.PROVISIONAL) return console.log("Granted")
try{
const status: Notifications.NotificationPermissionsStatus = await Notifications.requestPermissionsAsync({
ios: {
allowAlert: true,
allowBadge: true,
allowSound: true,
allowCriticalAlerts: true
}
})
if(status.granted){
console.log("permissions granted")
} else {
console.log("permissions not granted")
}
} catch (ex) {
console.error("Exception occurred when requesting for permissions", ex);
}
}
// const handleAppStateChange = (nextAppState: any) => {
// if(appState.current.match(/inactive|background/) && nextAppState == "active"){
// console.log("application is now in foreground")
// }
// appState.current = nextAppState
// }
// Sets up notification handler config and audio config
const setupDefaults = async () => {
// Allows notification to show up in foreground
Notifications.setNotificationHandler({
handleNotification: async() => ({
shouldShowAlert: true,
shouldPlaySound: true,
shouldSetBadge: true,
})
})
await Audio.setAudioModeAsync({
// staysActiveInBackground: true,
// interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX, // Means that it interrupts ongoing audio
// interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DUCK_OTHERS,
shouldDuckAndroid: true,
playThroughEarpieceAndroid: false,
allowsRecordingIOS: false, // THIS REDUCES VOLUME OF ALL SOUNDS if SET TO TRUE!!
// interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
// playsInSilentModeIOS: true,
})
}
return (
<Provider store={store}>
<SafeAreaProvider>
<LinearGradient
colors={['rgba(2,0,45,1)', 'rgba(85,1,84,1)']}
style={tw`flex-1 absolute top-0 w-full h-full`}/>
<NavigationContainer>
<MainNavigator isFirstTime={isFirstTime} />
</NavigationContainer>
</SafeAreaProvider>
</Provider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
// backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});