rokudev / SceneGraphDeveloperExtensions

Other
114 stars 64 forks source link

How to Manage Custom View ObserveField in MainScene? #39

Closed chaklasiyanikunj closed 4 years ago

chaklasiyanikunj commented 4 years ago

I created a Custom Component using an 8_Custom Screen. Now, I tried to manage ObserveField in Component. It's successfully managed that component like below. And I stored Custom View content in a custom view, not stored and not updated in MainScene.

Custom Component:

sub init()
    m.postergrid = m.top.findNode("FreeChannelsIDPosterGrid")
    m.postergrid.observeField("itemFocused", "OnPosterItemFocused") 'Here It's Working
end sub

But, I try to manage observeField in MainScene. But no luck. I also Refer GridView CreateNewOrUpdateGridNode() Function and something like applied a Custom View. But, also no luck. Here, My CustomView is Extends with Group and GridView Extends With SGDEXComponent. I also refer to this Example CustomGrid_ContentManager. In this example it's successfully managed. I also Put Interface Element in both XML File Custom View and MainScene. But no luck.

<field id="ItemFocused" type="integer" alwaysNotify="true" />

MainScene:

sub Show(args as Object)
    m.customView = CreateObject("roSGNode", "ChannelIDPosterGrid")
    m.customView.observeFieldScoped("itemFocused", "OnPosterItemFocused") 'Here It's not Working
    m.top.ComponentController.CallFunc("show", {
        view: m.customView
    })
end sub
sub OnPosterItemFocused(event as Object)
    m.grid = event.GetRoSGNode()
    ?"MainScene :: OnPosterItemFocused :: m.grid :" m.grid
end sub

Is there any way to handle ObserveField in MainScene.brs. I also tried with the ObserveFieldScoped Field. But no luck. or Is there any Configuration required to handle this.

chaklasiyanikunj commented 4 years ago

Any update regarding this?

RokuChris commented 4 years ago

There's nothing wrong with what you're trying to do. Observing fields on custom views from the scene level is supported. Without knowing more about what is happening inside your custom view, it's difficult to say what might be wrong.

chaklasiyanikunj commented 4 years ago

I added Successfully MSG Component PosterGrid as Custom Component in SGD View as below.

MainScene.brs

sub Show(args as Object)
    m.CustomPosterGridView = CreateObject("roSGNode", "ChannelIDPosterGrid")
    m.CustomPosterGridView.observeFieldScoped("itemFocused", "OnPosterItemFocused")
m.top.ComponentController.CallFunc("show", {
     view: m.CustomPosterGridView 
})
end sub
sub OnPosterItemFocused(event as Object)
    m.grid = event.GetRoSGNode()
    ?"MainScene :: OnPosterItemFocused :: m.grid :" m.grid
end sub

MainScene.xml

<component name="MainScene" extends="BaseScene">
<interface>
    <field id="ItemFocused" type="integer" alwaysNotify="true" />
</interface>
</component>

ChannelIDPosterGrid.xml

<component name = "ChannelIDPosterGrid" extends = "Group" initialFocus = "examplePosterGrid" > 
<interface>
    <field id="ItemFocused" type="integer" alwaysNotify="true" />
</interface>
  <script type = "text/brightscript" >
    <![CDATA[
    sub init()
      m.top.backgroundURI = "pkg:/images/rsgde_bg_hd.jpg"
      m.top.setFocus(true)
      m.postergrid = m.top.findNode("examplePosterGrid")
      m.postergrid.observeFieldScoped("itemFocused", "OnPosterItemFocused")
      m.postergrid.translation = [ 130, 160 ]
      m.readPosterGridTask = createObject("roSGNode", "ContentReader")
      m.readPosterGridTask.contenturi = "http://www.sdktestinglab.com/Tutorial/content/rendergridps.xml"
      m.readPosterGridTask.observeField("content", "showpostergrid")
      m.readPosterGridTask.control = "RUN"
    end sub
    sub OnPosterItemFocused(event as Object)
      m.grid = event.GetRoSGNode()
      ?"ChannelIDPosterGrid:: OnPosterItemFocused :: m.grid :" m.grid
    end sub
    sub showpostergrid()
      m.postergrid.content = m.readPosterGridTask.content
    end sub
    ]]>
  </script>
  <children>
    <PosterGrid
      id = "examplePosterGrid"
      basePosterSize = "[ 512, 288 ]"
      caption1NumLines = "1"
      numColumns = "2"
      numRows = "2"
      itemSpacing = "[ 20, 20 ]" />
  </children> 
</component>

Content-Meta-Data :

<Content >
  <item hdgridposterurl = "https://www.sdktestinglab.com/Tutorial/images/rectanglepg.jpg"
    shortdescriptionline1 = "Rectangle Node"
    x = "0" y = "0" />
  ...
</Content>

Any other Changes are required to enable ObserveField in MainScene?

RokuChris commented 4 years ago

I don't think the problem is with observing the field. I think your observer isn't firing because the value isn't changing. You are observing the itemFocused field on an instance of ChannelIDPosterGrid, but I don't see you ever changing that value in the component.

chaklasiyanikunj commented 4 years ago

I'm sorry, But, I don't understand clearly. I also tried with only observing itemfocused field in MainScene. But no luck. How to change a value? You considered focus as value? In postergrid component, focus changed automatically right. Using up,down,right and left key.

RokuChris commented 4 years ago

Yes, the itemFocused field on the PosterGrid will change with focus because PosterGrid is a firmware component with logic built in for updating that value.

The itemFocused field you are observing from your scene does not belong to a PosterGrid. The field you are observing belongs to your ChannelIDPosterGrid component and I don't see any logic in that component for updating the value. That's a completely different field from the one on the PosterGrid. If you want the field on your component to mirror the field on the PosterGrid, you can make is an alias. There is more about that here: https://developer.roku.com/docs/references/scenegraph/xml-elements/interface.md

chaklasiyanikunj commented 4 years ago

Ok Thank you, Now, For Focus, I'm Clearly Understand Clearly. It's Working fine, When I added alias in ChannelIDPosterGrid.xml like alias="examplePosterGrid.ItemFocused". But, It's a problem with the content. I tried to fetch the content using m.grid.content in MainScene. But no luck. I created another custom component For RowList. Here, Focus and content both are Working fine in MainScene using m.grid.content. and In PosterGrid Focus is Working fine. But, For a Content, It's Displayed "".Any other changes are required for Content in PosterGrid?