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: 
belltown
Roku Guru

Re: Back key not closing RSG Dialogs

I don't see why setting m.top.dialog in the child component wouldn't work. Are you setting this in one of the event-handlers in the child's brs code? And is keyboardDlg set up correctly when assigning it to m.top.dialog in the child component?
0 Kudos
marcelo_cabral
Roku Guru

Re: Back key not closing RSG Dialogs

"belltown" wrote:
I don't see why setting m.top.dialog in the child component wouldn't work. Are you setting this in one of the event-handlers in the child's brs code? And is keyboardDlg set up correctly when assigning it to m.top.dialog in the child component?

Here is the full code, if I choose line tagged as Option 1 it works,  if I switch to the option 2, nothing happens:
sub OnItemSelected()
    m.index = m.top.itemSelected
    if m.index = 0
        print "about selected"
    else if m.index < 3
        print "open keyboard"
        m.keyboardDlg = createObject("RoSGNode", "KeyboardDialog")
        m.keyboardDlg.title = "Login"
        m.keyboardDlg.text  = " "
        m.keyboardDlg.observeField("buttonSelected", "OnButtonSelected")
        m.keyboardDlg.observeField("text", "OnTextChanged")
        if m.index = 1
            m.keyboardDlg.message = "Entre o e-mail do usuário:"
            if m.global.user <> ""
                m.keyboardDlg.text  = m.global.user
            else
                m.keyboardDlg.text = "@email.com"
            end if
            m.keyboardDlg.keyboard.textEditBox.secureMode = false
        else if m.index = 2
            m.keyboardDlg.message = "Entre a senha do usuário:"
            m.keyboardDlg.text  = ""
            m.keyboardDlg.keyboard.textEditBox.secureMode = true
        end if
        [OPTION 1] m.top.scene.dialog = m.keyboardDlg <========= Dialog is Shown
        [OPTION 2] m.top.dialog = m.keyboardDlg <============= Nothing happens
    else
        m.infoLabel.text = ""
        item = m.optionsList.content.getChild(2).getChild(m.index - 3)
        if item.id <> m.global.maxRes
            m.global.maxRes = item.id
            LoadMenuItems()
            m.optionsList.jumpToItem = m.index
        end if
    end if
end sub

0 Kudos
belltown
Roku Guru

Re: Back key not closing RSG Dialogs

I'm not really sure what's going on. All I could come up with is that when OnItemSelected is called, if the component does not have focus, and therefore is not the "current Scene node" then setting that component's dialog will have no effect because, "Setting the dialog field of the current Scene node to a Dialog node causes the dialog to be displayed".
0 Kudos
EnTerr
Roku Guru

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?

Because not every component has a .dialog property.
Only Scene nodes have that property.
And since saw elsewhere we should use only one and only scene, that means there is only one such node per RSG.

His question is how can i find the scene from one of the children, nested levels down?
I suppose can just walk the tree up:
nxt = m.top
while nxt <> invalid:
 scene = nxt
 nxt = scene.getParent()
end while
' at this point `scene` is the top-most node `
0 Kudos
marcelo_cabral
Roku Guru

Re: Back key not closing RSG Dialogs

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

Because not every component has a .dialog property.
Only Scene nodes have that property.
And since saw elsewhere we should use only one and only scene, that means there is only one such node per RSG.

His question is how can i find the scene from one of the children, nested levels down?
I suppose can just walk the tree up:
nxt = m.top
while nxt <> invalid:
 scene = nxt
 nxt = scene.getParent()
end while
' at this point `scene` is the top-most node `


Thanks again EnTerr! 
The ideal would be to have it available as the global, once all child screens should be able to open dialogs, but anyway I will keep my implementation.
0 Kudos
belltown
Roku Guru

Re: Back key not closing RSG Dialogs

"EnTerr" wrote:
Because not every component has a .dialog property.
Only Scene nodes have that property.
And since saw elsewhere we should use only one and only scene, that means there is only one such node per RSG.

I get it now. I was confusing components with Scenes. Yes, there's only one Scene generally, so that's where you need to set the dialog.

I hadn't come across this issue myself because most of my dialogs are "custom" components, not real Dialog components, but they behave as modal dialogs. I show/hide them instead of setting scene.dialog. The only time I use actual Dialog components are in my main Scene, so m.top.dialog works.

So yes, EnTerr's solution should get the Scene m.top, or just pass it in as a component interface field -- or, since there's only one Scene, set m.global.scene = m.top
0 Kudos
NB_
Roku Guru

Re: Back key not closing RSG Dialogs

or you can do
            scene = invalid
           for each nod in m.top.getRoots():
               if nod.isSubType("scene") then scene = nod: exit for
           next

This should work, if there is one and only one scene (which seems like a sane assumption)
0 Kudos
belltown
Roku Guru

Re: Back key not closing RSG Dialogs

"RokuNB" wrote:
or you can do

m.top.getRoots()


According to the docs, the note above getRoots() states: The following methods can be called on any subject node and return the same global results. They can be used in a development channel for debugging purposes, but should not be used in a production channel. and then it goes on to say: Any calls to getAll(), getRoots(), getRootsMeta() and getAllMeta() should be removed from your production channels.
0 Kudos
NB_
Roku Guru

Re: Back key not closing RSG Dialogs

"belltown" wrote:
According to the docs, the note above getRoots() states: The following methods can be called on any subject node and return the same global results. They can be used in a development channel for debugging purposes, but should not be used in a production channel. and then it goes on to say: Any calls to getAll(), getRoots(), getRootsMeta() and getAllMeta() should be removed from your production channels.

The wisdom behind of that statement is not immediately apparent to me. It is possible that some of these functions are grossly inefficient (but ok for debug). It might be prudent then to use the previous idea of getParent() to the root.
0 Kudos
belltown
Roku Guru

Re: Back key not closing RSG Dialogs

"RokuNB" wrote:
"belltown" wrote:
According to the docs, the note above getRoots() states: The following methods can be called on any subject node and return the same global results. They can be used in a development channel for debugging purposes, but should not be used in a production channel. and then it goes on to say: Any calls to getAll(), getRoots(), getRootsMeta() and getAllMeta() should be removed from your production channels.

The wisdom behind of that statement is not immediately apparent to me. It is possible that some of these functions are grossly inefficient (but ok for debug). It might be prudent then to use the previous idea of getParent() to the root.

I'd be curious to know the wisdom as well. It did refer to these features as diagnostic tools in the Developer Blog post that announced their availability: https://blog.roku.com/developer/2016/06/21/roku-os-7-2-dev-highlights/. You wouldn't normally use diagnostic (debugging?) tools in production code, but it doesn't explain why these particular tools shouldn't be used in production.
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.