11import {
22 FlatList ,
33 Platform ,
4+ Pressable ,
45 StatusBar ,
56 StyleSheet ,
67 Text ,
78 View ,
89} from "react-native" ;
9- import React from "react" ;
10+ import React , { useState } from "react" ;
1011import courses from "../assets/data/courses" ;
1112import { Colors } from "../config/Colors" ;
13+ import Animated , {
14+ FadeIn ,
15+ useAnimatedStyle ,
16+ useSharedValue ,
17+ withSpring ,
18+ } from "react-native-reanimated" ;
19+ import Constants from "expo-constants" ;
1220
13- const Locations = ( ) => {
21+ const Locations = ( { navigation } ) => {
1422 const course = courses [ 1 ] ;
1523
24+ const [ isScrolling , setIsScrolling ] = useState ( false ) ;
25+
1626 return (
1727 < View style = { styles . container } >
1828 < StatusBar
1929 barStyle = { "light-content" }
2030 backgroundColor = "transparent"
2131 translucent
2232 />
23- < Text style = { styles . heading } > Locations</ Text >
24- < Text style = { styles . sub } > Please choose one of the following: </ Text >
33+ < Animated . Text style = { styles . heading } > Locations</ Animated . Text >
34+ < Animated . Text style = { styles . sub } >
35+ Please choose one of the following:
36+ </ Animated . Text >
2537 < View
2638 style = { { height : 2 , backgroundColor : "#fff9" , marginVertical : 15 } }
2739 />
2840 < FlatList
2941 data = { course . location }
30- // numColumns={2}
3142 contentContainerStyle = { { gap : 10 } }
43+ onScrollBeginDrag = { ( ) => {
44+ // Disable touch events while scrolling
45+ setIsScrolling ( true ) ;
46+ } }
47+ onScrollEndDrag = { ( ) => {
48+ // Enable touch events after scrolling
49+ setIsScrolling ( false , 150 ) ;
50+ } }
3251 renderItem = { ( { item, index } ) => (
33- < LocationItem key = { index } location = { item } />
52+ < LocationItem
53+ key = { index }
54+ location = { item }
55+ navigation = { navigation }
56+ disabled = { isScrolling }
57+ />
3458 ) }
3559 />
3660 </ View >
3761 ) ;
3862} ;
3963
40- const LocationItem = ( { location } ) => {
64+ const LocationItem = ( { location, navigation, disabled } ) => {
65+ const scale = useSharedValue ( 1 ) ;
66+
67+ const animatedStyle = useAnimatedStyle ( ( ) => ( {
68+ transform : [ { scale : scale . value } ] ,
69+ } ) ) ;
70+
71+ const onPressIn = ( ) => {
72+ scale . value = withSpring ( 0.9 , { damping : 15 , stiffness : 100 } ) ;
73+ } ;
74+
75+ const onPressOut = ( ) => {
76+ scale . value = withSpring ( 1 , { damping : 15 , stiffness : 200 } ) ;
77+ if ( disabled ) return ;
78+ navigation . navigate ( "Queue" ) ; // Navigate after animation
79+ } ;
80+
81+ const AnimatedPressable = Animated . createAnimatedComponent ( Pressable ) ;
82+
4183 return (
42- < View
43- style = { {
44- flex : 1 ,
45- backgroundColor : Colors . Secondary ,
46- padding : 30 ,
47- borderRadius : 15 ,
48- margin : 10 ,
49- alignItems : "center" ,
50- } }
84+ < AnimatedPressable
85+ onPressIn = { onPressIn }
86+ onPressOut = { onPressOut }
87+ entering = { FadeIn . delay ( 300 ) . damping ( 0.5 ) . stiffness ( 100 ) }
88+ exiting = { FadeIn . delay ( 300 ) . damping ( 0.5 ) . stiffness ( 100 ) }
89+ style = { [ { flex : 1 } , animatedStyle ] }
5190 >
52- < Text
53- style = { { color : Colors . Background , fontWeight : "bold" , fontSize : 14 } }
91+ < View
92+ style = { {
93+ flex : 1 ,
94+ backgroundColor : Colors . Secondary ,
95+ padding : 30 ,
96+ borderRadius : 15 ,
97+ margin : 10 ,
98+ alignItems : "center" ,
99+ } }
54100 >
55- { location }
56- </ Text >
57- </ View >
101+ < Text
102+ style = { {
103+ color : Colors . Background ,
104+ fontWeight : "bold" ,
105+ fontSize : Platform . OS === "android" ? 14 : 18 ,
106+ } }
107+ >
108+ { location }
109+ </ Text >
110+ </ View >
111+ </ AnimatedPressable >
58112 ) ;
59113} ;
60114
@@ -64,7 +118,7 @@ const styles = StyleSheet.create({
64118 container : {
65119 flex : 1 ,
66120 backgroundColor : Colors . Background ,
67- paddingTop : Platform . OS === "android" ? StatusBar . currentHeight + 20 : 0 ,
121+ paddingTop : Constants . statusBarHeight + 20 ,
68122 padding : 10 ,
69123 } ,
70124 heading : {
0 commit comments