newScrollView insert

Hi guys,

Thanks for taking the time to answer.

I am aware everyone has their own projects and I am not demanding answers, dont get me wrong.

@Ed,

Checked the link and did exactly what you wrote, yet I get an error which I am sure is something silly, but I havent figuered out.

How can this code…

local widget=require("widgetFix") 

and this…

local scroll=widget.newScrollView({ top=70, left=20, width=dcw-40, height=dch-70-70, hideBackground=true, horizontalScrollDisabled=true, hideScrollBar=true, isBounceEnabled=true, listener=scrollViewArtistsEvent}) dgSearchP1:insert(scroll) 

give this error message? 

attempt to index upvalue ‘widget’ (a boolean value)

I suspect the required library is not being loaded? Could it be a SDK vs Enterprise issue?

I am aware of your hitman service and if I ever get into the situation where I am truly stuck, I’ll take you up on it.

In the meantime, I appreciate hints and while I am new to all this, whenever I see the posibility to help someone else, I try to do so, since we’re all solving problems, only at different levels.

I’ll try to vent somewhere else in the future  :wink:

@Ed,

You sure that code snippet works?

Doesnt seem like it wants to load.

Got it working after studying 

https://docs.coronalabs.com/api/library/package/require.html

and realizing that it should look like this

require("widgetFix") local widget=require("widget")

instead of

local widget=require("widgetFix")

Thanks again Ed!

**UPDATED**

I use it all the time, but I have a slightly older local copy of the widget library.

Let me check and get back to you.

OOPS, saw your updated response.  Glad it worked for you.

-Ed

Thanks Ed, appreciate your help alot!

  1. Make sure you have more objects in the scroll than it is tall.

  2. Use placeholder fills (like a 16x16 transparent image) for off-screen objects.

  3. Detect the drag portion of the interaction and detect whether more objects will be needed before the finger is released and momentum takes over.  If so, add objects then.

Following these steps will ensure you don’t run out of elements to show, you don’t waste memory on fills for offscreen objects, and you don’t stop the momentum part of the scroll.

Also, don’t forget you can download and modify the widget library to suit your needs.

Hi roaminggamer,

I forgot to mention that what populates the list are images from the loadRemoteImage callback, in batches of 50 small images.

When they are created, I insert them into the list as they arrive.

Of course I can wait until all are downloaded and insert all in a loop but whichever way i do this, the resizing of the scrollView halts the slowdown momentum.

Point 1 is given but to my knowledge, I cant use a placeholder and then replace it with a different object since i’d have to insert the new one anway after destroying the old, and scrollView will always recalculate heigh (in my case) when an object is inserted. Or am i wrong?

Point 3 is gonna be hard as I do not know when the images will be finished loading.

What i’ve done as an alternative solution to keep scrolling smooth is that once the scroll reaches the end, it freezes, pops a loading tag, and once all is downloaded and checked, removes the tag and unlocks for forther scrolling. 

It works quite well, albeit not exactly how I wanted in the first place.

You don’t need to wait till they are downloaded.

  1. Put a placeholder rect or imageRect in the scroller of the correct dimensions.

  2. Fill it with a blank texture or just use an empty rectangle.

  3. Request the image and attach a listener to the rectangle.

  4. When the request comes in, fill the rectangle with the texture.

Tip: This may be complicated a bit if you don’t know the size of the image till it arrives.  If this is the case, either:

A. Use a rect in a container and scale the rect when its image comes in.

B. Mask the rect and do the same scaling.

Here are two basic examples of the temporary fill concept:

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2016/09/remoteFiles.zip

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2016/09/remoteFiles2.zip

These don’t include scrolling or culling off-screen objects, just placing a temporary rect, then filling with the downloaded image when it arrives.

https://www.youtube.com/watch?v=DBjfUR68hLQ

I have an offscreen culling example somewhere, but I can’t remember where it is right now.

If you want me to put together a working example for you we might be able to work something out

Note: You seem to be unclear on one point.

I’m not saying replace the object.  I’m saying to set the fill with the image when it is available.

You can change the fill of any rect or imageRect.

Thanks mate!

Need to study what you are saying here.

Only have 9 months of corona and lua under the belt and little programming experience before that.

Will let you know how it goes!

Note: If you want to till the scroller on the fly from remote images whose size you do not know and you also want those images to be shown full sized, then this will be a bit harder, but probably not impossible.

However, that sounds like  bad design to me.  I’d change the design so that all images must be displayed at a uniform size, even if that means you scale and or clip parts of the image when it arrives.

In this case, a little uniformity in the design rules will help a lot.

I’m about to take of, but last note.

I’ve made exactly the kind of scroller, filled with currently downloading images before as part of more than one app.

Assuming certain constraints, this is actually pretty straightforward.  

The only tricky bits are:

  1. Handling odd sized images of unknown dimensions.

  2. Culling off-screen objects for efficiency.  i.e. Re-fill offscreen images with the shared 16x16 texture.  This keeps memory usage down a lot.

cut my code down to bare minimum to figure this out and found that the culprit to this hick-up is that i do my progressive preload check in the scrollView event which only fires when finger is on the board. The release slow down scrolling does not fire any events.

I’ll fix this with a enterFrame runtime check instead tomorrow. it should work.

thanks for the tip on how to use placeholders!

anaqim

@anaqim, scrolling stops because of 1 line of code in the scrollView and is easily fixed by downloading the widget library from github.

This thread explains the fix - https://forums.coronalabs.com/topic/68105-scrollview-speed-limit-and-scrolling-abruptly-stopping-when-adding-new-elements-within/?hl=%2Bscrollview+%2Bstops+%2Bscrolling

In my case the rect fill doesn’t work as I have lots of text objects and filters.  Plus doing dynamic insert/remove saved over 70MB RAM so it was win/win.

Hi sphere,

Thanks! that sounds like something worth checking out first thing in the morning :slight_smile:

Hi again sphere,

Read the post you linked to and wonder if you’d mind sharing the improved dynamic load/unload version of this script that you fixed? It’s exactly what i’m looking for.

If not, thats fine too, just want to know before I “get to it”.

Cheers!

downloaded the script from github, removed the line in question, and tried to require it and use it, but it seems i’m too inexperienced to get it to work in my code.

all i need is to get rid of that pesky line that stops the scrolling.

any pointers is appreciated as to how i setup/use the modified script  :slight_smile:

got the dynamic loading/unloading of images working in the scroll so now all I am missing is to get that scroll stopper fixed.

if anyone has the knowledge and the time?  :slight_smile:

There are some internal referencing issues that need addressing if I remember correctly - check all the requires have valid paths. This will depend on how you have the project physically laid out.

thanks for the hints but its beyond my capabilities i’m afraid.

i have to try and find another way to do this then.