-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppTimelineItem.jsx
428 lines (403 loc) · 10.6 KB
/
AppTimelineItem.jsx
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
//// [IMPORTS] ////
import * as React from 'react';
import {
Image,
SafeAreaView,
ScrollView,
StyleSheet,
Modal,
Pressable,
Text,
View,
} from 'react-native';
import { MaterialIcons } from '@expo/vector-icons';
export default function TimeLineItem({
itemData,
isTextEnlarged,
inactive,
touchDetected,
warn,
}) {
//// [MODAL] ////
// [State: to control modal visibility]
const [modalVisible, setModalVisible] = React.useState(false);
//// [SCROLL] ////
// [State: to monitor if a card was scrolled]
const [scrolled, setScrolled] = React.useState(0);
// [cardRef: for scrolling cards]
let cardRef = React.useRef(null);
//// [handleScrollEvent: function to monitor scrolled cards]
const handleScrollEvent = () => {
let newScrolled = scrolled + 1;
setScrolled(newScrolled);
touchDetected();
};
//// [SCROLL TO IMAGE] ////
// [downButtonHandler: function to scroll for image icon onPress]
const downButtonHandler = () => {
cardRef.current.scrollToEnd({ animated: true });
handleScrollEvent();
};
//// [MAP MARKER FOR LOCAL EVENTS]
const youAreHere = `You\nAre\nHere`;
//// [MODAL] ////
// [handleModalOpen: function for opening modal]
const handleModalOpen = () => {
setModalVisible(true);
handleScrollEvent();
};
// [handleModalClose: function for closing modal]
const handleModalClose = () => {
setModalVisible(!modalVisible);
handleScrollEvent();
};
//// [WARNING TIMEOUT] ////
React.useEffect(() => {
if (warn && modalVisible) {
setModalVisible(false);
}
}), [warn];
//// [INACTIVITY TIMEOUT] ////
React.useEffect(() => {
if (inactive && scrolled) {
cardRef.current.scrollTo({
y: 0,
animated: true,
});
setScrolled(0);
};
if (modalVisible) {
setModalVisible(false);
}
},[inactive]);
//// [COMPONENT] ////
return (
<View style={styles.itemWrapper}>
{/* [CIRCLE DISPLAYING THE YEAR] */}
<View>
<View style={styles.circleIcon}>
<Text style={isTextEnlarged ? styles.circleYearEnlarged : styles.circleYearFont}>
{itemData.year}
</Text>
</View>
</View>
{/* [CARD DISPLAYING INFORMATION ABOUT THE EVENT] */}
<ScrollView
style={styles.itemCard}
ref={cardRef}
scrollEventThrottle={16}
onScrollEndDrag={handleScrollEvent}
scrolled={scrolled}
>
{/* [CARD TITLE] */}
<View style={styles.itemCardTitleBox}>
<Text
style={[isTextEnlarged ? styles.itemCardTitleEnlarged : styles.itemCardTitleFont]}>
{itemData.location}
</Text>
</View>
{/* [CARD IMAGE ICON/SCROLL-DOWN-BUTTON IF THERE IS MEDIA] */}
{itemData.media ?
<Pressable
style={styles.mediaIcon}
onPress={downButtonHandler}
>
<MaterialIcons name='image' size={32} color='black' />
</Pressable>
:
<View />
}
{/* [MAP MARKER FOR LOCAL EVENTS] */}
{itemData.location === 'Gothenberg, Nebraska' || itemData.location === 'The Pony Express Route' ?
<View style={styles.mapMarker}>
<MaterialIcons name="where-to-vote" size={32} color="green" />
<Text style={styles.youAreHere}>{youAreHere}</Text>
</View>
:
<View />
}
{/* [CARD SUBTITLE] */}
<View style={styles.itemCardSubTitleBox}>
<Text
style={[
styles.itemCardMarginBox,
isTextEnlarged ? styles.itemCardSubTitleEnlarged : styles.itemCardSubTitleFont
]}
>
{itemData.date}
</Text>
</View>
{/* [CARD CONTENT] */}
<Text style={[
styles.itemCardMarginBox,
isTextEnlarged ? styles.itemCardDescriptionEnlarged : styles.itemCardDescriptionFont
]}
>
{itemData.description}
</Text>
{/* [CARD MEDIA / IMAGES] */}
{itemData.media ?
<View style={styles.itemCardMedia}>
<Image
alt={itemData.media.alt ? itemData.media.alt : ""}
style={
{ flex: 1, height: undefined, width: undefined, marginVertical: 10, }
}
source={itemData.media.img}
resizeMethod='auto'
resizeMode='contain'
/>
{/* [BUTTON TO OPEN MODAL], this could possibly be wrapped around the image instead of a button */}
<Pressable
style={[styles.modalButton, styles.modalButtonOpen]}
onPress={handleModalOpen}
>
<Text style={isTextEnlarged ? styles. modalButtonTextEnlarged: styles.modalButtonTextFont}>
View Larger Image
</Text>
</Pressable>
{/* [MODAL TO VIEW LARGER IMAGE] */}
<Modal
animationType='slide'
// presentationStyle='fullScreen'
visible={modalVisible}
onRequestClose={() => {
setModalVisible(!modalVisible);
touchDetected();
}}
>
<SafeAreaView style={{ flex: 0, backgroundColor: '#191109', }} />
<SafeAreaView style={{ flex: 1, backgroundColor: '#191109', }}>
<View style={styles.modalMedia}>
<Image
alt={itemData.media.alt ? itemData.media.alt : ""}
style={{ flex: 1, height: undefined, width: undefined, }}
source={itemData.media.img}
resizeMethod='auto'
resizeMode='contain'
/>
</View>
{itemData.media.alt ?
<View style={styles.modalAltBox}>
<Text style={isTextEnlarged ? styles.modalAltTextEnlarged : styles.modalAltTextFont}>
{itemData.media.alt}
</Text>
</View>
:
<View />
}
<Pressable
style={[styles.modalButton, styles.modalButtonClose]}
onPress={handleModalClose}
>
<Text
style={isTextEnlarged ? styles. modalButtonTextEnlarged: styles.modalButtonTextFont}
>
Go Back To The Timeline
</Text>
</Pressable>
</SafeAreaView>
</Modal>
</View>
:
<View />
}
</ScrollView>
</View>
)
};
//// [ITEM STYLES] ////
const styles = StyleSheet.create({
itemWrapper: {
flex: 1,
flexDirection: 'column',
marginBottom: 10,
marginLeft: 40, // these margins keep the FlatList from staring/ending at the edges
marginRight: 40, // these margins keep the FlatList from staring/ending at the edges
marginTop: 0,
width: 500,
},
circleIcon: {
backgroundColor: '#322312', // brownMediumDark
borderColor: '#4A2711', // brownAccent
borderRadius: 5,
borderRadius: 100,
borderStyle: 'solid',
borderWidth: 1,
height: 80,
justifyContent: 'center',
marginTop: 0,
marginBottom: 5,
marginLeft: 'auto',
marginRight: 'auto',
paddingLeft: 2,
shadowColor: '#171717',
shadowOffset: {
width: 10,
height: 10,
},
shadowOpacity: 0.5,
shadowRadius: 5,
width: 80,
},
circleYearFont: {
color: '#E8DCB8',
fontFamily: 'Sancreek_400Regular',
fontSize: 24,
textAlign: 'center',
},
circleYearEnlarged: {
color: '#E8DCB8',
fontFamily: 'System',
fontSize: 24,
fontWeight: '500',
textAlign: 'center',
},
itemCard: {
backgroundColor: '#E8DCB8',
borderColor: '#191109', // brownDark
borderRadius: 20,
borderStyle: 'solid',
borderWidth: 1,
overflow: 'scroll',
padding: 20,
shadowColor: '#171717',
shadowOffset: {
width: 10,
height: 10
},
shadowOpacity: 0.5,
shadowRadius: 5,
width: 500,
},
itemCardMarginBox: {
marginBottom: 10,
marginTop: 10,
},
mediaIcon: {
position: 'absolute',
right: 0,
top: 0,
},
mapMarker: {
alignItems: 'center',
justifyContent: 'center',
position: 'absolute',
right: 0,
top: 55,
},
youAreHere: {
textAlign: 'center',
},
itemCardTitleBox: {
minHeight: 120,
maxWidth: 420,
},
itemCardTitleFont: {
fontFamily: 'SpecialElite_400Regular',
fontSize: 30,
},
itemCardTitleEnlarged: {
fontFamily: 'System',
fontSize: 35,
fontWeight: 'bold',
},
itemCardSubTitleBox: {
minHeight: 50,
maxWidth: 420,
},
itemCardSubTitleFont: {
fontFamily: 'SpecialElite_400Regular',
fontSize: 26,
marginBottom: 15,
marginTop: 5,
// textAlign: 'right'
},
itemCardSubTitleEnlarged: {
fontFamily: 'System',
fontSize: 30,
fontWeight: 'bold',
height: 45,
marginBottom: 5,
marginTop: 5,
// textAlign: 'right'
},
itemCardDescriptionFont: {
fontFamily: 'SpecialElite_400Regular',
fontSize: 24,
lineHeight: 25,
letterSpacing: .75,
paddingTop: 5,
marginBottom: 5,
},
itemCardDescriptionEnlarged: {
fontFamily: 'System',
fontSize: 30,
marginBottom: 5,
marginTop: 5,
},
itemCardMedia: {
flex: 1,
marginVertical: 20,
minWidth: 450,
minHeight: 450,
},
itemCardBottomSpace: {
height: 20,
},
modalMedia: {
backgroundColor: '#191109',
flex: 1,
margin: 20,
minHeight: 450,
minWidth: 450,
},
modalAltBox: {
alignSelf: 'center',
alignItems: 'center',
backgroundColor: '#E8DCB8',
borderColor: '#191109', // brownDark
borderRadius: 10,
borderStyle: 'solid',
borderWidth: 1,
justifyContent: 'center',
margin: 10,
padding: 20,
},
modalAltTextFont: {
fontFamily: 'SpecialElite_400Regular',
fontSize: 20,
textAlign: 'center',
},
modalAltTextEnlarged: {
fontFamily: 'System',
fontSize: 24,
fontWeight: 'bold',
textAlign: 'center',
},
modalButton: {
alignSelf: 'center',
backgroundColor: '#FAB05A',
borderRadius: 20,
elevation: 2,
marginBottom: 20,
padding: 10,
},
modalButtonOpen: {
width: 300,
},
modalButtonClose: {
width: 400,
},
modalButtonTextFont: {
fontFamily: 'SpecialElite_400Regular',
fontSize: 20,
textAlign: 'center',
},
modalButtonTextEnlarged: {
fontFamily: 'System',
fontSize: 24,
fontWeight: 'bold',
textAlign: 'center',
},
});