Roku:在不更改当前焦点项的情况下更新 RowList 内容

Roku : Update RowList content without changing current focus item

有没有办法在关注当前 selected/highlighted 行项目的同时将项目更新或附加到 RowList 内容?

rowList中的每一行都是一个异步加载的独立列表。 rowList 通过 observeField 方法更新(图 1)。问题在于,当新内容添加到行列表时,焦点会重置回第一行中的第一项。我想将注意力集中在用户导航到的任何行项目上,而其余行则异步加载。

我认为问题可能是我每次都将 RowList.content 设置为新的更新 masterList(图 2)。

我更改了代码以追加一个新的行项目,它也导致焦点重置到第一行。

Fig 1.) m.ApiMixedListTask.observeField("responseObject", "onMixedListResponse")

Fig 2.)
function onMixedListResponse()
   masterList.push(newRowItems)

   m.top.gridContent = masterList
end function 

图 3.) 行列表:https://sdkdocs.roku.com/display/sdkdoc/RowList

  <RowList
                id="RowList"
                focusBitmapUri="pkg:/images/focus_grid.9.png"
                translation="[-60, 372]"
                itemSize="[1327, 218]"
                numRows="3"
                itemSpacing="[13, 0]"
                focusXOffset="[147]"
                rowFocusAnimationStyle="fixedFocusWrap"
                rowItemSize="[[262, 147]]"
                rowItemSpacing="[[16.5, 3]]"
                showRowLabel="true"
                showRowCounter="true"
                rowLabelOffset="[[147, 20]]"
                />

虽然这会导致糟糕的用户体验,但如果无法保持专注,我可能只需要在加载内容时阻止用户交互。

你说得对!您遇到问题是因为您每次都将 RowList.content 设置为新的更新 masterList。 如果您只是 copy/paste 将此代码添加到您的项目中,我不确定该代码是否有效,但它会给您示例说明您可以做什么:

 for each item in m.ApiMixedListTask.newRowItems
    content = createObject("RoSGNode", "ContentNode")
    for each key in m.ApiMixedListTask.newRowItems[item]
         content[key] = m.ApiMixedListTask.newRowItems[item][key]       
    end for

    m.RowList.content.getChild(0).appendChild(content)
 end for

您需要了解 Roku 的一个奇怪行为。如果您从函数中获取新的行内容,即使您按应有的方式创建,某些单元格也会无效。

例如,此代码将无法按预期工作:

function MapMatchList(data, countInARow = 4)
    rowListContent = createObject("RoSGNode","ContentNode")
    if data = invalid then return rowListContent
    list = data.List
    if list = invalid then return rowListContent

    row = createObject("RoSGNode","ContentNode")
    rowListContent.appendChild(row)
    counter = 1
    for i = 0 to list.count() - 1
        if counter > countInARow
            counter = 1
            row = createObject("RoSGNode","ContentNode")
            rowListContent.appendChild(row)
        end if
        match = MapMatch(list[i])
        if match <> invalid
            row.appendChild(match)
        end if
        counter = counter + 1
    end for
    return rowListContent
end Function

调用函数时,部分单元格变为无效

rows = MapMatchList(m.top.MoreData)
for i = 0 to rows.getChildCount() - 1
    m.rowlist.content.appendChild(rows.getChild(i))
end for

您需要更改一些代码:

function MapMatchList(data, countInARow = 4, rowListContent = invalid)
    if rowListContent = invalid then rowListContent = createObject("RoSGNode","ContentNode")

终于可以调用了:

MapMatchList(m.top.MoreData, 4, m.rowlist.content)