From 28c1f81f4a16034109214929e56ddfe650bdd920 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sun, 27 Apr 2014 11:18:04 -0400 Subject: [PATCH] appDisplay: Make page panning smoother on touch Currently, our logic for page panning isn't great. If the user starts a pan upwards and hesitates over a new page, we'll go to the *next* page on release, since the difference is greater, but the velocity wound down to 0. Instead of trying to treat it like page down or scrolls, simply do the math to find the page where the user scrolled to. This is unfortunately broken for fast swipes, since the user doesn't get far enough into the new page to make a difference. I'm getting the impression we'll need a gesture recognizer for this, though, however crude. Simple hacks I tried, like a velocity multiplier, didn't work properly. https://bugzilla.gnome.org/show_bug.cgi?id=729064 --- js/ui/appDisplay.js | 26 ++++++++++++++------------ js/ui/iconGrid.js | 4 ++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js index 0f5baf82c..e04c59ac1 100644 --- a/js/ui/appDisplay.js +++ b/js/ui/appDisplay.js @@ -41,9 +41,7 @@ const MIN_FREQUENT_APPS_COUNT = 3; const INDICATORS_BASE_TIME = 0.25; const INDICATORS_ANIMATION_DELAY = 0.125; const INDICATORS_ANIMATION_MAX_TIME = 0.75; -// Fraction of page height the finger or mouse must reach -// to change page -const PAGE_SWITCH_TRESHOLD = 0.2; + const PAGE_SWITCH_TIME = 0.3; const VIEWS_SWITCH_TIME = 0.4; @@ -528,15 +526,19 @@ const AllView = new Lang.Class({ _onPanEnd: function(action) { if (this._displayingPopup) return; - let diffCurrentPage = this._diffToPage(this._currentPage); - if (diffCurrentPage > this._scrollView.height * PAGE_SWITCH_TRESHOLD) { - if (action.get_velocity(0)[2] > 0) - this.goToPage(this._currentPage - 1); - else - this.goToPage(this._currentPage + 1); - } else { - this.goToPage(this._currentPage); - } + + let pageHeight = this._grid.getPageHeight(); + + // Calculate the scroll value we'd be at, which is our current + // scroll plus any velocity the user had when they released + // their finger. + + let velocity = -action.get_velocity(0)[2]; + let endPanValue = this._adjustment.value + velocity; + + let closestPage = Math.round(endPanValue / pageHeight); + this.goToPage(closestPage); + this._panning = false; }, diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js index 6bbbcb7a8..16c58e92f 100644 --- a/js/ui/iconGrid.js +++ b/js/ui/iconGrid.js @@ -645,6 +645,10 @@ const PaginatedIconGrid = new Lang.Class({ return this._nPages; }, + getPageHeight: function() { + return this._availableHeightPerPageForItems(); + }, + getPageY: function(pageNumber) { if (!this._nPages) return 0;