tooot/src/App.tsx

120 lines
3.7 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'
import push from '@root/startup/push'
2021-01-27 00:35:34 +01:00
import sentry from '@root/startup/sentry'
import timezone from '@root/startup/timezone'
2020-12-27 18:43:49 +01:00
import { persistor, store } from '@root/store'
import * as Sentry from '@sentry/react-native'
2021-03-27 00:02:32 +01:00
import AccessibilityManager from '@utils/accessibility/AccessibilityManager'
import { changeLanguage, getSettingsLanguage } from '@utils/slices/settingsSlice'
2020-12-27 18:43:49 +01:00
import ThemeManager from '@utils/styles/ThemeManager'
import * as Localization from 'expo-localization'
import * as SplashScreen from 'expo-splash-screen'
import React, { useCallback, useEffect, useState } from 'react'
2022-06-03 21:25:20 +02:00
import { LogBox, Platform } from 'react-native'
import { GestureHandlerRootView } from 'react-native-gesture-handler'
2021-12-18 19:59:38 +01:00
import { enableFreeze } from 'react-native-screens'
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-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()
timezone()
2022-02-02 22:47:30 +01:00
enableFreeze(true)
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
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
}, [])
2020-11-23 00:07:32 +01:00
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<QueryClientProvider client={queryClient}>
<Provider store={store}>
<PersistGate
persistor={persistor}
onBeforeLift={onBeforeLift}
2022-08-07 01:18:10 +02:00
children={bootstrapped => {
log('log', 'App', 'bootstrapped')
if (bootstrapped) {
log('log', 'App', 'loading actual app :)')
log('log', 'App', `Locale: ${Localization.locale}`)
const language =
Platform.OS === 'ios'
? Localization.locale
: getSettingsLanguage(store.getState())
2022-08-07 01:18:10 +02:00
if (!language) {
if (Platform.OS !== 'ios') {
store.dispatch(changeLanguage('en'))
}
2022-08-07 01:18:10 +02:00
i18n.changeLanguage('en')
} else {
i18n.changeLanguage(language)
}
return (
<ActionSheetProvider>
<AccessibilityManager>
<ThemeManager>
<Screens localCorrupt={localCorrupt} />
</ThemeManager>
</AccessibilityManager>
</ActionSheetProvider>
2022-08-07 01:18:10 +02:00
)
} else {
return null
}
}}
/>
</Provider>
</QueryClientProvider>
</GestureHandlerRootView>
2020-11-23 00:07:32 +01:00
)
}
2020-10-31 21:04:46 +01:00
export default Sentry.wrap(App)