Skip to content

Commit 894d8cb

Browse files
committed
feat: adjust whiffing the card into the deck
1 parent 7a194c9 commit 894d8cb

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

src/app/Components/FancySwiper/FancySwiper.tsx

+19-5
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,18 @@ export const FancySwiper = ({
3434
}: FancySwiperProps) => {
3535
const remainingCards = useMemo(() => cards.reverse(), [cards.length])
3636
const swiper = useRef<Animated.ValueXY>(new Animated.ValueXY()).current
37+
const swiperSwipedCard = useRef<Animated.ValueXY>(new Animated.ValueXY()).current
3738

3839
const panResponder = PanResponder.create({
3940
onStartShouldSetPanResponder: () => true,
4041
onPanResponderMove: (_, { dx, dy, x0 }) => {
4142
// if we're 25% left of the screen when swiping then we update normally
4243
if (x0 <= whiffHitSlop) {
43-
swiper.setValue({ x: dx, y: dy })
44-
// otherwise we clamp the dragging to avoid up/down/right movement
44+
swiperSwipedCard.setValue({ x: dx, y: dy })
4545
} else {
46+
// otherwise we clamp the dragging to avoid up/down/right movement
4647
swiper.setValue({ x: Math.min(dx, 0), y: 0 })
4748
}
48-
// works but not allows a nice whiff
49-
// swiper.setValue({ x: Math.min(dx, 0), y: 0 })
5049
},
5150
onPanResponderRelease: (_, { dx, dy, x0 }) => {
5251
const isFullSwipe = Math.abs(dx) > SWIPE_MAGNITUDE
@@ -84,6 +83,7 @@ export const FancySwiper = ({
8483
}).start(() => {
8584
// revert the pan responder to its initial position
8685
swiper.setValue({ x: 0, y: 0 })
86+
swiperSwipedCard.setValue({ x: -width, y: 0 })
8787
onSwipeLeft()
8888
})
8989
}
@@ -102,8 +102,21 @@ export const FancySwiper = ({
102102
}
103103

104104
const handleRightWhiff = () => {
105-
swiper.setValue({ x: 0, y: 0 })
105+
// swiper.setValue({ x: 0, y: 0 })
106+
swiperSwipedCard.setValue({ x: 0, y: 0 })
106107
onWhiffRight?.()
108+
// Animated.timing(swiperSwipedCard, {
109+
// easing: Easing.cubic,
110+
// toValue: { x: 0, y: 0 },
111+
// duration: 300,
112+
// useNativeDriver: true,
113+
// }).start(() => {
114+
// swiper.setValue({ x: 0, y: 0 })
115+
// swiperSwipedCard.setValue({ x: 0, y: 0 })
116+
// onWhiffRight?.()
117+
// })
118+
// swiper.setValue({ x: 0, y: 0 })
119+
// onWhiffRight?.()
107120
}
108121

109122
return (
@@ -126,6 +139,7 @@ export const FancySwiper = ({
126139
key={card.artworkId}
127140
artworkId={card.artworkId}
128141
swiper={swiper}
142+
swiperSwipedCard={swiperSwipedCard}
129143
isTopCard={isTopCard}
130144
isSecondCard={isSecondCard}
131145
isSwipedCard={isSwipedCard}

src/app/Components/FancySwiper/FancySwiperCard.tsx

+8-6
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ interface FancySwiperCardProps extends GestureResponderHandlers {
1111
isSwipedCard: boolean
1212
isLastSwipedCard: boolean
1313
swiper: Animated.ValueXY
14+
swiperSwipedCard: Animated.ValueXY
1415
}
1516

1617
export const FancySwiperCard = memo(
1718
({
18-
artworkId,
1919
card,
2020
swiper,
21+
swiperSwipedCard,
2122
isTopCard,
2223
isSecondCard,
2324
isSwipedCard,
@@ -33,7 +34,6 @@ export const FancySwiperCard = memo(
3334
let swipedCardTransform = undefined
3435

3536
if (isTopCard) {
36-
console.log("cb::isTopCard", artworkId)
3737
// tilt the top card as it is being swiped away
3838
const rotate = swiper.x.interpolate({
3939
inputRange: [-SWIPE_MAGNITUDE, 0],
@@ -80,14 +80,13 @@ export const FancySwiperCard = memo(
8080
transform: [{ scale }],
8181
}
8282
} else if (isLastSwipedCard) {
83-
console.log("cb::isLastSwiperCard", artworkId)
84-
const rotate = swiper.x.interpolate({
83+
const rotate = swiperSwipedCard.x.interpolate({
8584
inputRange: [0, SWIPE_MAGNITUDE],
8685
outputRange: ["-5deg", "0deg"],
8786
extrapolate: "clamp",
8887
})
8988

90-
const translateX = swiper.x.interpolate({
89+
const translateX = swiperSwipedCard.x.interpolate({
9190
inputRange: [0, SWIPE_MAGNITUDE],
9291
outputRange: [-screenWidth, 0],
9392
extrapolate: "clamp",
@@ -96,8 +95,11 @@ export const FancySwiperCard = memo(
9695
swipedCardTransform = {
9796
transform: [{ translateX }, { rotate }],
9897
}
98+
99+
// swipedCardTransform = {
100+
// transform: [...swiperSwipedCard.getTranslateTransform(), { rotate }],
101+
// }
99102
} else if (isSwipedCard) {
100-
console.log("cb::isSwipedCard", artworkId)
101103
swipedCardTransform = {
102104
transform: [{ translateX: -screenWidth }, { translateY: 0 }],
103105
}

src/app/Scenes/InfiniteDiscovery/InfiniteDiscovery.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const InfiniteDiscovery: React.FC<InfiniteDiscoveryProps> = ({
9191
if (currentIndex < artworks.length - 1) {
9292
const dismissedArtworkId = artworks[currentIndex].internalID
9393

94-
setCurrentIndex(currentIndex + 1)
94+
setCurrentIndex((prev) => prev + 1)
9595
addDisoveredArtworkId(dismissedArtworkId)
9696

9797
trackEvent({
@@ -114,8 +114,6 @@ export const InfiniteDiscovery: React.FC<InfiniteDiscoveryProps> = ({
114114
})
115115
}
116116
setMaxIndexReached(newMaxIndexReached)
117-
118-
setCurrentIndex((prev) => prev + 1)
119117
}
120118

121119
// fetch more artworks when the user is about to reach the end of the list

0 commit comments

Comments
 (0)