diff --git a/src/screens/home/index.tsx b/src/screens/home/index.tsx index 02005de..097face 100644 --- a/src/screens/home/index.tsx +++ b/src/screens/home/index.tsx @@ -1,6 +1,14 @@ import * as React from 'react'; import styles from './styles'; -import {View, Text, StatusBar, FlatList} from 'react-native'; +import { + View, + Text, + StatusBar, + FlatList, + Animated, + Dimensions, + Pressable, +} from 'react-native'; import Colors from '../../../assets/styles/Colors'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import {NativeStackNavigationProp} from '@react-navigation/native-stack'; @@ -12,20 +20,112 @@ import GuidebookIcon from '../../../assets/icons/guidebook.svg'; import EazyPassportIcon from '../../../assets/icons/eazy_passport.svg'; import passportAppointmentData from '../../data/History/PassportAppointmentData'; import PassportAppointmentCard from '../../components/PassportAppointmentCard'; +import {useRef} from 'react'; type HomeScreenNavigationProp = NativeStackNavigationProp< RootStackParamList, 'Home' >; +const {width} = Dimensions.get('window'); +const ITEM_WIDTH = width * 0.8; +const ITEM_SPACING = (width - ITEM_WIDTH) / 2; +const FIRST_ITEM_SPACING = 16; + +const data = [1, 2, 3, 4]; + const ItemSeparator = () => ; const RenderContent = () => { const navigation = useNavigation(); + const scrollX = useRef(new Animated.Value(0)).current; return ( <> - + + item.toString()} + horizontal + showsHorizontalScrollIndicator={false} + snapToInterval={ITEM_WIDTH} + decelerationRate="fast" + bounces={false} + ListHeaderComponent={} + ListFooterComponent={} + onScroll={Animated.event( + [{nativeEvent: {contentOffset: {x: scrollX}}}], + {useNativeDriver: true}, + )} + scrollEventThrottle={16} + renderItem={({index}) => { + const inputRange = [ + (index - 1) * ITEM_WIDTH, + index * ITEM_WIDTH, + (index + 1) * ITEM_WIDTH, + ]; + + const scale = scrollX.interpolate({ + inputRange, + outputRange: [0.875, 1, 0.875], + extrapolate: 'clamp', + }); + + const opacity = scrollX.interpolate({ + inputRange, + outputRange: [0.5, 1, 0.5], + extrapolate: 'clamp', + }); + + return ( + + + + ); + }} + /> + + {data.map((_, i) => { + const inputRange = [ + (i - 1) * ITEM_WIDTH, + i * ITEM_WIDTH, + (i + 1) * ITEM_WIDTH, + ]; + + const dotOpacity = scrollX.interpolate({ + inputRange, + outputRange: [0.3, 1, 0.3], + extrapolate: 'clamp', + }); + + const dotScale = scrollX.interpolate({ + inputRange, + outputRange: [0.8, 1.2, 0.8], + extrapolate: 'clamp', + }); + + return ( + + ); + })} + + Layanan @@ -58,11 +158,13 @@ const RenderContent = () => { Status Permohonan - navigation.navigate('History')}> - Lihat semua - + navigation.navigate('History')} + style={({pressed}) => ({ + transform: [{scale: pressed ? 0.925 : 1}], + })}> + Lihat semua +