PSA timer.cancellAll will break your scrollingViews

This is something I spent way too much time on debugging, so I decided to share with y’all.

Using timer.cancelAll() can break your scrollView scrolling - the user won’t be able to scroll all its content.

I suppose this happens because the timer created by this call https://github.com/coronalabs/corona/blob/3b798eae8a8f45ccb2876b1580aede7a9ae02197/platform/resources/widget.lua#L2662
will get cancelled.

below is somewhat minimal example:

_G.widget = require("widget")

local scrollView = widget.newScrollView {
  x      = display.contentCenterX,
  y      = display.contentCenterY,
  width  = 100,
  height = 200
}
 
for i = 1,40 do
  local rect = display.newRect(50, i * 15, 80, 10)
  rect:setFillColor((math.pi * i) % 1, (math.pi * i * i) % 1, (math.pi * i * i * i) % 1)
  scrollView:insert(rect)
end

--uncommenting this line breaks the scrollView widget
--timer.cancelAll()

Yeah, seems like that’s by design.

One way to get around this is to create your timers with a tag and then cancel/pause the timers using that tag. That way you won’t accidentally cancel your active timer from scrollView.

To me it honestly feels like it’s by accident, but I get what you mean.

I agree, it’s a good practice to tag your timers and transitions. I mostly posted this to save some time for the next person who accidentally runs into this.

Yeah, when I wrote that API call, I didn’t know that there was a timer call in the scrollView widget. But, since it is there, timer.cancelAll() does work as intended, i.e. it cancels all timers.

Still, I do agree that it is worthwhile to post this so that others will have easier time figuring it out if they run into the same issue.