Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Scroll Locking in ion-content/ion-scroll #2849

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion js/views/scrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ ionic.views.Scroll = ionic.views.View.inherit({
self.__isSelectable = true;
self.__enableScrollY = true;
self.__hasStarted = true;
self.__scrollLockFix = {direction: null, doFix: false};
self.doTouchStart(getEventTouches(e), e.timeStamp);
e.preventDefault();
};
Expand Down Expand Up @@ -772,7 +773,21 @@ ionic.views.Scroll = ionic.views.View.inherit({
}
}

self.doTouchMove(getEventTouches(e), e.timeStamp, e.scale);
if(self.options.locking && self.__scrollLockFix.direction === null){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could swap self.__scrollLockFix.direction === null for !self.__scrollLockFix.doFix (slightly less verbose and ("nit-pickingly") slightly more performant).

var detect = 5,
dx = Math.abs(e.touches[0].pageX - self.__initialTouchLeft), dy = Math.abs(e.touches[0].pageY - self.__initialTouchTop);
if(dx > detect || dy > detect){
self.__scrollLockFix.direction = dx > dy;
self.__scrollLockFix.doFix = true;
}
}
var dir = self.__scrollLockFix.direction;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line could be moved inside the if block (since it's not used otherwise).

if(self.__scrollLockFix.doFix){
self.doTouchMove([{pageX: dir ? e.touches[0].pageX : self.__initialTouchLeft, pageY: dir ? self.__initialTouchTop : e.touches[0].pageY}], e.timeStamp, e.scale);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is too long. I would refactor it into something like below (but it's obviously a matter of a personal preference 😃):

var coords = dir ?
    {pageX: e.touches[0].pageX, pageY: self.__initialTouchTop} :
    {pageX: self.__initialTouchLeft, pageY: e.touches[0].pageY};
self.doTouchMove([coords], e.timeStamp, e.scale);

}else{
self.doTouchMove(getEventTouches(e), e.timeStamp, e.scale);
}

self.__isDown = true;
};

Expand Down