Scollview Buttons on Focus Issue

Hey everyone,

I’m missing something obvious here, but my brain is fried from working on this project for too long. I have a scroll view of buttons, but if you try to scroll while touching a button, nothing happens. The obvious answer is to use “takeFocus”. However, I still need the onRelease functionality to change scenes and I can only use onRelease = osteoView or onEvent = buttonTouch , but not both.

No idea why I can’t figure this out.

local storyboard = require "storyboard" local widget = require("widget") local scene = storyboard.newScene(); --Called if the scene hasn't been previously seen function scene:createScene( event )          -- Button Functions     local function osteoView( event )         storyboard.gotoScene( "osteomyelitis", {effect="crossFade", time= 400} )     end     -- Create New Group     local dataGroup = self.view          -- Create a ScrollView     local scrollView = widget.newScrollView     {         left = 0,         top = 0,         width = display.contentWidth,         height = display.contentHeight,         bottomPadding = 50,         id = "scrollView",         horizontalScrollDisabled = true,         verticalScrollDisabled = false,         listener = scrollListener,         hideBackground = true,     }     local function buttonTouch( event )         local phase = event.phase         if "moved" == phase then             local dy = math.abs( ( event.y - event.yStart ) )             -- If our finger has moved more than the desired range             if dy \> 10 then                 -- Pass the focus back to the scrollView                 scrollView:takeFocus( event )            end         end         return true     end          -- Create Buttons     local btn1 = widget.newButton     {         defaultFile = "images/blueBtn.png",         label = "Acute & Chronic Osteomyelitis",         fontSize = 16,         labelColor = {             default = {255},             over = {39,135,184},         },         --onRelease = osteoView,         onEvent = buttonTouch,     }  

I have over 30 buttons in the scrollView, so right now if you’re touching any of the buttons, it won’t scroll, you have to touch between the buttons and then scroll. Need more coffee…

It looks like you’re doing the right thing.  onRelease is like a tap event in that you don’t get various phases like a touch event, so there is no moved phase to detect.  By using onEvent you should get a moved phase and in there you can pass the event on.  The only thing I see is that you might want to do a “return false”  right after you call the takeFocus() call.   

Rob

What would the function be to make the buttons react to changing storyboard scenes and also reacting to scrolling?

I tried 

local function osteoView( event )         if event.phase == "moved" then             local dy = math.abs(event.y - event.yStart)                 if dy \> 10 then                 scrollView:takeFocus( event )                    print("scrolling")                end           elseif event.phase == "ended" then                print("Go to osteo!")                storyboard.gotoScene( "osteomyelitis", {effect="crossFade", time= 400} )             end         return false     end  

Which technically works, but the button you tapped on to scroll automatically changes the label color forever until you tap on it to change scenes.

scrollview.png

Here you can see what two buttons I touched to scroll up and down. I even removed the over phase, which didn’t help, the label still change color.

local btn1 = widget.newButton     {         defaultFile = "images/blueBtn.png",         label = "Acute & Chronic Osteomyelitis",         fontSize = 16,         labelColor = {             default = {255},         },         onEvent = osteoView     }     btn1.x = display.contentCenterX;     btn1.y = introText.y + introText.contentHeight + 40;     scrollView:insert(btn1);  

I was thinking more like:

local function osteoView( event )         if event.phase == "moved" then             local dy = math.abs(event.y - event.yStart)                 if dy \> 10 then                 scrollView:takeFocus( event )                    print("scrolling")                    return false                end           elseif event.phase == "ended" then                print("Go to osteo!")                storyboard.gotoScene( "osteomyelitis", {effect="crossFade", time= 400} )             end         return true     end

You still need to return true to keep the event from propagating other wise.

Thanks, Rob. I used your code, but unfortunately, it still results in the labels changing color even without an over phase.

Here’s a quick video demo to show you rather than try to explain it.

