Skip to content

Commit

Permalink
feat(core): watchSlidesProgress and watchSlidesVisibility merged …
Browse files Browse the repository at this point in the history
…into single `watchSlidesProgress`
  • Loading branch information
nolimits4web committed Aug 6, 2021
1 parent 1bad048 commit 33dbf62
Show file tree
Hide file tree
Showing 16 changed files with 18 additions and 53 deletions.
1 change: 0 additions & 1 deletion src/angular/src/swiper.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ export class SwiperComponent implements OnInit {
@Input() resistance: SwiperOptions['resistance'];
@Input() resistanceRatio: SwiperOptions['resistanceRatio'];
@Input() watchSlidesProgress: SwiperOptions['watchSlidesProgress'];
@Input() watchSlidesVisibility: SwiperOptions['watchSlidesVisibility'];
@Input() grabCursor: SwiperOptions['grabCursor'];
@Input() preventClicks: SwiperOptions['preventClicks'];
@Input() preventClicksPropagation: SwiperOptions['preventClicksPropagation'];
Expand Down
1 change: 0 additions & 1 deletion src/angular/src/utils/params-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export const paramsList = [
'_resistance',
'_resistanceRatio',
'_watchSlidesProgress',
'_watchSlidesVisibility',
'_grabCursor',
'preventClicks',
'preventClicksPropagation',
Expand Down
1 change: 0 additions & 1 deletion src/core/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export default {

// Progress
watchSlidesProgress: false,
watchSlidesVisibility: false,

// Cursor
grabCursor: false,
Expand Down
3 changes: 1 addition & 2 deletions src/core/events/onTouchMove.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ export default function onTouchMove(event) {
// Update active index in free mode
if (
(params.freeMode && params.freeMode.enabled && swiper.freeMode) ||
params.watchSlidesProgress ||
params.watchSlidesVisibility
params.watchSlidesProgress
) {
swiper.updateActiveIndex();
swiper.updateSlidesClasses();
Expand Down
6 changes: 1 addition & 5 deletions src/core/update/updateProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ export default function updateProgress(translate) {
isEnd,
});

if (
params.watchSlidesProgress ||
params.watchSlidesVisibility ||
(params.centeredSlides && params.autoHeight)
)
if (params.watchSlidesProgress || (params.centeredSlides && params.autoHeight))
swiper.updateSlidesProgress(translate);

if (isBeginning && !wasBeginning) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/update/updateSlides.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export default function updateSlides() {
swiper.emit('slidesGridLengthChange');
}

if (params.watchSlidesProgress || params.watchSlidesVisibility) {
if (params.watchSlidesProgress) {
swiper.updateSlidesOffset();
}
}
22 changes: 10 additions & 12 deletions src/core/update/updateSlidesProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@ export default function updateSlidesProgress(translate = (this && this.translate
(params.centeredSlides ? swiper.minTranslate() : 0) -
slide.swiperSlideOffset) /
(slide.swiperSlideSize + params.spaceBetween);
if (params.watchSlidesVisibility || (params.centeredSlides && params.autoHeight)) {
const slideBefore = -(offsetCenter - slide.swiperSlideOffset);
const slideAfter = slideBefore + swiper.slidesSizesGrid[i];
const isVisible =
(slideBefore >= 0 && slideBefore < swiper.size - 1) ||
(slideAfter > 1 && slideAfter <= swiper.size) ||
(slideBefore <= 0 && slideAfter >= swiper.size);
if (isVisible) {
swiper.visibleSlides.push(slide);
swiper.visibleSlidesIndexes.push(i);
slides.eq(i).addClass(params.slideVisibleClass);
}
const slideBefore = -(offsetCenter - slide.swiperSlideOffset);
const slideAfter = slideBefore + swiper.slidesSizesGrid[i];
const isVisible =
(slideBefore >= 0 && slideBefore < swiper.size - 1) ||
(slideAfter > 1 && slideAfter <= swiper.size) ||
(slideBefore <= 0 && slideAfter >= swiper.size);
if (isVisible) {
swiper.visibleSlides.push(slide);
swiper.visibleSlidesIndexes.push(i);
slides.eq(i).addClass(params.slideVisibleClass);
}
slide.progress = rtl ? -slideProgress : slideProgress;
}
Expand Down
1 change: 0 additions & 1 deletion src/modules/effect-coverflow/effect-coverflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export default function Coverflow({ swiper, extendParams, on }) {
swiper.classNames.push(`${swiper.params.containerModifierClass}coverflow`);
swiper.classNames.push(`${swiper.params.containerModifierClass}3d`);

swiper.params.watchSlidesProgress = true;
swiper.originalParams.watchSlidesProgress = true;
});
on('setTranslate', () => {
Expand Down
16 changes: 4 additions & 12 deletions src/modules/lazy/lazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export default function Lazy({ swiper, extendParams, on, emit }) {
}

if (!initialImageLoaded) initialImageLoaded = true;
if (swiper.params.watchSlidesVisibility) {
if (swiper.params.watchSlidesProgress) {
$wrapperEl.children(`.${swiperParams.slideVisibleClass}`).each((slideEl) => {
const index = isVirtual ? $(slideEl).attr('data-swiper-slide-index') : $(slideEl).index();
loadInSlide(index);
Expand Down Expand Up @@ -279,19 +279,11 @@ export default function Lazy({ swiper, extendParams, on, emit }) {
}
});
on('slideChange', () => {
const {
lazy,
cssMode,
watchSlidesVisibility,
watchSlidesProgress,
touchReleaseOnEdges,
resistanceRatio,
} = swiper.params;
const { lazy, cssMode, watchSlidesProgress, touchReleaseOnEdges, resistanceRatio } =
swiper.params;
if (
lazy.enabled &&
(cssMode ||
((watchSlidesVisibility || watchSlidesProgress) &&
(touchReleaseOnEdges || resistanceRatio === 0)))
(cssMode || (watchSlidesProgress && (touchReleaseOnEdges || resistanceRatio === 0)))
) {
load();
}
Expand Down
1 change: 0 additions & 1 deletion src/modules/thumbs/thumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export default function Thumb({ swiper, extendParams, on }) {
} else if (isObject(thumbsParams.swiper)) {
const thumbsSwiperParams = Object.assign({}, thumbsParams.swiper);
Object.assign(thumbsSwiperParams, {
watchSlidesVisibility: true,
watchSlidesProgress: true,
slideToClickedSlide: false,
});
Expand Down
1 change: 0 additions & 1 deletion src/react/params-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const paramsList = [
'_resistance',
'_resistanceRatio',
'_watchSlidesProgress',
'_watchSlidesVisibility',
'_grabCursor',
'preventClicks',
'preventClicksPropagation',
Expand Down
1 change: 0 additions & 1 deletion src/svelte/params-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const paramsList = [
'_resistance',
'_resistanceRatio',
'_watchSlidesProgress',
'_watchSlidesVisibility',
'_grabCursor',
'preventClicks',
'preventClicksPropagation',
Expand Down
9 changes: 1 addition & 8 deletions src/types/swiper-options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,19 +559,12 @@ export interface SwiperOptions {

// Progress
/**
* Enable this feature to calculate each slides progress
* Enable this feature to calculate each slides progress and visibility (slides in viewport will have additional visible class)
*
* @default false
*/
watchSlidesProgress?: boolean;

/**
* `watchSlidesProgress` should be enabled. Enable this option and slides that are in viewport will have additional visible class
*
* @default false
*/
watchSlidesVisibility?: boolean;

// Images
/**
* When enabled Swiper will force to load all images
Expand Down
1 change: 0 additions & 1 deletion src/vue/params-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const paramsList = [
'_resistance',
'_resistanceRatio',
'_watchSlidesProgress',
'_watchSlidesVisibility',
'_grabCursor',
'preventClicks',
'preventClicksPropagation',
Expand Down
4 changes: 0 additions & 4 deletions src/vue/swiper-vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,6 @@ declare const Swiper: DefineComponent<
type: BooleanConstructor;
default: undefined;
};
watchSlidesVisibility: {
type: BooleanConstructor;
default: undefined;
};
grabCursor: {
type: BooleanConstructor;
default: undefined;
Expand Down
1 change: 0 additions & 1 deletion src/vue/swiper.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ const Swiper = {
resistance: { type: Boolean, default: undefined },
resistanceRatio: { type: Number, default: undefined },
watchSlidesProgress: { type: Boolean, default: undefined },
watchSlidesVisibility: { type: Boolean, default: undefined },
grabCursor: { type: Boolean, default: undefined },
preventClicks: { type: Boolean, default: undefined },
preventClicksPropagation: { type: Boolean, default: undefined },
Expand Down

0 comments on commit 33dbf62

Please sign in to comment.