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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Key focus on children of custom component

I'm having a hard time getting a widget/component inside a custom component to get keypresses. I found that calling setFocus in the custom component's Init() doesn't fix this. Here's an example:

<component name="MyScreen" extends="Group">
vertFocusAnimationStyle = "floatingFocus" >
<ContentNode role="content">
<ContentNode title="Label1" />
<ContentNode title="Label2" />
<ContentNode title="Label3" />

I've tried a number of ways to get the keypresses to move the item selection on the LabelList content and the only thing that seems to work for me is the following hack.

Function Init()
m.LabelGroup ="Labels")
m.setFocusOnce = false
End Function

Function onKeyEvent(key As String, press As Boolean)
if not m.setFocusOnce then
m.setFocusOnce = true
return false
End Function

After this, the focus stays on the LabelGroup and works as expected, but I have to call it once AFTER the init() for it to gain focus. What am i missing? Something regarding construction order or the nodes?
0 Kudos
Channel Surfer

Re: Key focus on children of custom component

Have you tried adding the "initialFocus" attribute to the "component" tag?
My Channels: - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos

Re: Key focus on children of custom component

I haven't. Thanks for the suggestion. Primarily I was calling setFocus in various places.
0 Kudos