0

I am working on an app for Roku using BrightScript and SceneGraph. I have a postergrid where a user selects between a number of posters. When the user selects one, the ShowTopicScreen sub is called:

ShowTopicScreen.brs

sub ShowTopicScreen(topic as Object)
    topicScreen = CreateObject("roSGNode", "TopicScreen")
    topicScreen.content = topic
    topicScreen.ObserveField("visible", "OnDetailsScreenVisibilityChanged")
    ShowScreen(topicScreen)
    end sub

    sub OnTopicScreenVisibilityChanged(event as Object)
    visible = event.GetData()
    currentScreen = GetCurrentScreen()
    screenType = currentScreen.SubType()
    if visible = false
        if screenType = "HomeScreen"
            currentScreen.jumpToItem = m.selectedTopicIndex
        end if
    end if
end sub

The Topic Screen is supposed to read the content data and populate a label and load certain data to a rowlist (which is still under development)

TopicScreen.xml

<?xml version="1.0" encoding="UTF-8"?>

    <component name="TopicScreen" extends="Group" initialFocus="topicList">
    <script type="text/brightscript" uri="TopicScreen.brs" />
    
    <interface>
        <!-- Specifies the content for the Grid -->
        <field id="content" type="assocarray" />
        <field id="topiccontent" type="node" alias="topicList.content" />
        <field id="rowItemSelected" type="intarray" alwaysnotify="true" alias="topicList.rowItemSelected" />
        <field id="jumpToRowItem" type="intarray" alias="topicList.jumpToRowItem" />
    </interface>
    <children>
        <Label
            id="titleLabel"
            width="1020"
            translation="[105,170]"
        />

        <Label
            id="textLabel"
            width="1020"
            translation="[105,190]"
            text="A test label"
        />
         
        <RowList
            itemComponentName="TopicRowListItemComponent"
            id="topicList"
            translation="[105,240]"
            numRows="2"
            rowitemSize="[[320,180]]"
            rowItemSpacing="[[20,0]]"
            itemSize="[1100,270]"
            rowLabelOffset="[[50,20]]"
            focusXOffset="[50]"
            showRowLabel="[true]"
            rowFocusAnimationStyle="floatingfocus"
        />
    </children>
    </component>

TopicScreen.brs

sub Init()
    m.top.observeField("visible", "onVisibleChange")

    m.titleLabel = m.top.FindNode("titleLabel")
    end sub

    sub onVisibleChange()
    'this only runs when I leave the screen
    if m.top.visible = true
        SetContent()
    end if
    end sub

    sub SetContent() 
    m.titleLabel = m.top.topic.title
end sub

The problem is that the OnVisibleChange sub is never called (it is called when I press the back button to go to the first screen, however, if I go back to the topics screen, again it's not called). The TopicScreen is loading as I can see the static label ("A test label") on screen.

Why if the OnVisibleChange() sub not being called and how can I get the data to populate the label?

TwitchBronBron
  • 2,783
  • 3
  • 21
  • 45
cesarcarlos
  • 1,271
  • 1
  • 13
  • 33

1 Answers1

1

Your observer will only be fired if the visible field changes from one value to the other, unless you have defined notifyAlways as true for that field, but regardless, the observer callback fires off after the visible value is assigned. I don't see anywhere in your code how are you assigning the visible value.

Maybe you want to observe renderTracking instead? See more details in the Group class reference.

sub init()
  (...)

  m.top.enableRenderTracking = true
  m.top.observeField("renderTracking", "onVisibilityChange")
end sub

sub onVisibilityChange()
  if m.top.renderTracking = "full" ' Based on your needs you might want to check for "partial" as well.
      (...)
  end if
end sub
Alejandro Cotilla
  • 2,501
  • 1
  • 20
  • 35