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: 
Veeta
Visitor

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 2
TheEndless
Channel Surfer

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
Visitor

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
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.