Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9474] Android: ScrollableView throws exception when using scrollToView()

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-06-08T17:41:45.000+0000
Affected Version/sRelease 2.1.0
Fix Version/sRelease 2.1.0, Sprint 2012-12 API
ComponentsAndroid
Labelsapi, regression
ReporterJosh Roesslein
AssigneeJosh Roesslein
Created2012-06-08T15:11:26.000+0000
Updated2012-06-18T15:37:10.000+0000

Description

Trying to use scrollToView() on a ScrollableView sometimes results in an exception being thrown. This appears to be triggered by creating the ScrollableView and passing a "currentPage" parameter. This regression appears in the KS Base UI > Views > Scroll Views > Scrollable View. Try scrolling to the next view by using the arrows on the bottom (these call scrollToView()).

Standalone test case

var win = Ti.UI.createWindow({layout: 'vertical'});

var views = ['blue', 'red', 'yellow'].map(function(color) {
	return Ti.UI.createView({backgroundColor: color});
});

var scrollable = Ti.UI.createScrollableView({
	height: '80%',
	currentPage: 1,
	views: views
});
win.add(scrollable);

var controls = Ti.UI.createView({
	height: '20%'
});
win.add(controls);

var currentView = 1;

var prevButton = Ti.UI.createButton({
	title: "Prev",
	left: 10,
	width: 200
});
controls.add(prevButton);
prevButton.addEventListener('click', function() {
	if (currentView === 0) return;
	scrollable.scrollToView(--currentView);
});

var nextButton = Ti.UI.createButton({
	title: "Next",
	right: 10,
	width: 200
});
controls.add(nextButton);
nextButton.addEventListener('click', function() {
	if (currentView == (scrollable.views.length - 1)) return;
	var view = scrollable.views[++currentView];
	scrollable.scrollToView(view);
});

scrollable.addEventListener('scroll', function(e) {
	currentView = e.currentPage;
});

win.open();
Run the test case and try switching views by using the "next" or "prev" buttons. Expected: Views change without any crash.

Comments

  1. Josh Roesslein 2012-06-08

    Sent [PR #2364](https://github.com/appcelerator/titanium_mobile/pull/2364) to fix regression.
  2. Michael Pettiford 2012-06-18

    Closing issue Tested with Ti Studio build 2.1.0.201206172244 Ti Mobile SDK2.1.0.v20120618134156 hash r00905cd0 OSX Lion 10.7.3 Nexus S OS 4.0.4 The expected behavior is shown

JSON Source