-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
}; | ||
|
@@ -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){ | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line could be moved inside the |
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
}; | ||
|
||
|
There was a problem hiding this comment.
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).