How to define the end of scrolling of a scrollview?

You must Login before you can answer or comment on any questions.

I have a scrollView with text divided into some pages one under another. And I need to make it work like scrollableView but with vertical scrolling.

The problem is to define when the user stopped scrolling. the 'scrollEnd' event works not every time you scroll. 'scroll' event works too often (during the process of scrolling)... the 'touchend' event isn't fired when you stop scrolling.. so I don't know how to do that.

Any suggestions about it would be appreciated. thank you!

— asked 3 years ago by Anton Filimonov
2 Comments
  • I don't think there is a 'scrollEnd' event at all for the ScrollView. I have been trying to find a way to do this. Please let us know if you figure it out.

    — commented 3 years ago by Micah Alcorn

  • 'scrollEnd' event is fired by the scrollView after decelerating. There's not description for this event in API documentation, but I found this event in tableView description and tried to use it with scrollView. it works.. but unfortunately it doesn't work good enough..

    — commented 3 years ago by Anton Filimonov

4 Answers

How about the event dragEnd, instead of touchEnd? It works the same but when you drag instead of touching (Normally scrollViews have content bigger than it's size. obviously so you can 'scroll' through it, so the event 'touchEnd' works only when you don't drag which is pretty hard... unless the content fits and you can't scroll).

It's fired when the finger stop touching the Scrollview

scrollView.addEventListener('dragEnd',function(e){
    Ti.API.info('Hello World');
});
Or you can use scrollEnd, it's fired when the 'inertia' of the content stops (or decelerate)
scrollView.addEventListener('scrollEnd',function(e){
    Ti.API.info('Hello World');
});
Sorry for my awful English.

Another solution:

var ypos = 0;
var intervalIsRunning = false;
scrollView.addEventListener('scroll', function(e) {
    ypos = e.y;
    if (!intervalIsRunning) {
        //Ti.API.info('started');
        intervalIsRunning = true;
        var i = setInterval(function() {
            if (yposPrevious != ypos) {
                yposPrevious = ypos; 
            } else {
                clearInterval(i);
                intervalIsRunning = false;
                //Ti.API.info('stopped');
                // Do something here        
            }
        }, 500);
    }
 
});

Don't know it this will be usefull for you. I used e.dragging, so when the user stops dragging the scrollview you can know it, but you can't know when it stops moving...

Hello

If you mean that you want to determine when it's at the bottom of the entire scrollView you can use the scroll method and calculate where it's placed.

And example can be found in the kitchensink for a tableview, but I think scrollView works just the same:

var isBusy = false;
scrollView.addEventListener('scroll',function(e)
{
    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 (!isBusy && (total >= nearEnd))
        {
            //set isBusy true so it doesn't keep on doing this function
            isBusy = true;
            doSomething();
        }
    }
    lastDistance = distance;
});
 
function doSomething(){
    //Do something in this function
 
    //set isBusy to false
    isBusy = false;
}
Hope this helps you!

Tjeu

— answered 3 years ago by Tjeu Vdw
answer permalink
2 Comments
  • thank you for answer, but it's not what I'm looking for.. I need to define the moment when the user stopped touching the display after scrolling, but touchend event is useless because it's not fired after scrolling..

    — commented 3 years ago by Anton Filimonov

  • And it does not work the same.

    — commented 3 years ago by Micah Alcorn

Your Answer

Think you can help? Login to answer this question!