-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
314 lines (290 loc) · 9.09 KB
/
App.js
File metadata and controls
314 lines (290 loc) · 9.09 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
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
import React, {useState, useEffect, useRef} from 'react';
import {
Animated,
Dimensions,
Modal,
ScrollView,
StyleSheet,
Text,
View,
} from 'react-native';
import { LogBox } from 'react-native';
import Splash from './views/screens/splash';
import Login from './views/screens/Login';
import Resume from './views/screens/ResumeContents';
import Portfolio from './views/screens/Portfolio/Portfolio';
import Review from './views/screens/Review/Review';
import MyPage from './views/screens/MyPage/MyPage';
import Album from './views/screens/Album';
import Interview from './views/screens/Interview';
import 'react-native-gesture-handler';
import WhichGroup from './views/screens/WhichGroup';
import Help from './views/screens/Help';
import Share from './views/screens/Share';
import GroupVideo from './views/screens/GroupVideo';
import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import {useNavigation} from '@react-navigation/native';
import AsyncStorage from '@react-native-async-storage/async-storage';
// import AppContext from './AppContext`';
import {MyProvider} from './MyContext';
import {IndexProvider, useIndexContext} from './IndexContext';
import {UserInfoProvider, useUserInfo} from './UserInfoContext';
import {LoadingProvider, useLoadingContext} from './LoadingContext';
import Logout from './views/screens/Logout';
import LoginGo from './views/screens/LoginGo';
import Loading from './views/screens/Loading';
const AnimatedScrollView = Animated.createAnimatedComponent(ScrollView);
const SCREEN_WIDTH = Dimensions.get('window').width;
const xOffset = new Animated.Value(0);
const Screen = props => {
return (
<View style={styles.scrollPage}>
<Animated.View style={[styles.screen, transitionAnimation(props.index)]}>
{props.children}
</Animated.View>
</View>
);
};
const Stack = createStackNavigator();
const transitionAnimation = index => {
return {
transform: [
{perspective: 800},
{
scale: xOffset.interpolate({
inputRange: [
(index - 1) * SCREEN_WIDTH,
index * SCREEN_WIDTH,
(index + 1) * SCREEN_WIDTH,
],
outputRange: [0.95, 1, 0.95],
}),
},
{
rotateX: xOffset.interpolate({
inputRange: [
(index - 1) * SCREEN_WIDTH,
index * SCREEN_WIDTH,
(index + 1) * SCREEN_WIDTH,
],
outputRange: ['0deg', '0deg', '0deg'], //x각도
}),
},
{
rotateY: xOffset.interpolate({
inputRange: [
(index - 1) * SCREEN_WIDTH,
index * SCREEN_WIDTH,
(index + 1) * SCREEN_WIDTH,
],
outputRange: ['35deg', '0deg', '-35deg'], //y각도
}),
},
],
};
};
const App = () => {
return (
<IndexProvider>
<UserInfoProvider>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{headerShown: false}}
/>
<Stack.Screen
name="Help"
component={Help}
options={{headerShown: false}}
/>
<Stack.Screen
name="Share"
component={Share}
options={{headerShown: false}}
/>
<Stack.Screen
name="Album"
component={Album}
options={{headerShown: false}}
/>
<Stack.Screen
name="Login"
component={Login}
options={{headerShown: false}}
/>
<Stack.Screen
name="Logout"
component={Logout}
options={{headerShown: false}}
/>
</Stack.Navigator>
</NavigationContainer>
</UserInfoProvider>
</IndexProvider>
);
};
const HomeScreen = () => {
const {token, id, name, email} = useUserInfo();
const [modalOpen, setModalOpen] = useState(false);
const [isSplashVisible, setIsSplashVisible] = useState(true);
const {
currentIndex,
changeIndex,
horizontalIndex,
changeHorizontalIndex,
dataIndex,
changeDataIndex,
selectedMemId,
changeSelectedMemId,
selectedGroupId,
} = useIndexContext();
const [oldIndex, setOldIndex] = useState(horizontalIndex);
const horizontalScrollRef = useRef(null);
const {loading, changeLoading} = useLoadingContext();
LogBox.ignoreLogs(['Warning: ...']); // Ignore log notification by message
LogBox.ignoreAllLogs();//Ignore all log notifications
useEffect(() => {
if (horizontalScrollRef.current) {
horizontalScrollRef.current.scrollTo({
x: horizontalIndex * SCREEN_WIDTH,
animated: true,
});
}
}, [horizontalIndex, horizontalScrollRef]);
useEffect(() => {
AsyncStorage.getItem('isSplashVisible').then(value => {
if (value !== null) {
setIsSplashVisible(JSON.parse(value));
}
});
// setIsSplashVisible(true);
let timer = setTimeout(() => {
setIsSplashVisible(false);
console.log('Splash:' + isSplashVisible);
}, 5000);
return () => clearTimeout(timer);
}, []);
useEffect(() => {
AsyncStorage.setItem('isSplashVisible', JSON.stringify(!isSplashVisible));
}, [isSplashVisible]);
// 토큰값 수신 확인 및 반영
useEffect(() => {
if (token) {
console.log('Token 메인: ', token);
console.log(`id: ${id}, name: ${name}, email: ${email}`);
}
}, [token, id, name, email]);
// 사용자 정보 수신 확인
useEffect(() => {
console.log(`id: ${id}, name: ${name}, email: ${email}`);
}, [id, name, email]);
// const [indexValue, setIndexValue] = useState(0);
const handleScroll = event => {
const offsetX = event.nativeEvent.contentOffset.x;
const newIndex = Math.round(offsetX / SCREEN_WIDTH);
// 변경된 인덱스를 처리하는 함수 호출
if (oldIndex !== newIndex) {
changeHorizontalIndex(newIndex);
setOldIndex(newIndex);
console.log("newIndex: ", newIndex, ", oldIndex: ", oldIndex, ", horizontalIndex: ", horizontalIndex);
}
};
return (
<UserInfoProvider>
<MyProvider>
<LoadingProvider>
<AnimatedScrollView
ref={horizontalScrollRef}
// scrollEventThrottle={300}
onScroll={Animated.event(
[{nativeEvent: {contentOffset: {x: xOffset}}}],
{
useNativeDriver: true,
listener: handleScroll,
},
)}
horizontal
pagingEnabled
style={styles.scrollView}>
{token ? ( // 로그인 전이면 그룹 페이지만, 로그인 후면 전체 페이지
<>
{isSplashVisible === false ? (
<Screen text="Screen 1" index={0}>
<WhichGroup token={token} />
</Screen>
) : <Splash isSplashVisible={isSplashVisible}></Splash>}
<Screen text="Screen 2" index={1}>
<GroupVideo token={token} />
</Screen>
<Screen text="Screen 3" index={2}>
<Interview token={token} />
</Screen>
<Screen text="Screen 4" index={3}>
<Portfolio token={token} options={{headerShown: false}} />
</Screen>
<Screen text="Screen 5" index={4}>
<Resume token={token} />
</Screen>
<Screen text="Screen 6" index={5}>
<Review token={token} currentUserId={id} />
</Screen>
<Screen text="Screen 7" index={6}>
<MyPage token={token} options={{headerShown: false}} />
</Screen>
</>
) : (
<>
{isSplashVisible === false ? (
<Screen text="Screen 0" index={0}>
<LoginGo token={token} />
</Screen>
) : <Splash isSplashVisible={isSplashVisible}></Splash>}
</>
)}
{loading ? (
<Modal
transparent={true}
visible={loading}
onRequestClose={() => hideLoading()}>
<View style={styles.loading}>
<Loading />
</View>
</Modal>
) : null}
</AnimatedScrollView>
</LoadingProvider>
</MyProvider>
</UserInfoProvider>
);
};
const styles = StyleSheet.create({
loading: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'rgba(0, 0, 0, 0.4)', // 투명도가 있는 검은색 배경0
},
scrollView: {
flexDirection: 'row',
backgroundColor: 'black',
},
scrollPage: {
width: SCREEN_WIDTH,
},
screen: {
width: '100%',
height: '100%',
justifyContent: 'center',
alignItems: 'center',
borderRadius: 0,
backgroundColor: 'white',
},
text: {
fontSize: 45,
fontWeight: 'bold',
},
});
export default App;