-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathApp.js
41 lines (35 loc) · 1.31 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
import React, { useEffect, useState } from "react"
import AppLoading from "expo-app-loading"
import { StatusBar } from "expo-status-bar"
import { NavigationContainer } from "@react-navigation/native"
import { AuthNavigator, TabNavigator } from "./app/navigation"
import navigationTheme from "./app/navigation/theme"
import OfflineNotice from "./app/components/OfflineNotice"
import AuthContext from "./app/auth/context"
import authStorage from "./app/auth/storage"
import { navigationRef } from "./app/navigation/rootNavigation"
const App = () => {
const [user, setUser] = useState(null)
const [isReady, setIsReady] = useState(false)
useEffect(() => {
const checkAuthStatus = async () => {
const user = await authStorage.getUser()
setUser(user)
}
if (!user && !isReady) {
checkAuthStatus()
setIsReady(true)
}
}, [user])
if (!isReady) return <AppLoading />
return (
<AuthContext.Provider value={{ user, setUser }}>
<StatusBar style={"auto"} />
<NavigationContainer ref={navigationRef} theme={navigationTheme}>
{user ? <TabNavigator /> : <AuthNavigator />}
</NavigationContainer>
<OfflineNotice />
</AuthContext.Provider>
)
}
export default App