Forum Discussion

cesarcarlos's avatar
cesarcarlos
Binge Watcher
3 years ago

"ObserveField visible" is not running when the screen appears

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?

3 Replies

  • RokuBen's avatar
    RokuBen
    Community Moderator

    Your topicScreen.ObserveField call is passing "OnDetailsScreenVisibilityChanged", but the method you want to call is "OnTopicScreenVisibilityChanged"

     

    • cesarcarlos's avatar
      cesarcarlos
      Binge Watcher

      Thanks, I fixed that, but that isn't affecting the issue. The observer that is not working is m.top.observeField("visible", "onVisibleChange") in the TopicScreen.brs file.

      • RokuBen's avatar
        RokuBen
        Community Moderator

        You won't be observer calls for fields that aren't changing.  I'd guess that your TopicScreen is created already visible in its parent.