1- import {
2- FlatList ,
3- Platform ,
4- StatusBar ,
5- StyleSheet ,
6- Text ,
7- View ,
8- } from "react-native" ;
9- import React from "react" ;
1+ import { FlatList , StatusBar , StyleSheet , Text , View } from "react-native" ;
2+ import React , { useEffect } from "react" ;
3+ import { SafeAreaView } from "react-native-safe-area-context" ;
104
115import { Colors } from "../config/Colors" ;
126import courses from "../assets/data/courses" ;
137import Course from "../components/Course" ;
148
15- const Home = ( ) => {
9+ import MaterialIcons from "@expo/vector-icons/MaterialIcons" ;
10+
11+ const Home = ( { navigation } ) => {
12+ const [ isScrolling , setIsScrolling ] = React . useState ( false ) ;
13+
14+ useEffect ( ( ) => {
15+ const unsub = navigation . addListener ( "beforeRemove" , ( e ) => {
16+ e . preventDefault ( ) ;
17+ } ) ;
18+
19+ return unsub ;
20+ } , [ ] ) ;
21+
1622 return (
17- < View style = { styles . container } >
18- { /* User Greeting Header */ }
19- < StatusBar
20- barStyle = { "light-content" }
21- translucent
22- backgroundColor = { "transparent" }
23- />
24- < View >
25- < Text style = { styles . welcomeText } > Welcome back, Amit</ Text >
26- < Text style = { styles . sub } >
27- Please choose from the list of available office hours below:
28- </ Text >
29- </ View >
23+ < SafeAreaView style = { styles . container } >
24+ < View style = { { paddingTop : 10 , flex : 1 } } >
25+ { /* User Greeting Header */ }
26+ < StatusBar
27+ barStyle = { "light-content" }
28+ translucent
29+ backgroundColor = { "transparent" }
30+ />
31+ < View >
32+ < View
33+ style = { {
34+ flexDirection : "row" ,
35+ justifyContent : "space-between" ,
36+ alignItems : "center" ,
37+ } }
38+ >
39+ < Text style = { styles . welcomeText } > Welcome back, Amit!</ Text >
40+ < MaterialIcons name = "logout" size = { 30 } color = { Colors . Red } />
41+ </ View >
42+ < Text style = { styles . sub } >
43+ Please choose from the list of available office hours below:
44+ </ Text >
45+ </ View >
3046
31- { /* Flatlist of courses */ }
32- < View
33- style = { { height : 2 , backgroundColor : "#fff9" , marginVertical : 15 } }
34- > </ View >
35- < FlatList
36- data = { courses }
37- numColumns = { 2 }
38- renderItem = { ( { item, index } ) => < Course key = { index } course = { item } /> }
39- />
40- </ View >
47+ { /* Flatlist of courses */ }
48+ < View
49+ style = { { height : 2 , backgroundColor : "#fff9" , marginVertical : 15 } }
50+ > </ View >
51+ < FlatList
52+ data = { courses }
53+ numColumns = { 2 }
54+ onScrollBeginDrag = { ( ) => {
55+ // Disable touch events while scrolling
56+ setIsScrolling ( true ) ;
57+ } }
58+ onScrollEndDrag = { ( ) => {
59+ // Enable touch events after scrolling
60+ setIsScrolling ( false , 150 ) ;
61+ } }
62+ renderItem = { ( { item, index } ) => (
63+ < Course
64+ key = { index }
65+ course = { item }
66+ navigation = { navigation }
67+ disabled = { isScrolling }
68+ />
69+ ) }
70+ />
71+ </ View >
72+ </ SafeAreaView >
4173 ) ;
4274} ;
4375
@@ -46,14 +78,14 @@ export default Home;
4678const styles = StyleSheet . create ( {
4779 container : {
4880 flex : 1 ,
49- backgroundColor : Colors . Background ,
50- paddingTop : Platform . OS === "android" ? StatusBar . currentHeight + 20 : 0 ,
81+ backgroundColor : "#0d031b" ,
5182 padding : 10 ,
5283 } ,
5384 welcomeText : {
5485 fontSize : 28 ,
5586 fontWeight : "bold" ,
5687 color : Colors . Primary ,
88+ width : "70%" ,
5789 } ,
5890 sub : {
5991 fontSize : 16 ,
0 commit comments