Skip to content

Commit

Permalink
PWA-1745: Fixed swiper, so that loops function properly by manually s…
Browse files Browse the repository at this point in the history
…witching to the correct react slide, when a duplicated is about to be shown.
  • Loading branch information
SG-Noxoreos committed Apr 1, 2019
1 parent 5c38dd3 commit 317466f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions libraries/common/components/Swiper/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,29 @@ function Swiper(props) {
disabled,
} = props;

/** @type {Swiper} swiper An instance of the Swiper. */
const [swiper, setSwiper] = useState(null);

useEffect(() => {
if (swiper !== null) {
swiper.update();
swiper.on('slideChange', () => onSlideChange(swiper.realIndex));
swiper.on('transitionEnd', () => {
// In loop mode the Swiper duplicates elements, which are not in the virtual DOM
if (loop) {
// Skip duplicated elements
if (swiper.activeIndex < 1) {
swiper.slideToLoop(children.length - 1, 0);
} else if (swiper.activeIndex > children.length) {
swiper.slideToLoop(0, 0);
}
}
});
swiper.on('beforeDestroy', () => {
swiper.off('slideChange');
swiper.off('transitionEnd');
swiper.off('beforeDestroy');
});
}
}, [swiper]);

Expand Down

0 comments on commit 317466f

Please sign in to comment.