tooot/App.tsx

105 lines
2.7 KiB
TypeScript
Raw Normal View History

2021-01-13 01:03:46 +01:00
import { ActionSheetProvider } from '@expo/react-native-action-sheet'
2020-12-29 01:09:22 +01:00
import Index from '@root/Index'
2021-01-13 01:03:46 +01:00
import dev from '@root/startup/dev'
2021-01-23 02:41:50 +01:00
import sentry from '@root/startup/sentry'
2021-01-13 01:03:46 +01:00
import log from '@root/startup/log'
import audio from '@root/startup/audio'
import onlineStatus from '@root/startup/onlineStatus'
import netInfo from '@root/startup/netInfo'
2020-12-27 18:43:49 +01:00
import { persistor, store } from '@root/store'
import ThemeManager from '@utils/styles/ThemeManager'
import * as SplashScreen from 'expo-splash-screen'
import React, { useCallback, useEffect, useState } from 'react'
2020-12-25 18:20:09 +01:00
import { enableScreens } from 'react-native-screens'
2021-01-07 19:13:09 +01:00
import { QueryClient, 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-01-13 01:03:46 +01:00
import { LogBox, Platform } from 'react-native'
if (Platform.OS === 'android') {
LogBox.ignoreLogs(['Setting a timer for a long period of time'])
}
2021-01-22 02:21:13 +01:00
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()
onlineStatus()
2020-12-27 18:43:49 +01:00
2021-01-07 19:13:09 +01:00
log('log', 'react-query', 'initializing')
2020-12-25 18:20:09 +01:00
const queryClient = new QueryClient()
2021-01-07 19:13:09 +01:00
log('log', 'react-native-screens', 'initializing')
2020-12-25 18:20:09 +01:00
enableScreens()
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
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
}, [])
const main = useCallback(
bootstrapped => {
2021-01-07 19:13:09 +01:00
log('log', 'App', 'bootstrapped')
if (bootstrapped) {
log('log', 'App', 'loading actual app :)')
require('@root/i18n/i18n')
return (
2021-01-13 01:03:46 +01:00
<ActionSheetProvider>
<ThemeManager>
<Index localCorrupt={localCorrupt} />
</ThemeManager>
</ActionSheetProvider>
)
} else {
return null
}
},
2021-01-07 19:13:09 +01:00
[localCorrupt]
)
2020-11-23 00:07:32 +01:00
return (
2020-12-21 23:30:26 +01:00
<QueryClientProvider client={queryClient}>
<Provider store={store}>
<PersistGate
persistor={persistor}
onBeforeLift={onBeforeLift}
children={main}
/>
2020-12-21 23:30:26 +01:00
</Provider>
</QueryClientProvider>
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)