ScrollView various issues

I’m having a number of strange issues in regards to the ScrollView widget and G2.  I’ve tried to put together a simple piece of code to show the issues, as well as some video demonstrating them as well.

I am running into 3 issues:

  1. The ScrollView does not seem to update itself visually until I move it.  Even a tiny nudge will make it appear, but does not show on its own.  I’ve also tried a short delay before rendering the ScrollView, but it made no difference.

  2. Setting the scrollWidth when instantiating the widget does not seem to work.  But…it can be adjusted after the fact using setScrollWidth.

  3. I could be misunderstanding how the anchors work, but even when trying to place the widget at a 0 x and y, and anchorX and anchorY to 0 it still seems to scroll the starting point to the middle of the screen, but it does seem to start at the proper spot (though its hard to tell because of the issue #1). Again, this could be a misunderstanding on my part.

You can view the screencast here.

Code:

[lua]local widget = require( “widget” )

local function renderScrollView()

local function scrollListener( event )
–print(‘event’)
end

local scrollView = widget.newScrollView
{
width = display.contentWidth,
height = 240,
–scrollWidth = 6200,
scrollHeight = 0,
verticalScrollEnabled = false,
isBounceEnabled = false,
hideScrollBar = true,
hideBackground = true,
listener = scrollListener,
}

for i=1, 20 do
local g = display.newGroup()

local btn = display.newRect( 0, 0, 200, 200 )
btn:setFillColor( 128 )
btn.x = 250 * i
g:insert( btn )

local text = display.newText({
text = “item” … i,
width = 220,
height = 0,
font = native.systemFont,
fontSize = 42,
align = “center”
})

text:setFillColor( 0 )
text.x = btn.x
text.y = btn.y - 10

g:insert( text )

scrollView:insert( g )
end

scrollView.anchorX = 0
scrollView.anchorY = 0

scrollView.x = 0
scrollView.y = 0

scrollView:setScrollWidth( 6200 )

end

renderScrollView()[/lua]

Build 2047 - Windows 8.1 - Nexus 4 - Kindle HDX

As an additional note, the last version that seems to work consistently with the ScrollView is Build 2026.

Can anyone confirm this?  Is this a possible bug?

Best.

It seems like the refresh issue maybe a bug.  The width thing seems like a bug too.  Can you please file a bug report?

Thanks

Rob

Will do.  Thanks for the confirmation.

Well, I don’t know if anyone else is having this problem but, in my case, this code solved your first problem for me:

scrollview:scrollToPosition { x = -scrollview.width/2, y = -scrollview.height/2, time = 0 }

Basically it forces the scrollview to go to top (at least, it’s what is happening) without any animation. That way, the scrollview is updated.

Ok, this code solved the 2 first issues for me dynamically:

local scrollviews={} function fix.widget.newScrollView(options) local height=options.height local width=options.width options.topPadding=(not options.topPadding) and 0 or options.topPadding options.bottomPadding=(not options.bottomPadding) and 0 or options.bottomPadding options.leftPadding=(not options.leftPadding) and 0 or options.leftPadding options.rightPadding=(not options.rightPadding) and 0 or options.rightPadding local height\_div=options.height/2 local width\_div=options.width/2 local scrollView=widget.newScrollView(options) scrollView:setScrollHeight(scrollView.height) scrollView:scrollToPosition { x = -width\_div, y = -height\_div, time = 0 } local insert=scrollView.insert scrollView.update\_y=false; scrollView.update\_x=false; scrollView.debug\_size=options.debug\_size function scrollView:insert(index, child, resetTransform) insert(scrollView,index, child, resetTransform) local element=child if (not element) then element=index end local sum=element.y+element.height if (sum\>scrollView.\_view.\_scrollHeight) then scrollView.update\_y=true end sum=element.x+element.width if (sum\>scrollView.\_view.\_scrollHeight) then scrollView.update\_x=true end local removeSelf=element.removeSelf function element:removeSelf() scrollView.update\_y=true scrollView.update\_x=true removeSelf(element) end end local remove=scrollView.remove function scrollView:remove( indexOrChild ) scrollView.update\_y=true scrollView.update\_x=true remove(scrollView,indexOrChild) end table.insert(scrollviews,scrollView) return scrollView end timer.performWithDelay(200, function() for k,v in pairs(scrollviews) do if (v.update\_x or v.update\_y) then local max\_y=0 local max\_x=0 for i=v.numChildren,1,-1 do local element = v[i] if (v.update\_x) then local sum=element.x+element.width if (sum\>max\_x) then if (sum\<v.width) then sum=v.width end max\_x=sum end end if (v.update\_y) then local sum=element.y+element.height if (sum\>max\_y) then if (sum\<v.height) then sum=v.height end max\_y=sum end end end if (v.update\_x) then v.update\_x=false v:setScrollWidth(max\_x) if (v.debug\_size) then print("Sized To X "..max\_x) end end if (v.update\_y) then v.update\_y=false v:setScrollHeight(max\_y) if (v.debug\_size) then print("Sized To Y "..max\_y) end end end end end,0)

It’s not the best solution because of the “timer” that I have there but, at least it solves the 2 first problems (I didn’t tested anchors).
Basically, it does what I’ve put on the previous post and everytime that I add something to the scrollView, it updates the scrollHeight value. As this is not instantly, I needed to use a timer because sometimes it was updating in wrong order.

To use this code, just change all “widget.newScrollView” to “fix.widget.newScrollView”.

It seems like the refresh issue maybe a bug.  The width thing seems like a bug too.  Can you please file a bug report?

Thanks

Rob

Will do.  Thanks for the confirmation.

Well, I don’t know if anyone else is having this problem but, in my case, this code solved your first problem for me:

scrollview:scrollToPosition { x = -scrollview.width/2, y = -scrollview.height/2, time = 0 }

Basically it forces the scrollview to go to top (at least, it’s what is happening) without any animation. That way, the scrollview is updated.

Ok, this code solved the 2 first issues for me dynamically:

local scrollviews={} function fix.widget.newScrollView(options) local height=options.height local width=options.width options.topPadding=(not options.topPadding) and 0 or options.topPadding options.bottomPadding=(not options.bottomPadding) and 0 or options.bottomPadding options.leftPadding=(not options.leftPadding) and 0 or options.leftPadding options.rightPadding=(not options.rightPadding) and 0 or options.rightPadding local height\_div=options.height/2 local width\_div=options.width/2 local scrollView=widget.newScrollView(options) scrollView:setScrollHeight(scrollView.height) scrollView:scrollToPosition { x = -width\_div, y = -height\_div, time = 0 } local insert=scrollView.insert scrollView.update\_y=false; scrollView.update\_x=false; scrollView.debug\_size=options.debug\_size function scrollView:insert(index, child, resetTransform) insert(scrollView,index, child, resetTransform) local element=child if (not element) then element=index end local sum=element.y+element.height if (sum\>scrollView.\_view.\_scrollHeight) then scrollView.update\_y=true end sum=element.x+element.width if (sum\>scrollView.\_view.\_scrollHeight) then scrollView.update\_x=true end local removeSelf=element.removeSelf function element:removeSelf() scrollView.update\_y=true scrollView.update\_x=true removeSelf(element) end end local remove=scrollView.remove function scrollView:remove( indexOrChild ) scrollView.update\_y=true scrollView.update\_x=true remove(scrollView,indexOrChild) end table.insert(scrollviews,scrollView) return scrollView end timer.performWithDelay(200, function() for k,v in pairs(scrollviews) do if (v.update\_x or v.update\_y) then local max\_y=0 local max\_x=0 for i=v.numChildren,1,-1 do local element = v[i] if (v.update\_x) then local sum=element.x+element.width if (sum\>max\_x) then if (sum\<v.width) then sum=v.width end max\_x=sum end end if (v.update\_y) then local sum=element.y+element.height if (sum\>max\_y) then if (sum\<v.height) then sum=v.height end max\_y=sum end end end if (v.update\_x) then v.update\_x=false v:setScrollWidth(max\_x) if (v.debug\_size) then print("Sized To X "..max\_x) end end if (v.update\_y) then v.update\_y=false v:setScrollHeight(max\_y) if (v.debug\_size) then print("Sized To Y "..max\_y) end end end end end,0)

It’s not the best solution because of the “timer” that I have there but, at least it solves the 2 first problems (I didn’t tested anchors).
Basically, it does what I’ve put on the previous post and everytime that I add something to the scrollView, it updates the scrollHeight value. As this is not instantly, I needed to use a timer because sometimes it was updating in wrong order.

To use this code, just change all “widget.newScrollView” to “fix.widget.newScrollView”.