Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3436] iOS: tableview "scroll" event only fires when dragging

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionInvalid
Resolution Date2017-06-21T22:09:34.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labelsn/a
ReporterBrian
AssigneeIngo Muschenetz
Created2011-04-15T03:45:10.000+0000
Updated2017-06-21T22:09:34.000+0000

Description

TiUITableView only fires the "scroll" event when the underlying scrollView is being dragged. There is actually a check for scrollView.isDragging in the scrollViewDidScroll delegate method around line 2020. We actually need to be notified at all times that the tableview is scrolling, regardless of whether or not it's being dragged. This is standard functionality that is available in native iOS and allows us to do much more with the UI. It also allows us to deal with the content inset issues when using headerPullview.

When you listen to a ScrollView's "scroll" event you get a boolean called "dragging" on the event, this should also be available on the TableView's "scroll" event. We already modified the Titanium code-base to support this in our project. We removed 3 lines of code and added one line. The required changes are outlined bedlow. Also the documentation for a TableView's "scroll" event would need to be updated to show the new boolean "dragging".

TiUITableView.m
Goto line 2020 and into the method - (void)scrollViewDidScroll:(UIScrollView *)scrollView
Remove the scrollView.isDragging check
Add the following to the event NSMutableDictionary:
[event setObject:NUMBOOL([scrollView isDragging]) forKey:@"dragging"];

Best,

Brian

Comments

  1. Brian 2011-04-15

    I went ahead and made the changes...here is the pull request:

    https://github.com/appcelerator/titanium_mobile/pull/85">https://github.com/appcelerator/titanium_mobile/pull/85

    Thanks,

    Brian

  2. Thiago 2011-04-15

    Hi Brian, I have some problems too with pull to refresh solution with iphone <= 3G, as you mentioned.
    I implemented your fix and still have some delay on scrollend to set some control variables.

    Well, I would like to know how you fixed pull to refresh issues with your fix.

    Thanks.

  3. Brian 2011-04-15

    @Thiago,

    On your tableView's scroll event you have to check for dragging and if it's not dragging but is reloading then you force the headerPullView to show. Here is an example:

       tableView.addEventListener('scroll', function(e) {
           var offset = e.contentOffset.y;
       
           if (e.dragging && !reloading) {
               if (!pulling && offset <= -65.0) {
                   pulling = true;
                   var t = Ti.UI.create2DMatrix();
                   t = t.rotate(-180);
                   arrow.animate({transform:t,duration:100});
                   statusLabel.text = "Release to update...";
               }
               else if (pulling && offset > -65.0 && offset < 0) {
                   pulling = false;
                   var t = Ti.UI.create2DMatrix();
                   arrow.animate({transform:t,duration:100});
                   statusLabel.text = "Pull down to update...";
               }
           }
           if (!e.dragging && reloading) {
               tableView.scrollToTop(-65, {animated:true});
           }
       });
       
  4. Thiago 2011-04-15

    Ohh, I was doing everything right, except using scrollToTop. I was using the bugged setContentInsets instead of scrollToTop (by the way, if you set animated to true, it goes to the top and then the scroll goes to the desired position - is there a way to fix this [the best solution I found was setting animated to false]?).

    Thanks! And I hope they can fix all this weird code and all developers like us can sleep better in the end of the day.

  5. Brian 2011-04-15

    Ya setting animated to false is probably the best way...glad you were able to get everything working :)

  6. Lee Morris 2017-06-21

    Closing ticket due to time passed and lack of progress for a number of years. Any problems, please file a new ticket.

JSON Source