Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
fyvekatz
Newbie

Moving focus from a child to a parent

I've been having an issue changing focus from a RowList component to the HomeScene object that the RowList component is indirectly a part of. An abbreviated version of the component hierarchy:

<component name="HomeScene" extends="Scene"...
   <children>
      <Rectangle>
         <Channels Grid />
 
Where Channels Grid derives from RowList:
 
<component name="ChannelsGrid" extends="RowList"...
 
In the init() for my HomeScene, I set the focus to the scene and everything was fine:
 
m.top.setFocus(true)
 
I have an onKeyEvent handler in the HomeScene which successfully sets focus to the ChannelsGrid when the down button is pressed:
 
function onKeyEvent(key as String, press as Boolean) as Boolean

  handled = false
  if press then
      if m.top.hasFocus()
        if key = "left" OR key = "right"
             <do_stuff>
        else if key = "down"
                m.channelsGrid.setFocus(true)
                handled = true
        end if
      else if m.channelsGrid.hasFocus()
            if key = "back"
                m.channelsGrid.setFocus(false)   'Line that solved the problem
                m.top.setFocus(true)
                handled = true
            end if
      end if
  end if

return handled
end function
    
  
So the code reads:
  • Handle "left" and "right" from HomeScene.
  • If "down" is pressed, move focus to the ChannelsGrid (RowList)
  • If "back" is pressed while focus is on the ChannelsGrid, set focus back to the HomeScene.

This never transferred focus back to the HomeScene. I would even test the focus value in back to back lines:

 

? m.top.setFocus(true)
? m.top.hasFocus()

And it would print out:

true
false

I then manually set focus to false for the HomeScene and it started to work as desired:

m.channelsGrid.setFocus(false)
m.top.setFocus(true)

But I read in the docs that you should never do this. I don't want to just take the win and move forward because there's something that I don't understand about how focus works. Some clarification would be greatly appreciated.

2 REPLIES 2
curiousDev
Newbie

Re: Moving focus from a child to a parent

Hi. Were you able to figure this out ? What OS version was the device ?

0 Kudos
RowanG1Bilue
Binge Watcher

Re: Moving focus from a child to a parent

Anyone figured this out yet?

0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.