Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7400] Android: ScrollView - Runtime error generated when scrollView.contentOffset object is used in a call back function

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-03-11T22:31:13.000+0000
Affected Version/sRelease 1.8.0.1, Release 1.8.1
Fix Version/sSprint 2012-03, Release 2.0.0, Release 1.8.2
ComponentsAndroid
Labelsparity, qe-and012312, qe-testadded
ReporterWilson Luu
AssigneeHieu Pham
Created2012-01-25T13:49:19.000+0000
Updated2012-03-11T22:31:13.000+0000

Description

Steps to reproduce: 1. Launch the following code in app.js:
var win = Titanium.UI.createWindow({  
    layout:'vertical',
    backgroundColor:'#fff'
});

var scrollView = Ti.UI.createScrollView({
	showHorizontalScrollIndicator:true, showVerticalScrollIndicator:true,
	width: 250, height: 100, top: 50,
	borderColor:'green', borderWidth:1,
	contentWidth:1000, contentHeight:100
});

for(var i=0; i<10; i++) {
	for(var j=0; j<10; j++) {
		scrollView.add(Ti.UI.createLabel({
			top:i*100, left:j*100,
			width:100, height:100,
			text:i+':'+j, textAlign:'center',
			color:'white',
			backgroundColor:'#A0' + Number(i%2*8).toString(16) +'0'+ Number(8-j%2*8).toString(16)+'0',
			borderColor:'black', borderWidth:1 
		}));
	}
}

var button = Ti.UI.createButton({title:'Flip', width:100, height:50});
button.addEventListener('click', function() {
	scrollView.width = 100;
	scrollView.height = 250;
	
	scrollView.contentWidth = 100;
	scrollView.contentHeight = 1000;

	button.title = 'Click again';
	
});

scrollView.addEventListener('scroll', function() {
        // bug is here 
	Ti.API.info('Offset: (' + scrollView.contentOffset.x + ', ' + scrollView.contentOffset.y + ')');
});
win.add(scrollView);
win.add(button);
win.open();
Actual: Runtime error occur. See attachment. Expected: Should not get a runtime error. Above code ran without error in iOS Note: Occurs in 1.8.0.1

Attachments

FileDateSize
device-2012-01-25-125800.png2012-01-25T13:49:19.000+000030164

Comments

  1. Opie Cyrus 2012-02-07

    updated title
  2. Hieu Pham 2012-02-07

    Testing code:
       var win = Titanium.UI.createWindow({  
           layout:'vertical',
           backgroundColor:'#fff'
       });
       
       var scrollView = Ti.UI.createScrollView({
       	showHorizontalScrollIndicator:true, showVerticalScrollIndicator:true,
       	width: 250, height: 100, top: 50,
       	borderColor:'green', borderWidth:1,
       	contentWidth:1000, contentHeight:100, contentOffset:{"x":300, "y":0}
       });
       
       scrollView.contentOffset = {"x":400, "y":100}; 
       
       for(var i=0; i<10; i++) {
       	for(var j=0; j<10; j++) {
       		scrollView.add(Ti.UI.createLabel({
       			top:i*100, left:j*100,
       			width:100, height:100,
       			text:i+':'+j, textAlign:'center',
       			color:'white',
       			backgroundColor:'#A0' + Number(i%2*8).toString(16) +'0'+ Number(8-j%2*8).toString(16)+'0',
       			borderColor:'black', borderWidth:1 
       		}));
       	}
       }
       
       var button = Ti.UI.createButton({title:'Flip', width:100, height:50});
       button.addEventListener('click', function() {
       	scrollView.width = 100;
       	scrollView.height = 250;
       	
       	scrollView.contentWidth = 100;
       	scrollView.contentHeight = 1000;
       
       	button.title = 'Click again';
       	
       });
       
       scrollView.addEventListener('scroll', function(e) {
               // bug is here 
       	Ti.API.critical("x: " + scrollView.contentOffset.x + " y: " + scrollView.contentOffset.y);
       });
       win.add(scrollView);
       win.add(button);
       win.open();
       
  3. Natalie Huynh 2012-02-09

    No longer getting the runtime error, however the vertical scroll is not responding Tested with 1.9.0.v20120208180134 on Droid 3 (2.3.4)
  4. Natalie Huynh 2012-02-09

    Vertical scroll issue has a separate bug TIMOB-7402 closing this as we no longer get the runtime error

JSON Source