Focus boundary SG components example
This RSG 2.0 SDK app demonstrates FocusBoundary behavior with SceneGraph-backed components inside a TypeScript-driven focus flow.
This app isolates the FocusBoundary examples that mix native SceneGraph nodes with TypeScript focus management.
Examples
The app includes these examples:
- Directional Focus: A basic
FocusBoundarywith two horizontal SceneGraph Buttons and vertical navigation between rows. - Focus Boundary SG Button: A
FocusBoundarywith native SceneGraph Buttons and a LabelList as siblings. - Gain Focus Signal: Moves focus across native SceneGraph buttons declaratively by binding each leaf's
gainFocusto a signal. This example does not usesetFocus,useFocusActions,<Show>, or a remount. - Initial Focus Handoff: A preview-to-player handoff where each leaf is virtually registered (
useFocusable,gainFocus={isFocused()}) and focus follows the active stage throughinitialFocusand<Show>. This example does not usesetFocus, but it unmounts the inactive leaf on each handoff. - Imperative Focus: Two persistent native Button leaves move focus between each other through
useFocusActions().setFocus(ref)ononButtonSelected. This example does not use<Show>or a remount;gainFocus={isFocused()}follows the boundary. It is the imperative complement to the two declarative handoffs.
Key concepts
These concepts apply across the examples:
FocusBoundarycan coordinate focus across SceneGraph-backed components.useFocusablecan drivegainFocuson native nodes when they become virtually focused.- Mixed virtual and native controls can share a single TypeScript-driven navigation model.
- For a native SceneGraph leaf, the declarative focus mechanism is
gainFocus, notinitialFocus. You should bindgainFocusto a signal and change the signal to move focus; this approach does not requiresetFocusor a remount.initialFocusis read only at registration and boundary re-entry and is not reactive; as a result, it cannot move focus among leaves that are already mounted.
Controls
You can use these keys to navigate the app:
- Arrow keys: Navigate within and between focus boundaries
- OK: Activate the focused item
- Back: Return to the previous boundary or menu
Development
You can use these commands to build, test, and lint the app:
npx rk dev # Build + deploy to Roku device
pnpm test # Run tests
pnpm run lint # Lint sourcesUpdated about 6 hours ago
Did this page help you?