2022-07-18 22:24:37 +02:00
|
|
|
import 'react-native-url-polyfill/auto'
|
2022-06-09 20:03:25 +02:00
|
|
|
import React, {useState, useEffect} from 'react'
|
2022-11-21 23:07:26 +01:00
|
|
|
import {Linking} from 'react-native'
|
2022-07-26 01:31:42 +02:00
|
|
|
import {RootSiblingParent} from 'react-native-root-siblings'
|
|
|
|
import {GestureHandlerRootView} from 'react-native-gesture-handler'
|
2022-11-05 20:52:44 +01:00
|
|
|
import SplashScreen from 'react-native-splash-screen'
|
2022-11-16 21:05:21 +01:00
|
|
|
import {SafeAreaProvider} from 'react-native-safe-area-context'
|
2022-12-30 22:48:34 +01:00
|
|
|
import {observer} from 'mobx-react-lite'
|
2023-01-24 20:58:35 +01:00
|
|
|
import {
|
|
|
|
createClient,
|
|
|
|
SegmentClient,
|
|
|
|
AnalyticsProvider,
|
|
|
|
} from '@segment/analytics-react-native'
|
2022-12-28 21:06:01 +01:00
|
|
|
import {ThemeProvider} from './view/lib/ThemeContext'
|
2022-07-19 23:04:45 +02:00
|
|
|
import * as view from './view/index'
|
2022-07-19 22:37:24 +02:00
|
|
|
import {RootStoreModel, setupState, RootStoreProvider} from './state'
|
2022-08-31 21:36:50 +02:00
|
|
|
import {MobileShell} from './view/shell/mobile'
|
2023-01-24 20:00:11 +01:00
|
|
|
import {s} from './view/lib/styles'
|
2023-01-25 02:32:24 +01:00
|
|
|
import notifee, {EventType} from '@notifee/react-native'
|
2022-06-09 20:03:25 +02:00
|
|
|
|
2022-12-30 22:48:34 +01:00
|
|
|
const App = observer(() => {
|
2022-07-19 22:37:24 +02:00
|
|
|
const [rootStore, setRootStore] = useState<RootStoreModel | undefined>(
|
|
|
|
undefined,
|
|
|
|
)
|
2023-01-24 20:58:35 +01:00
|
|
|
const [segment, setSegment] = useState<SegmentClient | undefined>(undefined)
|
2022-06-09 20:03:25 +02:00
|
|
|
|
|
|
|
// init
|
|
|
|
useEffect(() => {
|
2022-11-23 22:04:44 +01:00
|
|
|
view.setup()
|
2023-01-24 20:58:35 +01:00
|
|
|
setSegment(
|
|
|
|
createClient({
|
|
|
|
writeKey: '8I6DsgfiSLuoONyaunGoiQM7A6y2ybdI',
|
|
|
|
trackAppLifecycleEvents: true,
|
|
|
|
}),
|
|
|
|
)
|
2022-11-23 22:04:44 +01:00
|
|
|
setupState().then(store => {
|
|
|
|
setRootStore(store)
|
|
|
|
SplashScreen.hide()
|
|
|
|
Linking.getInitialURL().then((url: string | null) => {
|
|
|
|
if (url) {
|
2022-11-21 23:07:26 +01:00
|
|
|
store.nav.handleLink(url)
|
2022-11-23 22:04:44 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
Linking.addEventListener('url', ({url}) => {
|
|
|
|
store.nav.handleLink(url)
|
2022-11-05 20:52:44 +01:00
|
|
|
})
|
2023-01-25 02:32:24 +01:00
|
|
|
notifee.onForegroundEvent(async ({type}: {type: EventType}) => {
|
|
|
|
store.log.debug('Notifee foreground event', {type})
|
|
|
|
if (type === EventType.PRESS) {
|
|
|
|
store.log.debug('User pressed a notifee, opening notifications')
|
|
|
|
store.nav.switchTo(1, true)
|
|
|
|
}
|
|
|
|
})
|
2022-11-23 22:04:44 +01:00
|
|
|
})
|
2022-06-09 20:03:25 +02:00
|
|
|
}, [])
|
|
|
|
|
|
|
|
// show nothing prior to init
|
|
|
|
if (!rootStore) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-01-24 20:00:11 +01:00
|
|
|
<GestureHandlerRootView style={s.h100pct}>
|
2022-07-26 01:31:42 +02:00
|
|
|
<RootSiblingParent>
|
2023-01-24 20:58:35 +01:00
|
|
|
<AnalyticsProvider client={segment}>
|
|
|
|
<RootStoreProvider value={rootStore}>
|
|
|
|
<ThemeProvider theme={rootStore.shell.darkMode ? 'dark' : 'light'}>
|
|
|
|
<SafeAreaProvider>
|
|
|
|
<MobileShell />
|
|
|
|
</SafeAreaProvider>
|
|
|
|
</ThemeProvider>
|
|
|
|
</RootStoreProvider>
|
|
|
|
</AnalyticsProvider>
|
2022-07-26 01:31:42 +02:00
|
|
|
</RootSiblingParent>
|
|
|
|
</GestureHandlerRootView>
|
2022-06-09 20:03:25 +02:00
|
|
|
)
|
2022-12-30 22:48:34 +01:00
|
|
|
})
|
2022-06-09 20:03:25 +02:00
|
|
|
|
|
|
|
export default App
|