I'm trying to animate a stack of cards moving up as the cards on the top get swiped off the deck but I cannot make the animation to run.
I try to run the animation when the number of cards on the deck changes
useEffect(() => {
LayoutAnimation.spring();
},[currentCard]);
Also, I try to run it on the function that is called on swiped completion:
function onSwipeComplete(direction) {
const item = data[currentCard];
direction === 1 ? onSwipeRigt(item) : onSwipeLeft(item);
pan.setValue({ x: 0, y: 0 });
setCurrentCard(index => index + 1);
LayoutAnimation.configureNext({
duration: 5000,
update: {
type: LayoutAnimation.Types.spring,
springDamping: 0.7
}
});
}
On the attached sandbox you will find both solutions implemented but of course I try to use one at the time.
To see the problem jump into the sandbox if you swipe the top card left or right you will notice that the cards bellow snap to the top, instead I want to slowly animate it to the top.
https://codesandbox.io/s/react-native-deckj-z1nwb?file=/src/Deck.js