From 82bcc5cc2ed3dc5c7995df45cfee1d76ed170139 Mon Sep 17 00:00:00 2001 From: Vladimir Kharlampidi Date: Tue, 2 Mar 2021 16:42:11 +0300 Subject: [PATCH] fix(lazy): fixed issue with lazy loading when freeMode stops without momentum fixes #4274 fixes #4275 --- src/components/core/events/onTouchEnd.js | 3 +++ src/components/lazy/lazy.js | 7 +------ src/types/swiper-events.d.ts | 14 +++++++++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/components/core/events/onTouchEnd.js b/src/components/core/events/onTouchEnd.js index f725becc3..dac768168 100644 --- a/src/components/core/events/onTouchEnd.js +++ b/src/components/core/events/onTouchEnd.js @@ -231,6 +231,7 @@ export default function onTouchEnd(event) { }); } } else { + swiper.emit('_freeModeNoMomentumRelease'); swiper.updateProgress(newPosition); } @@ -239,6 +240,8 @@ export default function onTouchEnd(event) { } else if (params.freeModeSticky) { swiper.slideToClosest(); return; + } else if (params.freeMode) { + swiper.emit('_freeModeNoMomentumRelease'); } if (!params.freeModeMomentum || timeDiff >= params.longSwipesMs) { diff --git a/src/components/lazy/lazy.js b/src/components/lazy/lazy.js index 166106b7b..c6cf57cf1 100644 --- a/src/components/lazy/lazy.js +++ b/src/components/lazy/lazy.js @@ -257,12 +257,7 @@ export default { swiper.lazy.load(); } }, - resize(swiper) { - if (swiper.params.lazy.enabled) { - swiper.lazy.load(); - } - }, - scrollbarDragMove(swiper) { + 'scrollbarDragMove resize _freeModeNoMomentumRelease': function lazyLoad(swiper) { if (swiper.params.lazy.enabled) { swiper.lazy.load(); } diff --git a/src/types/swiper-events.d.ts b/src/types/swiper-events.d.ts index 5a70d67f7..dab447765 100644 --- a/src/types/swiper-events.d.ts +++ b/src/types/swiper-events.d.ts @@ -215,17 +215,19 @@ export interface SwiperEvents { * !INTERNAL: Event will fired right before breakpoint change */ _beforeBreakpoint?: (swiper: Swiper, breakpointParams: SwiperOptions) => void; + /** * !INTERNAL: Event will fired after setting CSS classes on swiper container element */ _containerClasses?: (swiper: Swiper, classNames: string) => void; + /** - * INTERNAL: Event will fired after setting CSS classes on swiper slide element + * !INTERNAL: Event will fired after setting CSS classes on swiper slide element */ _slideClass?: (swiper: Swiper, el: HTMLElement, classNames: string) => void; /** - * INTERNAL: Event will fired after setting CSS classes on all swiper slides + * !INTERNAL: Event will fired after setting CSS classes on all swiper slides */ _slideClasses?: ( swiper: Swiper, @@ -233,9 +235,15 @@ export interface SwiperEvents { ) => void; /** - * INTERNAL: Event will fired as soon as swiper instance available (before init) + * !INTERNAL: Event will fired as soon as swiper instance available (before init) */ _swiper?: (swiper: Swiper) => void; + + /** + * !INTERNAL: Event will be fired on free mode touch end (release) and there will no be momentum + */ + _freeModeNoMomentumRelease?: (swiper: Swiper) => void; + /** * Event will fired on active index change */