Skip to content

Commit

Permalink
fix(esl-carousel): carousel now uses average of the real slide sizes …
Browse files Browse the repository at this point in the history
…during move action routines

Co-authored-by: Anna Barmina <abarmina@exadel.com>
  • Loading branch information
ala-n and abarmina committed Jul 30, 2024
1 parent 537db39 commit 2472723
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ export class ESLDefaultCarouselRenderer extends ESLCarouselRenderer {

/** Slides gap size */
protected gap: number = 0;
/** Slide size cached value */
protected slideSize: number = 0;
/** First index of active slides. */
protected currentIndex: number = 0;

/** Actual slide size (uses average) */
protected get slideSize(): number {
return this.$slides.reduce((size, $slide) => {
return size + (this.vertical ? $slide.offsetHeight : $slide.offsetWidth);
}, 0) / this.$slides.length;
}

/**
* Processes binding of defined renderer to the carousel {@link ESLCarousel}.
* Prepare to renderer animation.
Expand Down Expand Up @@ -210,7 +215,7 @@ export class ESLDefaultCarouselRenderer extends ESLCarouselRenderer {

this.gap = parseFloat(this.vertical ? areaStyles.rowGap : areaStyles.columnGap);
const areaSize = parseFloat(this.vertical ? areaStyles.height : areaStyles.width);
this.slideSize = Math.floor((areaSize - this.gap * (this.count - 1)) / this.count);
this.$area.style.setProperty(ESLDefaultCarouselRenderer.SIZE_PROP, this.slideSize + 'px');
const slideSize = Math.floor((areaSize - this.gap * (this.count - 1)) / this.count);
this.$area.style.setProperty(ESLDefaultCarouselRenderer.SIZE_PROP, slideSize + 'px');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class ESLGridCarouselRenderer extends ESLDefaultCarouselRenderer {
this.gap = parseFloat(this.vertical ? areaStyles.rowGap : areaStyles.columnGap);
const areaSize = parseFloat(this.vertical ? areaStyles.height : areaStyles.width);
const count = Math.floor(this.count / this.ROWS);
this.slideSize = Math.floor((areaSize - this.gap * (count - 1)) / count);
this.$area.style.setProperty(ESLDefaultCarouselRenderer.SIZE_PROP, this.slideSize + 'px');
const slideSize = Math.floor((areaSize - this.gap * (count - 1)) / count);
this.$area.style.setProperty(ESLDefaultCarouselRenderer.SIZE_PROP, slideSize + 'px');
}
}

0 comments on commit 2472723

Please sign in to comment.