-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
93 lines (82 loc) · 3.5 KB
/
App.js
File metadata and controls
93 lines (82 loc) · 3.5 KB
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
import 'react-native-gesture-handler';
import {NavigationContainer, DefaultTheme, DarkTheme} from '@react-navigation/native';
import Tabs from './navigation/tabs.js';
import { useColorScheme, Platform } from 'react-native'
import mobileAds, { MaxAdContentRating, TestIds } from 'react-native-google-mobile-ads';
import { useEffect, useState } from 'react';
import DeviceInfo from 'react-native-device-info'
import {IOSADID, ANDROIDADID} from '@dotenv'
import { AdIdContext } from './context/AdIdContext';
import { StatusBar } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { AppStylingContext } from './context/AppStylingContext';
import ErrorBoundary from './components/ErrorBoundary.js';
const EditedLightTheme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
link: 'blue'
}
}
const EditedDarkTheme = {
...DarkTheme,
colors: {
...DarkTheme.colors,
link: 'lightblue'
}
}
const App = () => {
const colorScheme = useColorScheme()
const productionAdId = Platform.OS === 'ios' ? IOSADID : ANDROIDADID
const [adId, setAdId] = useState(__DEV__ || DeviceInfo.isEmulatorSync() ? TestIds.BANNER : productionAdId)
const [appStylingContextState, setAppStylingContextState] = useState(null)
useEffect(() => {
mobileAds()
.setRequestConfiguration({
// Update all future requests suitable for parental guidance
maxAdContentRating: MaxAdContentRating.PG,
// Indicates that you want your content treated as child-directed for purposes of COPPA.
tagForChildDirectedTreatment: false,
// Indicates that you want the ad request to be handled in a
// manner suitable for users under the age of consent.
tagForUnderAgeOfConsent: true,
// An array of test device IDs to allow.
testDeviceIdentifiers: ['EMULATOR'],
})
.then(() => {
console.log('Set ad configuration successfully')
// Request config successfully set!
mobileAds()
.initialize()
.then(adapterStatuses => {
// Initialization complete!
console.log('Ads have successfully been initialized')
});
});
}, [])
useEffect(() => {
AsyncStorage.getItem('AppStylingContextState').then(result => {
if (!result) AsyncStorage.setItem('AppStylingContextState', 'Default')
setAppStylingContextState(result || 'Default')
}).catch(error => {
console.error('An error occurred while getting AppStylingContextState from AsyncStorage:', error)
})
}, [])
const theme = appStylingContextState === 'Default' ? colorScheme === 'dark' ? EditedDarkTheme : EditedLightTheme : appStylingContextState === 'Dark' ? EditedDarkTheme : EditedLightTheme
return (
<ErrorBoundary>
<AdIdContext.Provider value={{adId, setAdId}}>
<AppStylingContext.Provider value={{appStylingContextState, setAppStylingContextState}}>
<NavigationContainer theme={theme}>
<StatusBar
animated={true}
barStyle={theme.dark ? 'light-content' : 'dark-content'}
/>
<Tabs/>
</NavigationContainer>
</AppStylingContext.Provider>
</AdIdContext.Provider>
</ErrorBoundary>
)
}
export default App;