Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-7877

Android: TableView scroll event contentOffset returning null

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Low
    • Resolution: Not Our Bug
    • Affects Version/s: Release 1.7.5, Release 1.8.0.1, Release 1.8.2, Release 3.1.0
    • Fix Version/s: None
    • Component/s: Android
    • Labels:
      None
    • Environment:

      android 2.2.2
      LG Optimus V
      Ti SDK 2.0.0.v20120302191704

      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();
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                emerriman Eric Merriman
                Reporter:
                nsharma Nikhil Sharma
              • Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-12289
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Integration