Touch area inside widget.scrollView only receives phase began

Hey,

I have a simple widget scrollView instance with a rectangle with a touch event listener attached. When I print the events for this touch listener on the rectangle I notice only the “began” phase is ever received, any other phase is missing.

Is this a known bug? I looked around and noticed how some people had problems giving back focus to the scrollview once a button had been clicked, but I’m experiencing more or less the opposite.

Any ideas?

Thanks!

Wim

Hi Wim,

We’ll probably need to see your code to determine the issue, since it could be various combinations of how you’ve set up the listener(s), the scroll view, the functions, etc.

Thanks,

Brent

Sure, the most basic example is sufficient:

local widget = require("widget") local sv = widget.newScrollView { top = 10, left = 10, width = 300, height =300, horizontalScrollDisabled = true, } local r = display.newRect(0, 0, 100, 100); r:setFillColor(1, 0, 0) sv:insert(r) r:addEventListener("touch", function(event) print(event.phase) end)

This only prints “began” when touching.

Hi Wim,

What’s happening here is that the touch is being registered on the rectangle (so you get the “began” phase), but then the other phases are being “passed through” to the actual scrollView. If you need to pick up all phases on the rectangle, add “return true” to the end of your listener function. This will give you all of the phases, but then you’ll also need to use the “takeFocus()” method outlined in the docs  to pass control to the scrollView if the user moves the touch x/y number of pixels.

http://docs.coronalabs.com/api/type/ScrollViewWidget/takeFocus.html

Hope this helps,

Brent

Thanks Brent, now I understand!

have a good day!

Hi Wim,

We’ll probably need to see your code to determine the issue, since it could be various combinations of how you’ve set up the listener(s), the scroll view, the functions, etc.

Thanks,

Brent

Sure, the most basic example is sufficient:

local widget = require("widget") local sv = widget.newScrollView { top = 10, left = 10, width = 300, height =300, horizontalScrollDisabled = true, } local r = display.newRect(0, 0, 100, 100); r:setFillColor(1, 0, 0) sv:insert(r) r:addEventListener("touch", function(event) print(event.phase) end)

This only prints “began” when touching.

Hi Wim,

What’s happening here is that the touch is being registered on the rectangle (so you get the “began” phase), but then the other phases are being “passed through” to the actual scrollView. If you need to pick up all phases on the rectangle, add “return true” to the end of your listener function. This will give you all of the phases, but then you’ll also need to use the “takeFocus()” method outlined in the docs  to pass control to the scrollView if the user moves the touch x/y number of pixels.

http://docs.coronalabs.com/api/type/ScrollViewWidget/takeFocus.html

Hope this helps,

Brent

Thanks Brent, now I understand!

have a good day!