Accessing self within scrollview listener function

I want to be able to consistently access the scrollview object from within it’s own listener.

I am aware of event.target however there are different results depending on the phase of the event.
Specifically I want to access a custom property I’ve attached to the scrollview when ‘limitReached’ is true. I can access this on the ended phase but not when event.limitReached.
The point is, a different table seems to be returned by event.target at this point compared with any other point of the event.
Any idea what’s going on here?

If you test this scrollListener with a scrollview object and look at the print log, you’ll see what I mean.

 

local function scrollListener( event ) if event.phase == 'began' then print( 'self on began : ' .. tostring(event.target) ) elseif event.phase == 'moved' then print( 'self on moved : ' .. tostring(event.target) ) elseif event.phase == 'ended' then print( 'self on ended : ' .. tostring(event.target) ) end if event.limitReached then if event.direction == 'up' then print( 'self on limitReached-up : ' .. tostring(event.target) ) elseif event.direction == 'down' then print( 'self on limitReached-down : ' .. tostring(event.target) ) end end end

Hi @juliusbangert,

So if I understand your purpose, you want to detect when the view reaches a limit while moving it?

Brent

Hi Brent.
Ultimately I’m trying to create a scrollview with the functionality of pull down to refresh. Without going into the details of my code, I’m creating a generic extension scrollview class with a loading ring attached to the scrollview. So when I detect event.limitReached with event.direction == ‘down’ I want to be able to call scrollview.loadingRing:animate() which should equate to event.target.loadingRing. But my point is that a different object table seems to be returned by event.target when event.limitReached is true. Why would this be the case?

Hi Julius,

I’d have to explore the internal widget code further to see why this is happening. For your purposes, can you just set another variable reference to the scrollView and access that at all points?

Brent

Hi @juliusbangert,

So if I understand your purpose, you want to detect when the view reaches a limit while moving it?

Brent

Hi Brent.
Ultimately I’m trying to create a scrollview with the functionality of pull down to refresh. Without going into the details of my code, I’m creating a generic extension scrollview class with a loading ring attached to the scrollview. So when I detect event.limitReached with event.direction == ‘down’ I want to be able to call scrollview.loadingRing:animate() which should equate to event.target.loadingRing. But my point is that a different object table seems to be returned by event.target when event.limitReached is true. Why would this be the case?

Hi Julius,

I’d have to explore the internal widget code further to see why this is happening. For your purposes, can you just set another variable reference to the scrollView and access that at all points?

Brent