tooot/src/App.tsx

120 lines
3.4 KiB
TypeScript
Raw Normal View History

2021-01-13 01:03:46 +01:00
import { ActionSheetProvider } from '@expo/react-native-action-sheet'
2021-05-12 15:40:55 +02:00
import queryClient from '@helpers/queryClient'
2021-01-27 00:35:34 +01:00
import i18n from '@root/i18n/i18n'
import Screens from '@root/Screens'
2021-01-27 00:35:34 +01:00
import audio from '@root/startup/audio'
2021-01-13 01:03:46 +01:00
import dev from '@root/startup/dev'
import log from '@root/startup/log'
import netInfo from '@root/startup/netInfo'
2021-01-27 00:35:34 +01:00
import sentry from '@root/startup/sentry'
2020-12-27 18:43:49 +01:00
import { persistor, store } from '@root/store'
2021-03-27 00:02:32 +01:00
import AccessibilityManager from '@utils/accessibility/AccessibilityManager'
2021-01-27 00:35:34 +01:00
import { getSettingsLanguage } from '@utils/slices/settingsSlice'
2020-12-27 18:43:49 +01:00
import ThemeManager from '@utils/styles/ThemeManager'
2021-03-02 01:17:06 +01:00
import * as Notifications from 'expo-notifications'
import * as SplashScreen from 'expo-splash-screen'
import React, { useCallback, useEffect, useState } from 'react'
2021-03-02 01:17:06 +01:00
import { AppState, LogBox, Platform } from 'react-native'
import { GestureHandlerRootView } from 'react-native-gesture-handler'
2021-05-12 15:40:55 +02:00
import { QueryClientProvider } from 'react-query'
2020-11-21 13:19:05 +01:00
import { Provider } from 'react-redux'
import { PersistGate } from 'redux-persist/integration/react'
2021-02-27 16:33:54 +01:00
import push from './startup/push'
2021-01-13 01:03:46 +01:00
2021-02-27 16:33:54 +01:00
Platform.select({
android: LogBox.ignoreLogs(['Setting a timer for a long period of time'])
})
2021-01-07 19:13:09 +01:00
dev()
2021-01-23 02:41:50 +01:00
sentry()
2021-01-07 19:13:09 +01:00
audio()
2021-02-27 16:33:54 +01:00
push()
2020-12-27 18:43:49 +01:00
2020-11-23 00:07:32 +01:00
const App: React.FC = () => {
2021-01-07 19:13:09 +01:00
log('log', 'App', 'rendering App')
const [localCorrupt, setLocalCorrupt] = useState<string>()
2020-12-28 23:20:18 +01:00
const appStateEffect = useCallback(() => {
Notifications.setBadgeCountAsync(0)
Notifications.dismissAllNotificationsAsync()
}, [])
2021-03-02 01:17:06 +01:00
useEffect(() => {
AppState.addEventListener('change', appStateEffect)
2021-03-02 01:17:06 +01:00
return () => {
AppState.removeEventListener('change', appStateEffect)
2021-03-02 01:17:06 +01:00
}
}, [])
useEffect(() => {
const delaySplash = async () => {
2021-01-07 19:13:09 +01:00
log('log', 'App', 'delay splash')
try {
await SplashScreen.preventAutoHideAsync()
} catch (e) {
console.warn(e)
}
}
delaySplash()
}, [])
2021-01-07 19:13:09 +01:00
const onBeforeLift = useCallback(async () => {
2021-01-10 02:12:14 +01:00
let netInfoRes = undefined
try {
netInfoRes = await netInfo()
} catch {}
2021-01-07 19:13:09 +01:00
2021-01-10 02:12:14 +01:00
if (netInfoRes && netInfoRes.corrupted && netInfoRes.corrupted.length) {
2021-01-07 19:13:09 +01:00
setLocalCorrupt(netInfoRes.corrupted)
}
2021-01-07 19:13:09 +01:00
log('log', 'App', 'hide splash')
try {
await SplashScreen.hideAsync()
return Promise.resolve()
} catch (e) {
console.warn(e)
return Promise.reject()
}
2020-12-28 23:20:18 +01:00
}, [])
2021-01-27 00:35:34 +01:00
const children = useCallback(
bootstrapped => {
2021-01-07 19:13:09 +01:00
log('log', 'App', 'bootstrapped')
if (bootstrapped) {
log('log', 'App', 'loading actual app :)')
2021-03-28 23:31:10 +02:00
const language = getSettingsLanguage(store.getState())
i18n.changeLanguage(language)
return (
2021-01-13 01:03:46 +01:00
<ActionSheetProvider>
2021-03-27 00:02:32 +01:00
<AccessibilityManager>
<ThemeManager>
<Screens localCorrupt={localCorrupt} />
</ThemeManager>
</AccessibilityManager>
2021-01-13 01:03:46 +01:00
</ActionSheetProvider>
)
} else {
return null
}
},
2021-01-07 19:13:09 +01:00
[localCorrupt]
)
2020-11-23 00:07:32 +01:00
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<QueryClientProvider client={queryClient}>
<Provider store={store}>
<PersistGate
persistor={persistor}
onBeforeLift={onBeforeLift}
children={children}
/>
</Provider>
</QueryClientProvider>
</GestureHandlerRootView>
2020-11-23 00:07:32 +01:00
)
}
2020-10-31 21:04:46 +01:00
2021-01-01 23:10:47 +01:00
export default React.memo(App, () => true)