Trouble intercepting "up" key to change focus from MarkupGrid to categories
Hi everyone! I need some help handling key navigation between two components in my SceneGraph app.
I’m using a <MarkupGrid> with numColumns="1" to display a vertical list of channels:
<MarkupGrid
id="channelList"
translation="[20, 100]"
numColumns="1"
itemSize="[440, 100]"
itemComponentName="ChannelItem"
focusable="true"
/>
My intention is: when the user is focused on the first item (itemFocused = 0) and presses the up key, the focus should move from the channel list (channelList) to a RowList of categories (categoryRowList).
Here’s the logic I’m using inside onKeyEvent:
if (key = "up") and (m.channelList.hasFocus() = true)
if m.channelList.itemFocused = 0 then
print "⬆️ First item focused — moving focus to categories"
m.channelList.setFocus(false)
m.categoryRowList.setFocus(true)
return true
end if
end if
Expected behavior:
When pressing up on the first item, focus should go to categoryRowList.
Actual behavior:
Instead of transferring the focus, it loops to the last item in the channelList, as if I had pressed down on the last item.
I’ve also tried another approach using the observeField("itemFocused", "onItemFocusChanged") pattern:
function onItemFocusChanged()
m.currentIndex = m.channelList.itemFocused
print "🔍 Focused item: " + m.currentIndex.toStr()
currentIndex = m.channelList.itemFocused
print "🎯 Current focus: "; currentIndex.toStr(); " | Last: "; m.lastFocusedIndex.toStr()
if currentIndex = 63 and m.lastFocusedIndex = 0
print "🔼 Second UP on index 0 → switching focus"
m.categoryRowList.setFocus(true)
m.channelList.setFocus(false)
end if
m.lastFocusedIndex = currentIndex
end function
And even created a helper:
function transferFocusToCategories()
print "🔼 Transferring focus to categories (via ChannelItem)"
m.allowFocusTransfer = false
m.channelList.setFocus(false)
m.categoryRowList.setFocus(true)
end function
Unfortunately, none of these approaches work reliably. It seems like MarkupGrid (and even MarkupList, which I used before) internally handles the up/down keys, making it difficult to override the default behavior.
Question:
How can I correctly intercept the up key on the first item in a MarkupGrid to move focus to another component?
Thanks in advance!