Skip to content

Commit

Permalink
refactor normalizIndex method
Browse files Browse the repository at this point in the history
  • Loading branch information
nikkithelegendarypokemonster committed Oct 14, 2024
1 parent 73e6fe1 commit f08fdd3
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions packages/devextreme/js/__internal/ui/m_multi_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const MultiView = CollectionWidget.inherit({
return this.option('items').length;
},

_normalizeIndex(index) {
_normalizeIndex(index, direction) {
const count = this._itemsCount();

if (index < 0) {
Expand All @@ -110,7 +110,7 @@ const MultiView = CollectionWidget.inherit({
index -= count;
}

const step = this._swipeDirection > 0 ? -1 : 1;
const step = direction > 0 ? -1 : 1;

while (!this._isItemVisible(index)) {
index = (index + step) % count;
Expand Down Expand Up @@ -422,20 +422,14 @@ const MultiView = CollectionWidget.inherit({

e.maxLeftOffset = toNumber(loop || (rtl ? selectedIndex > firstAvailableIndex : selectedIndex < lastAvailableIndex));
e.maxRightOffset = toNumber(loop || (rtl ? selectedIndex < lastAvailableIndex : selectedIndex > firstAvailableIndex));

this._swipeDirection = null;
},

_swipeUpdateHandler(e) {
const { offset } = e;
const swipeDirection = sign(offset) * this._getRTLSignCorrection();

if (swipeDirection !== this._swipeDirection) {
this._swipeDirection = swipeDirection;
}

const selectedIndex = this.option('selectedIndex');
const newIndex = this._normalizeIndex(selectedIndex - swipeDirection);
const newIndex = this._normalizeIndex(selectedIndex - swipeDirection, swipeDirection);

if (selectedIndex === newIndex) {
return;
Expand Down

0 comments on commit f08fdd3

Please sign in to comment.