Skip to content

Commit

Permalink
step 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Caputo committed Dec 5, 2024
1 parent 2981307 commit 5f70ca2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 21 additions & 1 deletion components/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import { ALL_IMAGES, IMG_HEIGHT, STACK_OFFSET } from "@/constants";
import ListItem from "./ListItem";
import { StyleSheet, useWindowDimensions } from "react-native";
import { Gesture, GestureDetector } from "react-native-gesture-handler";
import Animated, { useSharedValue, withDecay } from "react-native-reanimated";
import Animated, {
runOnJS,
useAnimatedReaction,
useSharedValue,
withDecay,
} from "react-native-reanimated";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { useState } from "react";

const List = () => {
const listYTranslation = useSharedValue(0);
Expand All @@ -12,7 +18,21 @@ const List = () => {
const { height } = useWindowDimensions();
const { top, bottom } = useSafeAreaInsets();

const [panEnabled, setPanEnabled] = useState(true);

useAnimatedReaction(
() => selectedIndex.value,
(current) => {
if (current !== null) {
runOnJS(setPanEnabled)(false);
} else {
runOnJS(setPanEnabled)(true);
}
}
);

const panGesture = Gesture.Pan()
.enabled(panEnabled)
.onChange(({ changeY }) => {
listYTranslation.value += changeY;
})
Expand Down
2 changes: 0 additions & 2 deletions components/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ 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 Down

0 comments on commit 5f70ca2

Please sign in to comment.