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

Commit

Permalink
ScrollController and FlexScrollView now only process paginated fast s…
Browse files Browse the repository at this point in the history
…wipes when they are in the configured direction.
  • Loading branch information
IjzerenHein committed Nov 13, 2015
1 parent 49d8acb commit 37f3da2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
20 changes: 10 additions & 10 deletions src/FlexScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,51 +522,51 @@ define(function(require, exports, module) {
* Delegates any scroll force to leading/trailing scrollviews.
* @private
*/
FlexScrollView.prototype.releaseScrollForce = function(delta, velocity) {
FlexScrollView.prototype.releaseScrollForce = function(delta, velocity, detectSwipes) {
var leadingScrollView = this.options.leadingScrollView;
var trailingScrollView = this.options.trailingScrollView;
if (!leadingScrollView && !trailingScrollView) {
return ScrollController.prototype.releaseScrollForce.call(this, delta, velocity);
return ScrollController.prototype.releaseScrollForce.call(this, delta, velocity, detectSwipes);
}
var partialDelta;
if (delta < 0) {
if (leadingScrollView) {
partialDelta = Math.max(this._leadingScrollViewDelta, delta);
this._leadingScrollViewDelta -= partialDelta;
delta -= partialDelta;
leadingScrollView.releaseScrollForce(this._leadingScrollViewDelta, delta ? 0 : velocity);
leadingScrollView.releaseScrollForce(this._leadingScrollViewDelta, delta ? 0 : velocity, detectSwipes);
}
if (trailingScrollView) {
partialDelta = Math.max(this._thisScrollViewDelta, delta);
this._thisScrollViewDelta -= partialDelta;
delta -= partialDelta;
ScrollController.prototype.releaseScrollForce.call(this, this._thisScrollViewDelta, delta ? 0 : velocity);
ScrollController.prototype.releaseScrollForce.call(this, this._thisScrollViewDelta, delta ? 0 : velocity, detectSwipes);
this._trailingScrollViewDelta -= delta;
trailingScrollView.releaseScrollForce(this._trailingScrollViewDelta, delta ? velocity : 0);
trailingScrollView.releaseScrollForce(this._trailingScrollViewDelta, delta ? velocity : 0, detectSwipes);
}
else {
this._thisScrollViewDelta -= delta;
ScrollController.prototype.releaseScrollForce.call(this, this._thisScrollViewDelta, delta ? velocity : 0);
ScrollController.prototype.releaseScrollForce.call(this, this._thisScrollViewDelta, delta ? velocity : 0, detectSwipes);
}
}
else {
if (trailingScrollView) {
partialDelta = Math.min(this._trailingScrollViewDelta, delta);
this._trailingScrollViewDelta -= partialDelta;
delta -= partialDelta;
trailingScrollView.releaseScrollForce(this._trailingScrollViewDelta, delta ? 0 : velocity);
trailingScrollView.releaseScrollForce(this._trailingScrollViewDelta, delta ? 0 : velocity, detectSwipes);
}
if (leadingScrollView) {
partialDelta = Math.min(this._thisScrollViewDelta, delta);
this._thisScrollViewDelta -= partialDelta;
delta -= partialDelta;
ScrollController.prototype.releaseScrollForce.call(this, this._thisScrollViewDelta, delta ? 0 : velocity);
ScrollController.prototype.releaseScrollForce.call(this, this._thisScrollViewDelta, delta ? 0 : velocity, detectSwipes);
this._leadingScrollViewDelta -= delta;
leadingScrollView.releaseScrollForce(this._leadingScrollViewDelta, delta ? velocity : 0);
leadingScrollView.releaseScrollForce(this._leadingScrollViewDelta, delta ? velocity : 0, detectSwipes);
}
else {
this._thisScrollViewDelta -= delta;
ScrollController.prototype.updateScrollForce.call(this, this._thisScrollViewDelta, delta ? velocity : 0);
ScrollController.prototype.updateScrollForce.call(this, this._thisScrollViewDelta, delta ? velocity : 0, detectSwipes);
}
}
return this;
Expand Down
12 changes: 8 additions & 4 deletions src/ScrollController.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,9 @@ define(function(require, exports, module) {
}

// Release scroll force
this.releaseScrollForce(this._scroll.mouseMove.delta, velocity);
var swipeDirection = (Math.abs(this._scroll.mouseMove.current[0] - this._scroll.mouseMove.prev[0]) > Math.abs(this._scroll.mouseMove.current[1] - this._scroll.mouseMove.prev[1])) ? 0 : 1;
var allowSwipes = (swipeDirection === this._direction);
this.releaseScrollForce(this._scroll.mouseMove.delta, velocity, allowSwipes);
this._scroll.mouseMove = undefined;
}

Expand Down Expand Up @@ -609,7 +611,9 @@ define(function(require, exports, module) {

// Release scroll force
var delta = this._scroll.touchDelta;
this.releaseScrollForce(delta, velocity);
var swipeDirection = (Math.abs(primaryTouch.current[0] - primaryTouch.prev[0]) > Math.abs(primaryTouch.current[1] - primaryTouch.prev[1])) ? 0 : 1;
var allowSwipes = (swipeDirection === this._direction);
this.releaseScrollForce(delta, velocity, allowSwipes);
this._scroll.touchDelta = 0;
}

Expand Down Expand Up @@ -1651,7 +1655,7 @@ define(function(require, exports, module) {
* @param {Number} [velocity] Velocity to apply after which the view keeps scrolling
* @return {ScrollController} this
*/
ScrollController.prototype.releaseScrollForce = function(delta, velocity) {
ScrollController.prototype.releaseScrollForce = function(delta, velocity, detectSwipes) {
this.halt();
if (this._scroll.scrollForceCount === 1) {
var scrollOffset = _calcScrollOffset.call(this);
Expand All @@ -1665,7 +1669,7 @@ define(function(require, exports, module) {
if (item.renderNode !== this._scroll.scrollForceStartItem.renderNode) {
this.goToRenderNode(item.renderNode);
}
else if (this.options.paginationEnergyThreshold && (Math.abs(this._scroll.particle.getEnergy()) >= this.options.paginationEnergyThreshold)) {
else if (detectSwipes && this.options.paginationEnergyThreshold && (Math.abs(this._scroll.particle.getEnergy()) >= this.options.paginationEnergyThreshold)) {
velocity = velocity || 0;
if ((velocity < 0) && item._node._next && item._node._next.renderNode) {
this.goToRenderNode(item._node._next.renderNode);
Expand Down

0 comments on commit 37f3da2

Please sign in to comment.