-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
85 lines (78 loc) · 2.68 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, {useLayoutEffect, useState} from 'react';
import type {Node} from 'react';
import {NavigationContainer} from '@react-navigation/native';
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
import SearchView from './Views/SearchView';
import BookingsView from './Views/BookingsView';
import AccountView from './Views/AccountView';
import SelectionView from './Views/LoginViews/SelectionView';
import {AccountContext, getToken} from './Logic/AccountLogic';
import {Platform, Settings, useColorScheme} from 'react-native';
import {DefaultTheme, DarkTheme} from '@react-navigation/native';
import Icon from 'react-native-vector-icons/Ionicons';
const Tab = createBottomTabNavigator();
const App: () => Node = () => {
const isDarkMode = useColorScheme() === 'dark';
const [isSignedIn, setIsSignedIn] = useState(() => {
if (Platform.OS === 'ios') {
const optionalToken = Settings.get('booklyToken');
return optionalToken !== null && optionalToken !== undefined;
} else {
return false;
}
});
const update = async () => {
const item = await getToken();
setIsSignedIn(item != null);
};
useLayoutEffect(() => {
update();
}, []);
return (
<NavigationContainer theme={isDarkMode ? DarkTheme : DefaultTheme}>
<AccountContext.Provider value={{isSignedIn, update}}>
{isSignedIn ? (
<Tab.Navigator screenOptions={{headerShown: false}}>
<Tab.Screen
name="SearchTab"
options={{
headerLargeTitle: true,
tabBarLabel: 'Search',
tabBarIcon: ({focused, color, size}) => <Icon name="search" size={size} color={color} />,
}}
component={SearchView}
/>
<Tab.Screen
name="BookingsTab"
options={{
headerLargeTitle: true,
tabBarLabel: 'Bookings',
tabBarIcon: ({focused, color, size}) => <Icon name="book" size={size} color={color} />,
}}
component={BookingsView}
/>
<Tab.Screen
name="AccountTab"
options={{
headerLargeTitle: true,
tabBarLabel: 'Account',
tabBarIcon: ({focused, color, size}) => <Icon name="person-circle" size={size} color={color} />,
}}
component={AccountView}
/>
</Tab.Navigator>
) : (
<SelectionView />
)}
</AccountContext.Provider>
</NavigationContainer>
);
};
export default App;