Skip to content

Instantly share code, notes, and snippets.

@sjurgis
Created May 14, 2019 20:17
Show Gist options
  • Save sjurgis/7a648811af2a99f4657b3158e43667a7 to your computer and use it in GitHub Desktop.
Save sjurgis/7a648811af2a99f4657b3158e43667a7 to your computer and use it in GitHub Desktop.
({
afterRender: function (component, helper) {
this.superAfterRender();
var targetEl = component.find("main").getElement();
var preventPullToRefreshCheckbox = true;
var preventOverscrollGlowCheckbox = false;
var preventScrollCheckbox = false;
var maybePreventPullToRefresh = false;
var lastTouchY = 0;
var touchstartHandler = function (e) {
if (e.touches.length !== 1) return;
lastTouchY = e.touches[0].clientY;
maybePreventPullToRefresh =
preventPullToRefreshCheckbox.checked &&
window.pageYOffset === 0;
};
var touchmoveHandler = function (e) {
// alert('yeeet')
var touchY = e.touches[0].clientY;
var touchYDelta = touchY - lastTouchY;
lastTouchY = touchY;
if (maybePreventPullToRefresh) {
maybePreventPullToRefresh = false;
if (touchYDelta > 0) {
e.preventDefault();
return;
}
}
if (preventScrollCheckbox.checked) {
e.preventDefault();
return;
}
if (preventOverscrollGlowCheckbox.checked) {
if (window.pageYOffset === 0 && touchYDelta > 0) {
e.preventDefault();
return;
}
}
};
targetEl.addEventListener('touchstart', touchstartHandler, {passive: false});
targetEl.addEventListener('touchmove', touchmoveHandler, {passive: false});
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment