Skip to content

Commit

Permalink
step 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Caputo committed Dec 5, 2024
1 parent 0d13bbb commit 2981307
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions components/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Animated, {
} from "react-native-reanimated";
import { Image } from "expo-image";
import { IMG_HEIGHT, STACK_OFFSET } from "@/constants";
import { Gesture, GestureDetector } from "react-native-gesture-handler";

type ListItemProps = {
source: string;
Expand All @@ -30,6 +31,8 @@ const ListItem = ({
if (selectedIndex.value === null) {
yOffset.value = curr + index * (IMG_HEIGHT - STACK_OFFSET);
previousOffset.value = yOffset.value;
} else {
console.log(`item ${selectedIndex.value} has been tapped!`);
}
}
);
Expand All @@ -38,10 +41,20 @@ const ListItem = ({
transform: [{ translateY: yOffset.value }],
}));

const tapGesture = Gesture.Tap().onStart(() => {
if (index === selectedIndex.value) {
selectedIndex.value = null;
return;
}
selectedIndex.value = index;
});

return (
<Animated.View style={[styles.itemWrapper, rItemStyle]}>
<Image contentFit="cover" source={source} style={styles.image} />
</Animated.View>
<GestureDetector gesture={tapGesture}>
<Animated.View style={[styles.itemWrapper, rItemStyle]}>
<Image contentFit="cover" source={source} style={styles.image} />
</Animated.View>
</GestureDetector>
);
};
const styles = StyleSheet.create({
Expand Down

0 comments on commit 2981307

Please sign in to comment.