Focus boundary example apps
This RSG 2.0 SDK app demonstrates the TypeScript-based FocusBoundary and useFocusable APIs for virtual focus management.
This app uses the FocusBoundary and useFocusable components from @roku-sdk/components, the pure-TypeScript approach to managing focus without relying on BrightScript's SceneGraph focus system.
Examples
The app includes these examples:
- Focus Boundary:
FocusBoundaryanduseFocusableAPI with section switching (menu to color picker) - Nested Focus Boundary: Nested
FocusBoundarycomposition with TypeScript-level key bubbling andrememberLastFocus - Navigation Map: Explicit
navigationMapinstead of the linearnavigationprop - Can Receive Focus:
canReceiveFocushandler for disabling and enabling items at runtime
Key concepts
These concepts apply across the examples:
FocusBoundaryis a pure TypeScript context provider that does not have a SceneGraph node.useFocusableprovides a reactiveisFocused()accessor for visual state.onKeyis a declarative map from keys to handlers.- The
onKeymap dispatches keys entirely in TypeScript. - Key bubbling happens through the
FocusBoundarychain in TypeScript.
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 4 hours ago
Did this page help you?