Skip to content

Commit

Permalink
fix(core): correctly destroyor create loop on breakpoints
Browse files Browse the repository at this point in the history
fixes #6967
  • Loading branch information
nolimits4web committed Aug 30, 2023
1 parent 2cf3fc2 commit 12a44fb
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/core/breakpoints/setBreakpoint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ export default function setBreakpoint() {
breakpointParams.direction && breakpointParams.direction !== params.direction;
const needsReLoop =
params.loop && (breakpointParams.slidesPerView !== params.slidesPerView || directionChanged);
const wasLoop = params.loop;

if (directionChanged && initialized) {
swiper.changeDirection();
}
extend(swiper.params, breakpointParams);

const isEnabled = swiper.params.enabled;
const hasLoop = swiper.params.loop;

Object.assign(swiper, {
allowTouchMove: swiper.params.allowTouchMove,
Expand All @@ -80,10 +82,17 @@ export default function setBreakpoint() {

swiper.emit('_beforeBreakpoint', breakpointParams);

if (needsReLoop && initialized) {
swiper.loopDestroy();
swiper.loopCreate(realIndex);
swiper.updateSlides();
if (initialized) {
if (needsReLoop) {
swiper.loopDestroy();
swiper.loopCreate(realIndex);
swiper.updateSlides();
} else if (!wasLoop && hasLoop) {
swiper.loopCreate(realIndex);
swiper.updateSlides();
} else if (wasLoop && !hasLoop) {
swiper.loopDestroy();
}
}

swiper.emit('breakpoint', breakpointParams);
Expand Down

0 comments on commit 12a44fb

Please sign in to comment.