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: 
michelperez
Visitor

How to expose fields obtained inside screen to main thread for a SignIn component

Hi, I'm trying to create a SignIn component, but once I get username and password from the user in my component I can't "export" them back to the main thread. This is what I'm trying right now:
<component name = "SignInScene" extends = "Scene" >
  <script type = "text/brightscript" >
    <![CDATA[
    sub init()
       m.communicator = m.top.findNode("communicator")
       m.communicator.addField("password", "roString", true)
      ...
   end sub

    sub onPasswordKeyboardBtnSelected(roEvent)
     if roEvent.getData() = 0 then
        if m.password <> "" and m.password <> invalid then
            m.communicator.setField("password", m.password)
            ...
        end if
     end if
    end sub

   <children>
     <Label id="communicator"/>
   </children>
</component>


Now, in main.brs I have:


   screen = CreateObject("roSGScreen")
   m.port = [i]CreateObject[/i]("roMessagePort")
    screen.setMessagePort(m.port)
    scene = screen.CreateScene("SignInScene")
    screen.Show()
    
    scene.findNode("communicator").observeField("password", m.port)
    
     while (true)
        msg = wait(0, m.port)
        msgType = type(msg)
        LogToConsole(msgType)
    
        if msgType = "roSGScreenEvent"
          if msg.isScreenClosed() then return
        end if
      end while


When I set field "password" and I try a `getField` after that I get `invalid`, also nothing is caught in the main thread. Basically what I want is a way to pass login data out of the component. Is this the better approach? What am I doing wrong?

Thanks!!
0 Kudos
2 REPLIES 2
renojim
Community Streaming Expert

Re: How to expose fields obtained inside screen to main thread for a SignIn component

I think you're making it more complicated than it needs to be.  Just set the label's text value to the password/username.
<children>
  <Label id="password" translation="[0,0]" text="" visible="false" />
</children>

password = m.top.findNode("password")
...
password.text = "user's password"

In your main thread:
sg = createObject("roSGScreen")
scene = sg.createScene("SignInScene")
sg.Show()
sg.setMessagePort(m.port)
password = scene.findNode("password")
password.observeField("text", m.port)
while(true)
  msg = wait(0,m.port)
  msgType = type(msg)
  print "msgType: ";msgType

  if msgType = "roSGScreenEvent" then
     if msg.isScreenClosed() then
        print "isScreenClosed"
        exit while
     end if
  else if msgType = "roSGNodeEvent" then
     passwordText = password.text
  end if
end while

I hope that's enough to get the point across.  It may not be the best approach, but it works for me.

-JT
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
michelperez
Visitor

Re: How to expose fields obtained inside screen to main thread for a SignIn component

Hi renojim,[/color]

Thank you so much!!, that worked like a charm, you are the man!. For some reason I had a hard time finding an answer for this, which seems an obvious workflow, Roku samples from the guide are incomplete they show you how to create a keyboard component or a pin dialog but they don't mention how to interact with it, docs are lacking on that area.

Thanks!!!!
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.