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: 

Back key not closing RSG Dialogs

I'm finishing a new RSG channel and it was based on the Hero Grid Channel sample (https://github.com/rokudev/hero-grid-channel).

After all my implementation and changes I noticed that the Dialog used to show warnings and the KeyboardDialog I added to a screen, are not closing when the "back" remote key is pressed.

There is still only one "onKeyEvent" for the whole channel, located at the Scene brs script. I noticed that the "back" "press" event is never triggered at this function, indicating it was handled somewhere else before the scene, but the dialog is not closed. I also noticed that setting the "close" property to true, as described at the documentation, also is not closing the dialog.

I can't figure out what I did that could have caused this, but I thing it is wrong behaviour, because the documentation says clearly that the "back" key always close dialogs.

Anyone have a good clue for me ?
0 Kudos
20 Replies
Roku Employee
Roku Employee

Re: Back key not closing RSG Dialogs

i haven't read that sample - are the "Dialog used to show warnings and the KeyboardDialog" part of it (then pls mention which file/component) or something you added? who has the input focus at that time, when they are up?
0 Kudos

Re: Back key not closing RSG Dialogs

"RokuNB" wrote:
i haven't read that sample - are the "Dialog used to show warnings and the KeyboardDialog" part of it (then pls mention which file/component) or something you added? who has the input focus at that time, when they are up?

The warning Dialog is part of it not the KeyboardDialog. But neither is behaving properly. 

Some of my code related to the KeyboardDialog.

The XML has:
        <KeyboardDialog
            id="KeyboardDialog"
            text=" "
            visible="false" />

The script Init:
m.keyboardDlg = m.top.findNode("KeyboardDialog")
m.keyboardDlg.observeField("buttonSelected", "OnButtonSelected")
m.keyboardDlg.observeField("text", "OnTextChanged")


To show the dialog I'm using:
m.keyboardDlg.title = "User Login"
m.keyboardDlg.buttons = ["OK", "Cancel"]
m.keyboardDlg.visible = true
m.keyboardDlg.focusButton = 0
m.keyboardDlg.setFocus(true)


Everything works as expected, except the back key that does not close the dialog.

And actually in the documentation there is no declared way to prevent pressing "back" from closing the dialog.
0 Kudos
EnTerr
Level 8

Re: Back key not closing RSG Dialogs

"marcelo.cabral" wrote:
Everything works as expected, except the back key that does not close the dialog.

And actually in the documentation there is no declared way to prevent pressing "back" from closing the dialog.

Your sentences - read together - are confusing. One complains Back does not close the dialog, the next says there is no way to prevent dialog from being closed...

Now, i know how to display a modal dialog in a scene and that is by setting scene's dialog property, i.e.
myScene.dialog = myDialog
myScene.optionsDialog = true ' if you want `*` to also close it '

That's all - from there on the scene will take care of displaying it modal and hold it on for dear life - that is, until Back button is pressed or say you set myScene.close = true ...

So i think the magic ingredient is to let the scene handle it. If not, i assume dialogs behave as generic windows...
0 Kudos

Re: Back key not closing RSG Dialogs

"EnTerr" wrote:
"marcelo.cabral" wrote:
Everything works as expected, except the back key that does not close the dialog.

And actually in the documentation there is no declared way to prevent pressing "back" from closing the dialog.

Your sentences - read together - are confusing. One complains Back does not close the dialog, the next says there is no way to prevent dialog from being closed...

Sorry for the confusion, what I meant with the second sentence was that even if I wanted to prevent the back button to close the Dialog, based on the documentation, there is not way to do it.
This was to emphasize that in my view it's either a bug, or a missing information in the documentation.

"EnTerr" wrote:

Now, i know how to display a modal dialog in a scene and that is by setting scene's dialog property, i.e. 
myScene.dialog = myDialog
myScene.optionsDialog = true ' if you want `*` to also close it '

That's all - from there on the scene will take care of displaying it modal and hold it on for dear life - that is, until Back button is pressed or say you set myScene.close = true ...

So i think the magic ingredient is to let the scene handle it. If not, i assume dialogs behave as generic windows...

Hmmm, the documentation again does not make it clear that the dialog would only respond to a back if is assigned to the scene dialog property. And if it is supposed to act as a regular screen, in my scenario, then the "press" event for the "back" button should be generated at the only "onKeyEvent" of the channel, don't you agree?
0 Kudos

Re: Back key not closing RSG Dialogs

I found one place at the documentation that mentions that we should use the scene dialog property: " For example, to create the dialog object and assign it to the dialog field of a Scene node defined in a component XML file (which is the required usage of the Dialog node class)" from
https://sdkdocs.roku.com/display/sdkdoc/Scene+Graph+Data+Scoping#SceneGraphDataScoping-m.topComponen...

The problem is the example provided by Roku (that I based my implementation on) does not follow this "requirement", by defining the Dialog named "WarningDialog" in the Screen xml. So I believe the documentation needs to be improved on Dialog node usage, and the fact it "swalows" the back key in some situations is a bug for me.
0 Kudos
belltown
Level 7

Re: Back key not closing RSG Dialogs

What you're both saying aligns with my experience: A dialog isn't a dialog unless you assign it to the Scene's dialog field.

Once that's been done, the Back button will be handled automatically by the dialog and close the dialog. You won't get a keypress event for Back (in this case), which is consistent with what the documentation says.

The Roku example appears flawed. Surprise, surprise! At least it's on GitHub, so you can submit an issue and/or pull request.
https://github.com/belltown/
0 Kudos

Re: Back key not closing RSG Dialogs

I managed to make it work, thank you guys.

Another question: I want to show the dialog from a script that is in a screen brs not the scene brs, there is any way I can access the "parent" scene from there ?
The way I implemented was to pass the reference for the scene down to the screen using a field:
    else if key = "options"
      if m.DetailsScreen.visible = false
          m.OptionsScreen.scene = m.top
          m.OptionsScreen.visible = true
          m.OptionsList.setFocus(true)
      end if
0 Kudos
belltown
Level 7

Re: Back key not closing RSG Dialogs

Why do you need the parent's m.top? Can't you set the child's m.top.dialog to the Dialog?
https://github.com/belltown/
0 Kudos

Re: Back key not closing RSG Dialogs

"belltown" wrote:
Why do you need the parent's m.top? Can't you set the child's m.top.dialog to the Dialog?

When I set to m.top.dialog at the child screen the dialog never showed, but this way setting in the child screen script it works:
m.top.scene.dialog = keyboardDlg

PS. Considering that I passed down the Scene node as the code in my previous post
0 Kudos