http://www.youtube.com/watch?v=BnUR6LfbPHM

I’m going to suggest you file a bug report on this.  I’m not sure this is a condition that the button’s were meant to do, but the label should restore afterwards.   So file a bug report and see if engineering can fix it.

Rob

Okay, thanks Rob. I just submitted a bug report.

Before I sent it in, I actually updated to yesterday’s daily build and tested it on my iPhone 5 and got the same result. I just wanted to make sure it wasn’t old build/simulator related.

I stripped it down to a bare-bones example and it still has the same issues in case you’d like to see it: http://www.gpanimations.com/scrollview.zip

It looks like you’re doing the right thing.  onRelease is like a tap event in that you don’t get various phases like a touch event, so there is no moved phase to detect.  By using onEvent you should get a moved phase and in there you can pass the event on.  The only thing I see is that you might want to do a “return false”  right after you call the takeFocus() call.   

Rob

What would the function be to make the buttons react to changing storyboard scenes and also reacting to scrolling?

I tried 

local function osteoView( event )         if event.phase == "moved" then             local dy = math.abs(event.y - event.yStart)                 if dy \> 10 then                 scrollView:takeFocus( event )                    print("scrolling")                end           elseif event.phase == "ended" then                print("Go to osteo!")                storyboard.gotoScene( "osteomyelitis", {effect="crossFade", time= 400} )             end         return false     end  

Which technically works, but the button you tapped on to scroll automatically changes the label color forever until you tap on it to change scenes.

scrollview.png

Here you can see what two buttons I touched to scroll up and down. I even removed the over phase, which didn’t help, the label still change color.

local btn1 = widget.newButton     {         defaultFile = "images/blueBtn.png",         label = "Acute & Chronic Osteomyelitis",         fontSize = 16,         labelColor = {             default = {255},         },         onEvent = osteoView     }     btn1.x = display.contentCenterX;     btn1.y = introText.y + introText.contentHeight + 40;     scrollView:insert(btn1);  

I was thinking more like:

local function osteoView( event )         if event.phase == "moved" then             local dy = math.abs(event.y - event.yStart)                 if dy \> 10 then                 scrollView:takeFocus( event )                    print("scrolling")                    return false                end           elseif event.phase == "ended" then                print("Go to osteo!")                storyboard.gotoScene( "osteomyelitis", {effect="crossFade", time= 400} )             end         return true     end

You still need to return true to keep the event from propagating other wise.

Thanks, Rob. I used your code, but unfortunately, it still results in the labels changing color even without an over phase.

Here’s a quick video demo to show you rather than try to explain it.

http://www.youtube.com/watch?v=BnUR6LfbPHM

I’m going to suggest you file a bug report on this.  I’m not sure this is a condition that the button’s were meant to do, but the label should restore afterwards.   So file a bug report and see if engineering can fix it.

Rob

Okay, thanks Rob. I just submitted a bug report.

Before I sent it in, I actually updated to yesterday’s daily build and tested it on my iPhone 5 and got the same result. I just wanted to make sure it wasn’t old build/simulator related.

I stripped it down to a bare-bones example and it still has the same issues in case you’d like to see it: http://www.gpanimations.com/scrollview.zip

This appears to be an iOS issue. I did device testing on an HTC Thunderbolt, Samsung Galaxy Tab 7, iPad 3, and iPhone 5 and the labels changing color only happens on the iOS devices. I submitted it as a bug on 11/09/2013, but haven’t heard anything.

Please post the bug ID number here for reference.

Thanks

Rob

(Case 27760) Button Label Color Change in Scroll View

This appears to be an iOS issue. I did device testing on an HTC Thunderbolt, Samsung Galaxy Tab 7, iPad 3, and iPhone 5 and the labels changing color only happens on the iOS devices. I submitted it as a bug on 11/09/2013, but haven’t heard anything.

Please post the bug ID number here for reference.

Thanks

Rob