scrollview scroll bar fixes and comments:

I’ve been playing with the scrollview widget and noticed a few bugs and things I’d like to change (daily build 1172) regarding the scrollbar.

Firstly, I’d like to thank the Corona guys for releasing the source (even if it isn’t quite up to date, it helped me achieve what I wanted).

Note these are only for a single vertically scrolling view, and also note that the scroll bar does not get created immediately, but after a slight delay (2 milliseconds at the moment according to the code) so you shouldn’t count on being able to create the scrollview and access the scroll bar immediately.

So, I wanted to move the bar slightly to the right.

You get no direct access to the scrollbar, but it can be located at [lua]scrollViewObject._view._scrollbar[/lua]

You can access its properties - so I simply made its X value = 3 (enough to move it to the right into the position I wanted).

Next, if you do [lua]scrollview.scrollToPosition()[/lua] then the scroll bar, if already shown, locks at the position when you call the command, and no longer vanishes. If the scroll bar isn’t showing, it never does while the scrollToPosition() takes effect.

So what I did was:

[lua]scrollView:scrollToPosition{ y = <value> }

scrollView._view._scrollBar:show()[/lua]

This forces the value to show. Then I set up a timer for the same duration as the scrollToPosition() event, with the onComplete = function() scrollView._view._scrollBar:show() ; end.

So, that takes care of the widget hiding itself.

For the updating, I have an enterFrame event in the scene.

The only thing you need to call within it to update the scroll bar is to call:

[lua]scrollView._view._scrollBar:move()[/lua]

And it positions itself automatically.

I’ve actually been a bit more cautious than this overall (I only call :move() if I am within the duration of the scrollToPosition(), and I check if the scrollbar exists before I set its .x property) etc. but at least now it does what I want (apart from the height and position of the scroll bar being just plain wrong at times, but that’s without any of my code so I know it isn’t my bug).

Just posted this in case it helps anyway - I was getting very frustrated by the lack of control of the scroll bar (it was appearing over a black border I have so it was invisible!).

Barry

Oh, I’ve just noticed that scrollToPosition() accepts an onComplete function, so you can compress the code above to not need the timer.

Oh, I’ve just noticed that scrollToPosition() accepts an onComplete function, so you can compress the code above to not need the timer.