Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-2721] Android: implement the "contentOffset" property for the "scroll" event in TableView

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionWon't Fix
Resolution Date2013-01-23T18:46:47.000+0000
Affected Version/sRelease 3.0.0
Fix Version/s2013 Sprint 02 API, 2013 Sprint 02
ComponentsAndroid
Labelsapi, insight, parity
ReporterRick Blalock
AssigneePing Wang
Created2011-04-15T03:27:47.000+0000
Updated2014-01-29T07:51:35.000+0000

Description

In the blog post here: http://developer.appcelerator.com/blog/2010/05/how-to-create-a-tweetie-like-pull-to-refresh-table.html"> http://developer.appcelerator.com/blog/2010/05/how-to-create-a-twee...

The scroll event listener references a contentOffset property which has x / y coord. props. contentOffset is undefined in our 1.6 SDK for Android only. contentOffset is present in 1.5.x for Android (works for iOS either way).

Comments

  1. Don Thorp 2011-04-15

    To my knowledge this has never been implemented in Android. I went back through the 1.5 source and could not find any reference to contentOffset and it doesn't appear that tableview is even firing a scroll event.

    I'm changing the title and tags to correctly denote this as a feature request. Please review the ticket submission guidelines as this ticket violates most of them.

  2. Jon Alter 2011-04-15

    Associated Helpdesk Ticket

    http://developer.appcelerator.com/helpdesk/view/76652">http://developer.appcelerator.com/helpdesk/view/76652

  3. Dawson Toth 2011-04-15

    klist'd and rplist'd

  4. Matthew Congrove 2011-06-22

    There's also no contentOffset for ScrollViews. Can we get this added at the same time? Request is coming from customer. http://support.appcelerator.com/tickets/APP-633921/
  5. Zsombor Papp 2011-09-25

    +1 for implementing this for ScrollView.
  6. Alan Leard 2011-10-03

  7. hans schoenburg 2012-03-19

    up up up!
  8. Eduardo Gomez 2012-07-05

    One may work around using the following Droid properties of Scroll event (firstVisibleItem, totalItemCount, visibleItemCount) - Tested on 2.1.0.GA:

    app.js

       Ti.UI.setBackgroundColor('#000');
       
           var win = Ti.UI.createWindow({
             backgroundColor: 'black',
             exitOnClose: true,
             fullscreen: false,
             title: 'TableView Demo'
           });
           
           // generate random number, used to make each row appear distinct for this example
           function randomInt(max){
             return Math.floor(Math.random() * max) + 1;
           }
           
           var IMG_BASE = 'https://github.com/appcelerator/titanium_mobile/raw/master/demos/KitchenSink/Resources/images/';
           var defaultFontSize = Ti.Platform.name === 'android' ? 16 : 14;
           
           var tableData = [];
           
           for (var i=1; i<=20; i++){
             var row = Ti.UI.createTableViewRow({
               className:'forumEvent', // used to improve table performance
               selectedBackgroundColor:'white',
               rowIndex:i, // custom property, useful for determining the row during events
               height:110
             });
             
             var imageAvatar = Ti.UI.createImageView({
               image: IMG_BASE + 'custom_tableview/user.png',
               left:10, top:5,
               width:50, height:50
             });
             row.add(imageAvatar);
             
             var labelUserName = Ti.UI.createLabel({
               color:'#576996',
               font:{fontFamily:'Arial', fontSize:defaultFontSize+6, fontWeight:'bold'},
               text:'Fred Smith ' + i,
               left:70, top: 6,
               width:200, height: 30
             });
             row.add(labelUserName);
             
             var labelDetails = Ti.UI.createLabel({
               color:'#222',
               font:{fontFamily:'Arial', fontSize:defaultFontSize+2, fontWeight:'normal'},
               text:'Replied to post with id ' + randomInt(1000) + '.',
               left:70, top:44,
               width:360
             });
             row.add(labelDetails);
             
             var imageCalendar = Ti.UI.createImageView({
               image:IMG_BASE + 'custom_tableview/eventsButton.png',
               left:70, bottom: 2,
               width:32, height: 32
             });
             row.add(imageCalendar);
             
             var labelDate = Ti.UI.createLabel({
               color:'#999',
               font:{fontFamily:'Arial', fontSize:defaultFontSize, fontWeight:'normal'},
               text:'on ' + randomInt(30) + ' Nov 2012',
               left:105, bottom:10,
               width:200, height:20
             });
             row.add(labelDate);
             
             tableData.push(row);
           }
           
           var tableView = Ti.UI.createTableView({
             backgroundColor:'white',
             data:tableData
           });
           
           win.add(tableView);
           win.open();
       
       tableView.addEventListener('scroll', function(e)
       {
          //Ti.API.info('x|y ' + e.contentOffset.x + '|' + e.contentOffset.y);//it will be undefined indeed ... 
          Ti.API.info('-------------------');
       	Ti.API.info( 'firstVisibleItem : Number - Row index of the topmost visible row in the view: ' + e.firstVisibleItem);
       	Ti.API.info( 'totalItemCount : Number - Total number of rows in the view: ' + e.totalItemCount );
       	Ti.API.info( 'visibleItemCount : Number - Number of rows currently visible in the view: '+ e.visibleItemCount );
       });
       
  9. Karl Rowley 2012-12-19

    It looks like fixing this would require keeping track of row heights. Here's a post from stack overflow: http://stackoverflow.com/questions/10808387/android-getting-exact-scroll-position-in-listview This would be possible if every TableView started at the top and then scrolled down. However, a TableView can be programmatically scrolled to any row. In this case the height of proceeding rows may not be known yet.
  10. Ping Wang 2013-01-23

    There is no notion of Y scroll for a ListView in Android simply because the total height of the content is unknown. Only the height of the displayed content is known. I don't think it is possible to implement this feature on Android.
  11. Ping Wang 2013-01-23

    Mark the ticket as Won't Fix since the native Android does not support it.

JSON Source