-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
95 lines (82 loc) · 2.76 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import React, {useState} from 'react';
import {createStackNavigator} from '@react-navigation/stack';
import {NavigationContainer, useNavigation} from "@react-navigation/native";
import {createBottomTabNavigator} from "@react-navigation/bottom-tabs";
import {AppLoading} from "expo";
import AppNavigator from "./app/navigation/AppNavigator";
import navigationTheme from "./app/navigation/navigationTheme";
import Screen from "./app/components/Screen";
import routes from "./app/navigation/routes";
import OfflineNotice from "./app/components/OfflineNotice";
import AuthNavigator from "./app/navigation/AuthNavigator";
import AuthContext from "./app/auth/context";
import authStorage from "./app/auth/storage";
import {navigationRef} from "./app/navigation/rootNavigation";
const Link = () => {
const navigation = useNavigation();
return (
<Button title="Click" onPress={() => navigation.navigate(routes.TWEET_DETAILS)}/>
);
};
const Tweets = ({navigation}) => (
<Screen>
<Text>Tweets</Text>
<Button title="View Tweet" onPress={() => navigation.navigate(routes.TWEET_DETAILS, {id: 1})}/>
</Screen>
);
const TweetDetails = ({route}) => (
<Screen>
<Text>Tweet Details {route.params.id}</Text>
</Screen>
);
const Stack = createStackNavigator();
const StackNavigator = () => (
<Stack.Navigator
screenOptions={{
headerStyle: {backgroundColor: "dodgerblue"},
headerTintColor: "white",
}}
>
<Stack.Screen
name="Tweets"
component={Tweets}
options={{}}
/>
<Stack.Screen
name="TweetDetails"
component={TweetDetails}
options={({route}) => ({title: route.params.id})}/>
</Stack.Navigator>
);
const Account = () => <Screen><Text>Account</Text></Screen>
const Tab = createBottomTabNavigator();
const TabNavigator = () => (
<Tab.Navigator>
<Tab.Screen
name="Feed"
component={StackNavigator}/>
<Tab.Screen
name="Account"
component={Account}/>
</Tab.Navigator>
);
export default function App() {
const [user, setUser] = useState();
const [isReady, setIsReady] = useState(false);
const restoreUser = async () => {
const user = await authStorage.getUser();
if (user) setUser(user);
}
if (!isReady)
return (
<AppLoading startAsync={restoreUser} onFinish={() => setIsReady(true)}/>
);
return (
<AuthContext.Provider value={{user, setUser}}>
<OfflineNotice/>
<NavigationContainer ref={navigationRef} theme={navigationTheme}>
{user ? <AppNavigator/> : <AuthNavigator/>}
</NavigationContainer>
</AuthContext.Provider>
);
}