Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25514] Android: Vertical ScrollView.scrollTo() goes to wrong position when animated as of 6.2.2

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2017-11-16T00:51:16.000+0000
Affected Version/sRelease 6.2.2
Fix Version/sRelease 7.0.0
ComponentsAndroid
Labelsandroid, scrollview
ReporterJoshua Quick
AssigneeJoshua Quick
Created2017-11-15T04:05:42.000+0000
Updated2017-11-16T01:55:32.000+0000

Description

*Summary:* The ScrollView.scrollTo() method, when "animated" is set to true, will not always scroll to the given position for "vertical" scroll views as of Titanium 6.2.2. *Steps to reproduce:*

Build and run the below code on Android via Titanium 6.2.2 or higher.

Scroll down to the bottom of the ScrollView.

Tap the "Scroll to Top" button.

var window = Ti.UI.createWindow();
var scrollView = Ti.UI.createScrollView(
{
	layout: "vertical",
	scrollType: "vertical",
	showHorizontalScrollIndicator: false,
	shorVerticalScrollIndicator: true,
	width: Ti.UI.FILL,
	height: Ti.UI.FILL,
});
scrollView.add(Ti.UI.createLabel(
{
	text: "First View",
	textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
	color: "white",
	backgroundColor: "blue",
	borderColor: "white",
	borderWidth: "1dp",
	width: "100%",
	height: "75%",
}));
scrollView.add(Ti.UI.createLabel(
{
	text: "Middle View",
	textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
	color: "white",
	backgroundColor: "#008800",
	borderColor: "white",
	borderWidth: "1dp",
	width: "100%",
	height: "75%",
}));
scrollView.add(Ti.UI.createLabel(
{
	text: "Last View",
	textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
	color: "white",
	backgroundColor: "purple",
	borderColor: "white",
	borderWidth: "1dp",
	width: "100%",
	height: "75%",
}));
window.add(scrollView);
var button = Ti.UI.createButton(
{
	title: "Scroll To Top",
	bottom: "10dp",
	right: "10dp",
});
button.addEventListener("click", function(e) {
	scrollView.scrollTo(0, 0, { animated: true });
});
window.add(button);
window.open();
*Result:* The ScrollView does not scroll to the top. *Expected Result:* The scrollTo() method should go to the given position. *Notes:* * The scrollTo() function will work if not set up to be animated. * The scrollTo() function will work when starting from the top of the ScrollView to scroll down, but is unreliable when called from any other scroll position. * This is not an issue with horizontal ScrollViews. * This appears to be a bug in Google's "NestedScrollView" Java class. It's smoothScrollTo() and fullScroll() methods are now unreliable, but its non-smooth scrolling methods work fine. *Work-Around:* The scrollTo() method will work when not set up to be animated, like this...
// Don't do this.
//scrollView.scrollTo(x, y, { animated: true });

// Do this. It works-around the issue.
scrollView.scrollTo(x, y);

Comments

  1. Joshua Quick 2017-11-15

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/9601
  2. Abir Mukherjee 2017-11-15

    FR passed; waiting for CR before merging.
  3. Abir Mukherjee 2017-11-16

    PR merged.
  4. Lokesh Choudhary 2017-11-16

    Verified the fix in SDK 7.0.0.v20171115153702. Closing.

JSON Source