When adding widget.newButton into scroll view i cant scroll.

So when i add a widget.newButton into my scrollView and click on it and try to scroll it doesn’t scroll.

Here’s a sample.

Simulated in a border-less android 1080x1920.

 local widget = require( "widget" ) local function scrollListener( event ) local phase = event.phase local direction = event.direction if "began" == phase then --print( "Began" ) elseif "moved" == phase then --print( "Moved" ) elseif "ended" == phase then --print( "Ended" ) end -- If the scrollView has reached its scroll limit if event.limitReached then if "up" == direction then --print( "Reached Top Limit" ) elseif "down" == direction then --print( "Reached Bottom Limit" ) elseif "left" == direction then --print( "Reached Left Limit" ) elseif "right" == direction then --print( "Reached Right Limit" ) end end return true end local scrollView = widget.newScrollView { x = display.contentCenterX, y = display.contentCenterY, width = display.actualContentWidth, height = display.actualContentHeight, horizontalScrollDisabled = true, listener = scrollListener } local box = widget.newButton { x = display.contentCenterX, y = display.contentCenterY, shape = "rect", width = 100, height = 100, } box:setFillColor( 1, 0, 0 ) scrollView:insert(box)

Thanks for an advice!

–SonicX278

Look at the takeFocus method of the newScrollView : https://docs.coronalabs.com/api/type/ScrollViewWidget/takeFocus.html

Yes I did. Didn’t seem to work.

–SonicX278

On our side, we are using the takeFocus and it work perfectly. However we do not use the button class of Corona, we are using our own custom class for our buttons.

Would you mind getting the code above and trying your method on it??

–SonicX278

I try the code from the documentation with our scrollview code and it work perfectly. Here is an extract of the code…

Of course some variable are not defined as I simply did a copy / paste and use the sample code from the Corona doc. The only diff I see with your code is your listener. Try to remove your listener just for testing it.

-- CODE FROM OUR APP local scrollArea = widget.newScrollView { left = 0, top = uiLib.viewY, width = screenW, height = screenH - uiLib.bottomBar - uiLib.viewY, hideBackground = true, horizontalScrollDisabled = true, scrollWidth = screenW, scrollHeight = screenH - uiLib.topBarH, scrollBarOptions = uiLib:getScrollBarInfo() } scene.uiGroup:insert(scrollArea) -- code from the documentation (UNTOUCHED) -- The touch listener function for the button (created below) local function handleButtonEvent( event ) local phase = event.phase if ( phase == "moved" ) then local dy = math.abs( ( event.y - event.yStart ) ) -- If the touch on the button has moved more than 10 pixels, -- pass focus back to the scroll view so it can continue scrolling if ( dy \> 10 ) then scrollArea:takeFocus( event ) end end return true end local button1 = widget.newButton { left = 100, top = 200, id = "button1", label = "Default", onEvent = handleButtonEvent } scrollArea:insert( button1 )

@SonicX278, were you successful with this ?

Yes I was! Thank you! I’m just on vacation right now so I don’t have WiFi all the time. But yes I got it to work with a little tweaking. Thanks!

–SonicX278

Look at the takeFocus method of the newScrollView : https://docs.coronalabs.com/api/type/ScrollViewWidget/takeFocus.html

Yes I did. Didn’t seem to work.

–SonicX278

On our side, we are using the takeFocus and it work perfectly. However we do not use the button class of Corona, we are using our own custom class for our buttons.

Would you mind getting the code above and trying your method on it??

–SonicX278

I try the code from the documentation with our scrollview code and it work perfectly. Here is an extract of the code…

Of course some variable are not defined as I simply did a copy / paste and use the sample code from the Corona doc. The only diff I see with your code is your listener. Try to remove your listener just for testing it.

-- CODE FROM OUR APP local scrollArea = widget.newScrollView { left = 0, top = uiLib.viewY, width = screenW, height = screenH - uiLib.bottomBar - uiLib.viewY, hideBackground = true, horizontalScrollDisabled = true, scrollWidth = screenW, scrollHeight = screenH - uiLib.topBarH, scrollBarOptions = uiLib:getScrollBarInfo() } scene.uiGroup:insert(scrollArea) -- code from the documentation (UNTOUCHED) -- The touch listener function for the button (created below) local function handleButtonEvent( event ) local phase = event.phase if ( phase == "moved" ) then local dy = math.abs( ( event.y - event.yStart ) ) -- If the touch on the button has moved more than 10 pixels, -- pass focus back to the scroll view so it can continue scrolling if ( dy \> 10 ) then scrollArea:takeFocus( event ) end end return true end local button1 = widget.newButton { left = 100, top = 200, id = "button1", label = "Default", onEvent = handleButtonEvent } scrollArea:insert( button1 )

@SonicX278, were you successful with this ?

Yes I was! Thank you! I’m just on vacation right now so I don’t have WiFi all the time. But yes I got it to work with a little tweaking. Thanks!

–SonicX278