forked from sdp-tech/UPCY_Mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
169 lines (154 loc) · 4.92 KB
/
App.tsx
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import React, { useState } from 'react';
import { View, TouchableOpacity, Text } from 'react-native';
import {
NavigationContainer,
DefaultTheme,
getFocusedRouteNameFromRoute,
} from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import {
BottomTabBarProps,
createBottomTabNavigator,
} from '@react-navigation/bottom-tabs';
import HomeScreen from './src/pages/Home';
import MyPageScreen from './src/pages/MyPage';
import useLoginGuard from './src/hooks/useLoginGuard';
import HomeIcon from './src/assets/navbar/Home.svg';
import MyPageIcon from './src/assets/navbar/MyPage.svg';
import SignIn from './src/components/Auth/SignIn';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { BottomBarProvider, useBottomBar } from './contexts/BottomBarContext';
import { LoginProvider } from './src/common/Context';
import Reformer from './src/components/Auth/Reformer/Reformer';
import SplashScreen from './src/common/SplashScreen';
export type StackProps = {
Home: undefined;
Signin: undefined;
ReformProfile: undefined;
};
const Stack = createNativeStackNavigator<StackProps>();
const GlobalTheme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
background: 'white',
},
};
function App(): React.JSX.Element {
const [isSplashFinished, setIsSplashFinished] = useState(false);
const finishSplash = () => {
console.log('finished');
setIsSplashFinished(true);
};
return (
<BottomBarProvider>
<GestureHandlerRootView style={{ flex: 1 }}>
<LoginProvider>
<NavigationContainer theme={GlobalTheme}>
{!isSplashFinished ? (
<SplashScreen onFinish={finishSplash} />
) : (
<Stack.Navigator
screenOptions={() => ({
headerShown: false,
})}>
<Stack.Screen name="Home" component={HomeTab} />
<Stack.Screen name="Signin" component={SignIn} />
<Stack.Screen name="ReformProfile" component={Reformer} />
</Stack.Navigator>
)}
</NavigationContainer>
</LoginProvider>
</GestureHandlerRootView>
</BottomBarProvider>
);
}
export type TabProps = {
홈: undefined;
마이페이지: undefined;
};
const CustomTab = ({ state, descriptors, navigation }: BottomTabBarProps) => {
const loginGuard = useLoginGuard();
const { options } = descriptors;
const { isVisible } = useBottomBar(); // 바텀바 보임/숨김 상태를 가져옵니다.
if (!isVisible) {
return null; // isVisible이 false일 경우 탭바를 렌더링하지 않습니다.
}
return (
<View
style={{
display: 'flex',
height: 86,
flexDirection: 'row',
justifyContent: 'space-around',
backgroundColor: '#FFFFFF',
paddingHorizontal: 10,
}}>
{state.routes.map((route, index) => {
const isFocused = state.index == index;
const onPress = () => {
if (route.name == '홈') {
if (isFocused)
navigation.reset({
routes: [{ name: route.name, params: { id: undefined } }],
});
else navigation.navigate(route.name, { id: undefined });
} else if (route.name == '마이페이지') {
if (isFocused)
navigation.reset({
routes: [{ name: route.name, params: { id: undefined } }],
});
else navigation.navigate(route.name, { id: undefined });
}
};
return (
<TouchableOpacity
key={index}
onPress={route.name == '마이페이지' ? loginGuard(onPress) : onPress}
style={{
width: '20%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}>
{
{
0: <HomeIcon color="#000000" opacity={isFocused ? 1 : 0.4} />,
1: <MyPageIcon color="#000000" opacity={isFocused ? 1 : 0.4} />,
}[index]
}
<Text
style={{
color: '#000000',
opacity: isFocused ? 1 : 0.4,
marginVertical: 5,
fontSize: 12,
}}>
{route.name}
</Text>
</TouchableOpacity>
);
})}
</View>
);
};
const Tab = createBottomTabNavigator<TabProps>();
const HomeTab = (): JSX.Element => {
return (
<Tab.Navigator
tabBar={props => <CustomTab {...props} />}
id="MainHome"
initialRouteName="홈"
screenOptions={() => ({
headerShown: false,
})}>
<Tab.Screen
name={'홈'}
component={HomeScreen}
options={{ tabBarStyle: { display: 'none' } }}
/>
<Tab.Screen name={'마이페이지'} component={MyPageScreen} />
</Tab.Navigator>
);
};
export default App;