Skip to content
Merged
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
18 changes: 9 additions & 9 deletions src/feature/photo-detail/components/SwiperPhotoList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ export default function SwiperPhotoList({
return () => window.removeEventListener('resize', updateThumbOffset);
}, [updateThumbOffset]);

// TODO : activeIndex위치 구하는 로직 고도화 필요
// useEffect(() => {
// if (!thumbSwiper || thumbSwiper.destroyed) return;
useEffect(() => {
if (!thumbSwiper || thumbSwiper.destroyed) return;

// thumbSwiper.slideTo(activeIndex);
// requestAnimationFrame(() => {
// thumbSwiper.setTranslate(thumbOffset);
// });
// }, [activeIndex, thumbOffset, thumbSwiper]);
thumbSwiper.slideTo(activeIndex);
requestAnimationFrame(() => {
thumbSwiper.setTranslate(thumbOffset);
});
}, [activeIndex, thumbOffset, thumbSwiper]);

return (
<>
Expand Down Expand Up @@ -121,8 +120,9 @@ export default function SwiperPhotoList({
initialSlide={activeIndex}
slidesPerView='auto'
spaceBetween={2}
slidesOffsetBefore={thumbOffset}
slidesOffsetAfter={thumbOffset}
Comment on lines +123 to +124
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Using both slidesOffsetBefore/slidesOffsetAfter and programmatically calling thumbSwiper.setTranslate() in the useEffect hook seems redundant and may lead to conflicting behavior or visual glitches. The useEffect hook that calls setTranslate is designed to dynamically adjust the swiper's position, which is the correct approach for centering a dynamically selected active slide. The slidesOffset... props are generally for static offsets. Using a dynamic thumbOffset value here will cause the Swiper component to re-render whenever the active slide changes, which is less performant than just updating the transform via setTranslate.

It's recommended to remove slidesOffsetBefore and slidesOffsetAfter and rely solely on the useEffect to handle the translation.

watchSlidesProgress
centeredSlides
allowTouchMove={false}
className='custom-thumb-swiper relative w-full px-3 py-2 backdrop-blur-md'
>
Expand Down
Loading