Skip to content

Commit

Permalink
Merge pull request #593 from shopgate/PWA-1745
Browse files Browse the repository at this point in the history
Fixed swiper open link actions
  • Loading branch information
devbucket committed Apr 1, 2019
2 parents 5c38dd3 + 317466f commit 46e238b
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 46e238b

Please sign in to comment.