Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Bug 1015509 - [B2G][Vertical Homescreen] Home screen scroll speed doe…
Browse files Browse the repository at this point in the history
…s not change based on how close icon is to edge of screen r=kgrandon
  • Loading branch information
crdlc authored and KevinGrandon committed May 28, 2014
1 parent 02026a5 commit b536b42
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions shared/elements/gaia_grid/js/grid_dragdrop.js
Expand Up @@ -12,6 +12,13 @@
* within a length of a page edge configured by this value */
const edgePageThreshold = 50;

const screenHeight = window.innerHeight;

const scrollStep = Math.round(screenHeight / edgePageThreshold);

/* The scroll step will be 10 times bigger over the edge */
const maxScrollStepFactor = 10;

function DragDrop(gridView) {
this.gridView = gridView;
this.container = gridView.element;
Expand Down Expand Up @@ -107,6 +114,22 @@
this.container.classList.remove('dragging');
},

/**
* The closer to edge the faster (bigger step).
** Distance 0px -> 10 times faster
** Distance 25px -> 5 times faster
** Distance 50px (edgePageThreshold) -> 0 times
*/
getScrollStep: function(distanceToEdge) {
var factor = maxScrollStepFactor;

if (distanceToEdge > 0) {
factor *= ((edgePageThreshold - distanceToEdge) / edgePageThreshold);
}

return Math.round(scrollStep * factor);
},

/**
* Scrolls the page if needed.
* The page is scrolled via javascript if an icon is being moved,
Expand All @@ -120,9 +143,6 @@
return;
}

var screenHeight = window.innerHeight;
var scrollStep = Math.round(screenHeight / edgePageThreshold);

function doScroll(amount) {
/* jshint validthis:true */
this.isScrolling = true;
Expand All @@ -133,18 +153,19 @@
}

var docScroll = document.documentElement.scrollTop;
if (touch.pageY - docScroll > screenHeight - edgePageThreshold) {
var distanceFromTop = Math.abs(touch.pageY - docScroll);
if (distanceFromTop > screenHeight - edgePageThreshold) {
var maxY = this.maxScroll;
var scrollStep = this.getScrollStep(screenHeight - distanceFromTop);
// We cannot exceed the maximum scroll value
if (touch.pageY >= maxY || maxY - touch.pageY < scrollStep) {
this.isScrolling = false;
return;
}

doScroll.call(this, scrollStep);
} else if (touch.pageY > 0 &&
touch.pageY - docScroll < edgePageThreshold) {
doScroll.call(this, 0 - scrollStep);
} else if (touch.pageY > 0 && distanceFromTop < edgePageThreshold) {
doScroll.call(this, 0 - this.getScrollStep(distanceFromTop));
} else {
this.isScrolling = false;
}
Expand Down

0 comments on commit b536b42

Please sign in to comment.