forked from sdp-tech/SASM_Mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
281 lines (258 loc) · 8.23 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
import React, { useEffect, useState, useCallback } from "react";
import { Text, TouchableOpacity, View, Linking, LinkingStatic, Alert } from "react-native";
import { LinkingOptions, NavigationContainer, useNavigation, useFocusEffect } from "@react-navigation/native";
import {
BottomTabBarProps,
createBottomTabNavigator,
} from "@react-navigation/bottom-tabs";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import MapScreen from "./src/pages/SpotMap";
import LoginScreen from "./src/components/Auth/Login";
import MyPageScreen from "./src/pages/MyPage";
import ForestScreen from "./src/pages/Forest";
import StoryScreen, { StoryStackParams } from "./src/pages/Story";
import Navbar0 from "./src/assets/navbar/Navbar0.svg";
import Navbar1 from "./src/assets/navbar/Navbar1.svg";
import Navbar2 from "./src/assets/navbar/Navbar2.svg";
import Navbar3 from "./src/assets/navbar/Navbar3.svg";
import Navbar4 from "./src/assets/navbar/Navbar4.svg";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import HomeScreen from "./src/pages/Home";
import { Coord } from "react-native-nmap";
import SplashScreen from "react-native-splash-screen";
import { LoginProvider } from "./src/common/Context";
import CodePush from 'react-native-code-push';
export type AppProps = {
Home: any;
Login: any;
}
const Stack = createNativeStackNavigator();
const useInitialURL = () => {
const [url, setUrl] = useState<string | null>(null);
const [processing, setProcessing] = useState(true);
useEffect(() => {
const getUrlAsync = async () => {
// Get the deep link used to open the app
const initialUrl = await Linking.getInitialURL();
// console.log(initialUrl)
// The setTimeout is just for testing purpose
setTimeout(() => {
setUrl(initialUrl);
setProcessing(false);
}, 1000);
};
getUrlAsync();
}, []);
return {url, processing};
};
const App = (): JSX.Element => {
useEffect(() => {
setTimeout(() => {
SplashScreen.hide();
}, 800);
});
// const navigation = useNavigation<StackNavigationProp<TabProps>>();
// useEffect(() => {
// //IOS && ANDROID : 앱이 딥링크로 처음 실행될때, 앱이 열려있지 않을 때
// Linking.getInitialURL()
// .then((url) => deepLink(url))
// //IOS : 앱이 딥링크로 처음 실행될때, 앱이 열려있지 않을 때 && 앱이 실행 중일 때
// //ANDROID : 앱이 실행 중일 때
// Linking.addEventListener('url', addListenerLink);
// return () => remover()
// })
// const deepLink = (url: any) => {
// console.log('deep', url)
// if (url) {
// console.log(url)
// // navigation.navigate('OTHER_PAGE', { share: url })
// }
// };
// const addListenerLink = ({url}: any) => {
// console.log('listener', url)
// if (url) {
// // navigation.navigate('OTHER_PAGE', { share: url })
// console.log(url)
// }
// };
// const remover = () => {
// Linking.removeAllListeners('url');
// };
const {url: initialUrl, processing} = useInitialURL();
useEffect(() => {
if(initialUrl) Alert.alert(initialUrl!)
}, [])
const linking : LinkingOptions<AppProps> = {
prefixes: ["kakao6f1497a97a65b5fe1ca5cf4769c318fd://"],
config: {
screens: {
Home: {
screens: {
홈: ':from/:id',
스토리: ':from/:id',
포레스트: ':from/:id'
}
},
Login: {}
},
},
};
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<LoginProvider>
<NavigationContainer linking={linking}>
<Stack.Navigator
screenOptions={() => ({
headerShown: false,
})}
>
<Stack.Screen name="Home" component={HomeScreens} />
<Stack.Screen name="Login" component={LoginScreen} />
</Stack.Navigator>
</NavigationContainer>
</LoginProvider>
</GestureHandlerRootView>
);
};
export type TabProps = {
홈: {
id?: number | undefined;
};
맵: {
id?: number;
coor?: Coord;
place_name?: string;
};
스토리: {
id: number | undefined;
};
포레스트:{
id: number | undefined;
}
/*add email parameter*/
마이페이지: {
email?: string;
}
};
const CustomTab = ({ state, descriptors, navigation }: BottomTabBarProps) => {
return (
<View
style={{
height: 88,
display: "flex",
flexDirection: "row",
justifyContent: "space-around",
backgroundColor: "#FFFFFF",
borderColor: "#E3E3E3",
borderTopWidth: 1,
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, coor: undefined },
},
],
});
else
navigation.navigate(route.name, {
id: undefined,
coor: undefined,
});
} else 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 });
}
else {
if (isFocused) navigation.reset({ routes: [{ name: route.name }] });
else navigation.navigate(route.name);
}
};
return (
<TouchableOpacity
key={index}
onPress={onPress}
style={{
width: "20%",
display: "flex",
alignItems: "center",
justifyContent: "center",
}}
>
{
{
0: <Navbar0 color={isFocused ? "#67D393" : "#202020"} />,
1: <Navbar1 color={isFocused ? "#67D393" : "#202020"} />,
2: <Navbar2 color={isFocused ? "#67D393" : "#202020"} />,
3: <Navbar3 color={isFocused ? "#67D393" : "#202020"} />,
4: <Navbar4 color={isFocused ? "#67D393" : "#202020"} />,
}[index]
}
<Text
style={{
color: isFocused ? "#67D393" : "#202020",
marginVertical: 5,
fontSize: 12,
}}
>
{route.name}
</Text>
</TouchableOpacity>
);
})}
</View>
);
};
const Tab = createBottomTabNavigator<TabProps>();
const HomeScreens = (): JSX.Element => {
return (
<Tab.Navigator
tabBar={(props) => <CustomTab {...props} />}
initialRouteName="홈"
screenOptions={() => ({
headerShown: false,
})}
backBehavior="order"
>
<Tab.Screen name={"홈"} component={HomeScreen} />
<Tab.Screen name={"스토리"} component={StoryScreen} />
<Tab.Screen name={"맵"} component={MapScreen} />
<Tab.Screen name={"포레스트"} component={ForestScreen} />
<Tab.Screen name={"마이페이지"} component={MyPageScreen} />
</Tab.Navigator>
);
};
const codePushOptions = {
checkFrequency: CodePush.CheckFrequency.ON_APP_START,
updateDialog: {
title: '업데이트하시겠습니까?',
optionalUpdateMessage: '소소한 버그를 수정했어요🐛',
optionalInstallButtonLabel: '업데이트',
optionalIgnoreButtonLabel: '아니요.'
},
installMode: CodePush.InstallMode.ON_NEXT_RESTART
}
export default CodePush(codePushOptions)(App);