diff --git a/src/scrollview/HISTORY.md b/src/scrollview/HISTORY.md index e054859d001..f74890536e2 100644 --- a/src/scrollview/HISTORY.md +++ b/src/scrollview/HISTORY.md @@ -4,7 +4,9 @@ ScrollView Change History @VERSION@ ------ -* No changes. +* [#1740][]: Scrollview scrolltoindex breaks after a click-drag down (@mairatma) + +[#1740]: https://github.com/yui/yui3/issues/1740 3.16.0 ------ diff --git a/src/scrollview/js/paginator-plugin.js b/src/scrollview/js/paginator-plugin.js index 01e9bae9769..9f854839acb 100644 --- a/src/scrollview/js/paginator-plugin.js +++ b/src/scrollview/js/paginator-plugin.js @@ -226,7 +226,8 @@ Y.extend(PaginatorPlugin, Y.Plugin.Base, { pageNodes = paginator._getPageNodes(), gestureAxis; - if (gesture) { + // Only look at the last gesture if we're not scrolling to a specific index. + if (gesture && !this._scrollingToIndex) { gestureAxis = gesture.axis; // Null the opposite axis so it won't be modified by host.scrollTo @@ -599,11 +600,19 @@ Y.extend(PaginatorPlugin, Y.Plugin.Base, { // Makes sure the viewport nodes are visible paginator._showNodes(pageNode); + // Set the flag to indicate that we're scrolling to a specific index, + // so _beforeHostScrollTo will not try to adjust the coordinates according + // to the last gesture. + paginator._scrollingToIndex = true; + // Scroll to the offset host.set(scrollAxis, scrollOffset, { duration: duration, easing: easing }); + + // Reset the flag to the original value. + paginator._scrollingToIndex = false; }, /** diff --git a/src/scrollview/tests/unit/assets/scrollview-paginator-unit-tests.js b/src/scrollview/tests/unit/assets/scrollview-paginator-unit-tests.js index 3c48a2911b6..3a5ffa77c6d 100644 --- a/src/scrollview/tests/unit/assets/scrollview-paginator-unit-tests.js +++ b/src/scrollview/tests/unit/assets/scrollview-paginator-unit-tests.js @@ -450,6 +450,15 @@ YUI.add('scrollview-paginator-unit-tests', function (Y, NAME) { Y.Assert.isNull(response.newArgs[0]); }, + '_beforeHostScrollTo through scrollToIndex should keep original values': function() { + var scrollview = this.scrollview = renderNewScrollview('x', 'x'); + + scrollview._gesture = { axis: 'y' }; + Y.Assert.areEqual(0, scrollview.get('scrollX')); + scrollview.pages.scrollToIndex(1); + Y.Assert.areEqual(300, scrollview.get('scrollX')); + }, + "Gestures against the grain should select the index page's node to transition" : function () { var scrollview = this.scrollview = renderNewScrollview('y', 'y'), paginator = this.scrollview.pages,