Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
Veeta
Level 7

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">
<children>
<LabelList
id="Labels"
vertFocusAnimationStyle = "floatingFocus" >
<ContentNode role="content">
<ContentNode title="Label1" />
<ContentNode title="Label2" />
<ContentNode title="Label3" />
</ContentNode>
</LabelList>
</children>
</component>


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 = m.top.findNode("Labels")
m.setFocusOnce = false
End Function

Function onKeyEvent(key As String, press As Boolean)
if not m.setFocusOnce then
m.LabelGroup.setFocus(true)
m.setFocusOnce = true
endif
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
2 Replies
TheEndless
Level 7

Re: Key focus on children of custom component

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

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