Skip to end of metadata
Go to start of metadata

Views are full-screen SceneGraph Developer Extension components that can be used as a template to build a view instead of creating one from scratch. SceneGraph Developer Extensions (SGDEX) supports out of the box stacking of the views. This means that you can add as many views to a stack as you want, and SGDEX will handle back button closing function of the view as well as add support for events when the view is:

  • Opened
  • Closed
  • Hidden because next view is displayed
  • Manually closed 

The component ViewStack is designed to work with any Roku SceneGraph (RSG) component or a SGDEX view.

Focus Handling

View stack handles basic focus when the view is opened or restores focus when it's closed.

According to Roku best practices, a view should handle focus by itself. ViewStack sets focus to view by implementing view.setFocus(true).

The view implements focus handling as follows:


Don't set focus to the view before adding it to ViewStack as it sets focus to a previous view.

Note: Dialogs are not supported by ViewStack, use scene.dialog field instead. 


Opening a new view

To add (open) a new view to the stack, use:

Receiving an event when the view is closed

If you want to be notified when the view is closed either manually or when the user has pressed back (observeField wasClosed), use the following:

Closing a view manually

To close a view manually, use the close field of view. This is useful when the channel needs to show the login flow after a successful login. 

Note: Close field is added by ViewStack.

The developer can close any view in the stack, even if it is not on the top. 

Component Controller

Using the component controller assists with implementing as well as managing the view stack. It essentially implements the basic default view management. Component Controller has fields to enable view development for building a channel using SceneGraph Developer Extensions. Refer to ComponentController Component for more details. 

Component Controller Fields

  • currentView - Links to the view that is currently shown by ViewStack (This view represents the view that is shown by ViewStack. If another view without using ViewStack is shown, it wouldn't be reflected here)
  • allowCloseChannelOnLastView - If true, the channel closes when the back button is pressed or if the previous view set the view's close field to true
  • allowCloseLastViewOnBack - If true, the current view is closed, and the user can open another view through the new view's wasClosed callback
  • No labels