Can you Insert a newImageRect into a ScrollView while it is still drifting?

I’ve tried to do this in the “if (phase == “began”)” (or “ended”) section of my scrollListener, but if I scrollView:insert(myNewImageRect) there, it stops any drifting of my scrollView, no matter the tension.

If I wait until the “stopped” phase, it works normally, drifting nicely, but then it obviously appears a little later than I’d like.

The idea is that my fingertips are leaving “stains” on the page I am scrolling as I touch them, but I’d love the drift to be normal. Somehow inserting a new bitmap into the scrollView is interrupting the “began”…“ended”…“stopped” process with regard to friction(less) drift and ending any natural drift.

Any ideas? I’m not sure why inserting is interrupting the natural touch flow of the scrollView, but it clearly is.

I faced this problem so I grabbed the source for the widgets library and changed it. It is on github so you can alter it to whatever functionality you’d like.

How do I know I’m grabbing the latest? Do these libraries get updated for new releases/OSes? Is there any other danger/cautions/concerns to doing this?

Is it this? https://github.com/coronalabs/framework-widget

Sorry, still a bit of a newbie here.

(Also, is there a proper place to request this be added to the functionality if it’s an actual limitation of the existing codebase? Is there any reason you’d want this to be the resulting behavior?)

You can put a request on GitHub but it is unlikely to get changed as this may well break the library for other users…

The line you want to remove is this one

self:scrollToPosition( { x = origX, y = origY, time = 0 } )

It is around line 450 in widget_scrollview.lua.

I would send you mine but it is heavily bespoked for my implementation.

Thanks, SGS. And thanks especially for helping me get down to the line at play. :slight_smile:

Um, okay, this may just be me being a little new to lua and rusty to libraries and includes, but is there a short answer to how I include this code instead of the typical library? Is there a cleanest way to do it and have this override the other?

I assume rather than including the library at the start of my code with local widget = require( “widget” ) I’m somehow including this instead? Or can I somehow get away with just including the altered widget_scrollview.lua and have it override that part of the library, or am I needing to override the whole widget library and include the whole framework? (I found the line you referenced at the end of the scrollView:updateScrollAreaSize() function; just not sure best to include and then modify it.)

(Sorry for the hassle; this part is never my favorite, and I guess I’m not quite sure how to proceed. Should maybe have put this in the Newbies section…)

Put the entire rep in a sub folder called widget and then when you want to use your amended version you would do this instead.

local widget = require( "widget.widget" )

Well, that doesn’t quite work for me.

I assume you meant the widgetLibrary folder, not the “entire rep,” because if I put all of framework-widget in there I get a far more solid error message. But when I put the widgetLibrary in there, rename it to widget, and then change that require line in my main.lua, I get a different set of error messages at runtime (this is on the Simulator, mind you), all related to being “Unable to perform arithmatic on field ‘_oldAnchorX’ (a nil value)” and traced to Line 476 in function _calculatePosition in widget.lua.

Sigh. Should this work in the Simulator? After my last post I did some other searches through the archive and there are alternate instructions for doing this with the widget library, including an option called “WidgetFix” and a whole string of “package.preload.widget_button = onRequireWidgetLibrary”-type commands and the like. Problem is, a lot of these posts are 3 or 4 years old, so I’m not sure whether to take them seriously and try them or whether things have changed or simplified.

(Well, I’ve tried them too, and also get errors.)

Thanks again for the assistance, and if there’s a more official and recent thread on how to do this, feel free to direct me there.

I use the entire rep as I have amended some of the other widgets too. I do remember there being some issues when I did it. Don’t rename anything otherwise you’ll break the dependencies.

It works in the sim just fine. I use scrollviews with thousands of dynamically inserted objects - both for speed and memory management.

Well, so far this is just me trying to replace the library, with NO changes. Not even commenting out the one line I should to get the behavior I want.

I guess I’ll tinker around with it a little more, but right now simply replacing the library and pointing to it with require doesn’t seem to quite do it. (At least not with the versions of things I’m running, which I might play with also I guess.)

So here’s a weird development.

I couldn’t get the above suggested modification of the libraries to work. I don’t know if this is because things have changed since it was suggested, or what exactly. I tinkered with some other ideas for workarounds, and decided I’d come back to it later. (Getting a new Mac laptop over Christmas, so will have the latest XCode/OS, just in case that is playing some part in my current issues. Right now I’m having to compile code with an outdated SDK, which works but obviously doesn’t produce the newest code.)

Anyway, I went ahead and was coding other things, and in testing suddenly noticed that the scrolling is working as I’d hoped it would on the actual device – even though in the Simulator it is not.

I think this might be because I simply included a modifed widget_scrollview.lua at the base level in my code without modifying any references to the library, in terms of the instructions given on pointing to a modified library. So does just that code get compiled with MY version, but the Simulator ignores my version?

It’s great that it’s working, but I was a bit shocked by the behavior! (And of course it would be nice to have the Simulator version also working.)

Anyway… Pretty weird.