Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/components/CarouselItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const CarouselItem = ({ animation, next, prev, swipe, state, index, maxIn
let animate = 'center';
if (index === active)
animate = 'center';
else if (index === prevActive)
else if (maxIndex>1 && index === prevActive)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution created a jitter effect where the current card would disappear and then would be replaced by the next card with a slide effect.. i have fixed that...

Suggested change
else if (maxIndex>1 && index === prevActive)
else if (index === prevActive)

{
animate = isNext ? 'leftwardExit' : 'rightwardExit';
if (active === maxIndex && index === 0) animate = 'rightwardExit';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace the code in line 117, 118 with the following

Suggested change
if (active === maxIndex && index === 0) animate = 'rightwardExit';
if (maxIndex === 1) {
if (active === maxIndex && index === 0) animate = 'leftwardExit';
if (active === 0 && index === maxIndex) animate = 'rightwardExit';
} else {
if (active === maxIndex && index === 0) animate = 'rightwardExit';
if (active === 0 && index === maxIndex) animate = 'leftwardExit';
}

Expand All @@ -120,8 +120,10 @@ export const CarouselItem = ({ animation, next, prev, swipe, state, index, maxIn
else
{
animate = index < active ? 'leftOut' : 'rightOut';
if (active === maxIndex && index === 0) animate = 'rightOut';
if (active === 0 && index === maxIndex) animate = 'leftOut'
if (maxIndex > 1) {
if (active === maxIndex && index === 0) animate = 'rightOut';
if (active === 0 && index === maxIndex) animate = 'leftOut';
}
Comment on lines +123 to +126

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (maxIndex > 1) {
if (active === maxIndex && index === 0) animate = 'rightOut';
if (active === 0 && index === maxIndex) animate = 'leftOut';
}
if (maxIndex === 1) {
if (active === maxIndex && index === 0) animate = 'leftOut';
if (active === 0 && index === maxIndex) animate = 'rightOut';
} else {
if (active === maxIndex && index === 0) animate = 'rightOut';
if (active === 0 && index === maxIndex) animate = 'leftOut';
}

}

duration = duration / 1000;
Expand All @@ -148,4 +150,4 @@ export const CarouselItem = ({ animation, next, prev, swipe, state, index, maxIn
</AnimatePresence>
</StyledItem>
)
}
}