Adding and removing an Object from a scrollview while scrolling

There’s an object that gets added to the scrollview when the scroll crosses a particular point in the scrollview and gets added to the parent group again while scrolling back.

local function scrollListener(event)

local x, y = event.target:getContentPosition();

if -y < *Some Y Position* then

  scrollView:insert(Object);
  Object.y = *Another Y position*;
else
  parentGroup:insert(Object);
end

return true;

end

The line where I’m adding the Object to the scrollView inside the listener breaks the height of the Scrollview.

Yeah, I’ve worked on many apps that add content to the scrollview while is being dragged (finger is still down) and it doesn’t handle it well when you are near the end of the scroll height and add more content.

You need to find a way to add that content before it needs to be displayed.

The same can happen if you swipe and lift your finger and add new content. If the end of the scroll area is hit before the add completes, it will stop.

1 Like

I created a duplicate object that’s a part of the scrollview. I got what I needed by adjusted the alpha of the both the objects.
Thanks for the approach. It was super helpful!