[TIMOB-7877] Android: TableView scroll event contentOffset returning null
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Not Our Bug |
Resolution Date | 2017-07-18T20:06:27.000+0000 |
Affected Version/s | Release 1.7.5, Release 1.8.0.1, Release 1.8.2, Release 3.1.0 |
Fix Version/s | n/a |
Components | Android |
Labels | n/a |
Reporter | Nikhil Sharma |
Assignee | Eric Merriman |
Created | 2012-03-05T08:39:01.000+0000 |
Updated | 2017-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();
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
This ticket can probably get closed as long as this works in ListView
Closing ticket with reference to the above comments. Any problems, please file a new ticket.