-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.js
118 lines (104 loc) · 3.56 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
import React, { useState, useEffect } from 'react'
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client'
import mobileAds from 'react-native-google-mobile-ads';
import { check, request, PERMISSIONS, RESULTS } from 'react-native-permissions';
import AsyncStorage from '@react-native-async-storage/async-storage'
import { Provider } from 'react-redux'
import * as ScreenOrientation from 'expo-screen-orientation'
import TabNavigationController from './NavigationController'
import { loadFonts } from './src/utils/fonts'
import { LogoActivityIndicator, ThemeProvider } from './src/components'
import store from './src/reducers'
import {
GET_HOME_FEED_ORDER_KEY,
IS_ONBOARDED_KEY,
SAVED_ARTICLES_KEY,
LAST_VIEWED_PUBLICATION_KEY,
NOTIF_PREFS_KEY,
DISPLAY_PREFS_KEY,
Storage,
} from './src/utils/storage'
import { PublicationEnum } from './src/utils/constants'
import { setInit, switchPublication } from './src/actions'
import { OnboardingModal } from './src/screens'
import { initOneSignalClient } from './src/utils/notifications';
// Initialize Apollo Client
const client = new ApolloClient({
uri: 'https://graphql-295919.ue.r.appspot.com/graphql',
cache: new InMemoryCache(),
})
const getAsyncStorage = () => {
return dispatch => {
AsyncStorage.multiGet([
GET_HOME_FEED_ORDER_KEY(PublicationEnum.dp),
GET_HOME_FEED_ORDER_KEY(PublicationEnum.street),
GET_HOME_FEED_ORDER_KEY(PublicationEnum.utb),
SAVED_ARTICLES_KEY,
LAST_VIEWED_PUBLICATION_KEY,
NOTIF_PREFS_KEY,
DISPLAY_PREFS_KEY
]).then(result => {
let lastViewedPublication = JSON.parse(result[4][1])
if (lastViewedPublication != null) {
dispatch(switchPublication(lastViewedPublication))
}
dispatch(setInit(result))
})
}
}
store.dispatch(getAsyncStorage())
const App = () => {
const [assetsLoaded, setAssetsLoaded] = useState(false)
const [isOnboarded, hasCompletedOnboarding] = useState(true)
const [attachOnboardingModalToDom, updateAttachment] = useState(true)
useEffect(() => {
const loadAssets = async () => {
// await AsyncStorage.clear()
await loadFonts()
await ScreenOrientation.lockAsync(
ScreenOrientation.OrientationLock.PORTRAIT_UP
)
// Request app tracking transparency authorization for ads - user does not need to accept
const result = await check(PERMISSIONS.IOS.APP_TRACKING_TRANSPARENCY);
if (result === RESULTS.DENIED) {
// The permission has not been requested, so request it.
await request(PERMISSIONS.IOS.APP_TRACKING_TRANSPARENCY);
}
// Initialize React Native Google Mobile Ads
const adapterStatuses = await mobileAds().initialize();
let onboarded = await Storage.getItem(IS_ONBOARDED_KEY)
hasCompletedOnboarding(onboarded === true)
updateAttachment(onboarded !== true)
setAssetsLoaded(true)
}
loadAssets()
}, [])
if (!attachOnboardingModalToDom) {
setTimeout(() => {
initOneSignalClient()
}, 5000);
}
if (assetsLoaded) {
return (
<ApolloProvider client={client}>
<Provider store={store}>
{attachOnboardingModalToDom ? (
<OnboardingModal {...{ isOnboarded, hasCompletedOnboarding }} />
) : null}
<ThemeProvider>
<TabNavigationController />
</ThemeProvider>
</Provider>
</ApolloProvider>
)
} else {
return (
<Provider store={store}>
<ThemeProvider>
<LogoActivityIndicator />
</ThemeProvider>
</Provider>
)
}
}
export default App;