Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7877] Android: TableView scroll event contentOffset returning null

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionNot Our Bug
Resolution Date2017-07-18T20:06:27.000+0000
Affected Version/sRelease 1.7.5, Release 1.8.0.1, Release 1.8.2, Release 3.1.0
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterNikhil Sharma
AssigneeEric Merriman
Created2012-03-05T08:39:01.000+0000
Updated2017-07-18T20:06:31.000+0000

Description

TableView scroll event contentOffset returning null on android. It works fine on iOS but not on android.

Repro Steps

1. Run the below code. 2. In the alert the scroll event contentOffset will return null.
var win = Ti.UI.createWindow({
	backgroundColor: '#ffffff'	
});
var data = [];
var lastRow = 10;
for (var c=0;c<lastRow;c++)
{
	data[c] = {title:"Row "+(c+1)};
}

var tableView = Ti.UI.createTableView({
	data: data
});

win.add(tableView);

var navActInd = Titanium.UI.createActivityIndicator();
// win.setRightNavButton(navActInd);

var updating = false;
var loadingRow = Ti.UI.createTableViewRow({title:"Loading..."});

function beginUpdate()
{
	updating = true;
	navActInd.show();

	tableView.appendRow(loadingRow);

	// just mock out the reload
	setTimeout(endUpdate,2000);
}

function endUpdate()
{
	updating = false;

	tableView.deleteRow(lastRow,{animationStyle:Titanium.UI.iPhone.RowAnimationStyle.NONE});

	// simulate loading
	for (var c=lastRow;c<lastRow+10;c++)
	{
		tableView.appendRow({title:"Row "+(c+1)},{animationStyle:Titanium.UI.iPhone.RowAnimationStyle.NONE});
	}
	lastRow += 10;

	// just scroll down a bit to the new rows to bring them into view
	tableView.scrollToIndex(lastRow-9,{animated:true,position:Ti.UI.iPhone.TableViewScrollPosition.BOTTOM});

	navActInd.hide();
}

var lastDistance = 0; // calculate location to determine direction

tableView.addEventListener('scroll',function(e)
{
	alert(e.contentOffset);
	
	var offset = e.contentOffset.y;
	var height = e.size.height;
	var total = offset + height;
	var theEnd = e.contentSize.height;
	var distance = theEnd - total;

	// going down is the only time we dynamically load,
	// going up we can safely ignore -- note here that
	// the values will be negative so we do the opposite
	if (distance < lastDistance)
	{
		// adjust the % of rows scrolled before we decide to start fetching
		var nearEnd = theEnd * .75;

		if (!updating && (total >= nearEnd))
		{
			beginUpdate();
		}
	}
	lastDistance = distance;
});



win.open();

Comments

  1. jithinpv 2013-03-20

    alert shows null also it shows a Runtime Error - "Uncaught Type Error:Cannot read property 'y' of undefined",source - "var offset =e.contentOffset.y;" Issue reproduces Tested with Titanium Studio, build: 3.0.1.201212181159 Titanium SDK version: 3.1.0 (03/11/13 15:43 0c88429) Titanium SDK version: 3.0.2 (02/07/13 16:46 a4def81) Device: Samsung galaxy s duos Android version: 4.0.4 jithinpv
  2. Shannon Hicks 2013-04-09

    This ticket can probably get closed as long as this works in ListView
  3. Lee Morris 2017-07-18

    Closing ticket with reference to the above comments. Any problems, please file a new ticket.

JSON Source