-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.jsx
More file actions
155 lines (133 loc) · 3.68 KB
/
App.jsx
File metadata and controls
155 lines (133 loc) · 3.68 KB
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
import React, { useState, useEffect, useRef } from 'react';
import { NavigationContainer, DefaultTheme } from '@react-navigation/native';
import { StatusBar, BackHandler, ToastAndroid, StyleSheet } from 'react-native';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { WebView } from 'react-native-webview';
import PropTypes from 'prop-types';
// import back from './src/assets/images/NaviIcon/left.png';
// import settingsIcon from './src/assets/images/NaviIcon/web-settings.png';
import StackNavigator from './src/navigation/StackNavigator';
const WebViewScreen = ({ route }) => {
const { url } = route.params;
return <WebView source={{ uri: url }} />;
};
WebViewScreen.propTypes = {
route: PropTypes.shape({
params: PropTypes.shape({
url: PropTypes.string.isRequired,
}).isRequired,
}).isRequired,
};
// StatusBar 투명하게 설정
StatusBar.setBackgroundColor('transparent');
StatusBar.setTranslucent(true);
StatusBar.setBarStyle('dark-content');
const App = () => {
const navigationRef = useRef();
const [isLoading, setIsLoading] = useState(true);
const [backPressedOnce, setBackPressedOnce] = useState(false);
useEffect(() => {
const checkLoginStatus = async () => {
try {
const value = await AsyncStorage.getItem('isLoggedIn');
console.log('isLoggedIn value:', value); // 로그 추가
} catch (error) {
console.error('Failed to fetch isLoggedIn from AsyncStorage', error);
} finally {
setIsLoading(false);
}
};
checkLoginStatus();
}, []);
useEffect(() => {
if (isLoading) {
return;
}
const backAction = () => {
const currentRoute = navigationRef.current?.getCurrentRoute()?.name;
if (
currentRoute === 'Login' ||
['Course', 'Community', 'Crew', 'MyProfile'].includes(currentRoute)
) {
if (backPressedOnce) {
BackHandler.exitApp();
return true;
}
setBackPressedOnce(true);
ToastAndroid.show('한번 더 누르면 종료됩니다.', ToastAndroid.SHORT);
setTimeout(() => {
setBackPressedOnce(false);
}, 2000);
return true;
}
navigationRef.current?.goBack();
return true;
};
const backHandler = BackHandler.addEventListener(
'hardwareBackPress',
backAction,
);
return () => backHandler.remove();
}, [backPressedOnce, isLoading]);
if (isLoading) {
return null; // 로딩 중일 때 표시할 컴포넌트 (스플래시 화면 등)
}
const customTheme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
background: 'white',
},
fonts: {
regular: {
color: 'black',
fontFamily: 'Pretendard',
},
},
};
return (
<GestureHandlerRootView style={styles.container}>
<NavigationContainer theme={customTheme} ref={navigationRef}>
<StackNavigator />
</NavigationContainer>
</GestureHandlerRootView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
},
backButton: {
marginLeft: 16,
},
backButtonCircle: {
width: 36,
height: 36,
borderRadius: 18,
backgroundColor: '#50C878',
justifyContent: 'center',
alignItems: 'center',
},
backIcon: {
width: 24,
height: 24,
},
settingButton: {
marginRight: 16,
},
settingButtonCircle: {
width: 36,
height: 36,
borderRadius: 18,
backgroundColor: '#50C878',
justifyContent: 'center',
alignItems: 'center',
},
settingIcon: {
width: 24,
height: 24,
},
});
export default App;