问题
I am facing some issue in screen navigation in Roku Brightscript. Please, anyone, help me how I can manage 5-6 screen in my Roku project. I want to navigate from 1 to 2 screen and also want to back from that screen. This is some major issue I have for the last 6 month. I am not able to do it. Some help from your side helps me to understand.
Currently, I have tried by following below procedure
1-if I want to go to 2 screens then I will do below part
m.top.AppendChild(m.secondscreen)
m.secondscreen.setFocus(true)
m.secondscreen.visible="true"
2- when I click back then in a second-screen back key I will return it false So that it comes to 1st screen back and here I will just do this
m.secondscreen.setFocus(false)
m.secondscreen.visible="false"
return true
Here it will come to the 1st screen. So like this, I will go to all pages. But I know this is not the exact process in Roku. So I have faced many difficulties by doing this.and I am not able to move from 5 screens to 1 screen by following the above procedure So anyone let me understand with some example if you have.it will be grateful to you
回答1:
I assume your m.secondscreen is a "roSGScreen" component and if so, you are correct that you are incorrect. A Roku scenegraph application should only have one "roSGScreen" created ever.
The concept of "screen" is confusing, because you can create many components that could be thought of as "screens" when they're actually just views. Your one and only scene should control the active views (subcomponents, not roSGScreens) and can attach / detach or show / hide the subcomponents as needed based on user action.
Technically speaking, I'm pretty certain that you want to manage 5 views, not 5 screens.
I suggest spending some time with the example application from the SDK docs tutorial to learn about this more.
回答2:
I have used the view stack component provided by Roku on some published channels.
I encourage you to use it, it will make easier the screen handling.
Please see Github Sample Docs.
Probably at first, the setup could be painful but definitely, it's more scalable as your applications keep growing.
To show a screen, you call it like this:
viewOne = CreateObject("roSGNode", "customScreen")
m.top.ComponentController.CallFunc("show", {
view: viewOne
})
To close your screen manually, you just need to change a property "close" to true.
viewOne.close = true
You can keep calling the show method and it will append all those views on the stack.
You also gain some functionality by letting the component controller handle your screen stack:
• currentView - Links to the view that is currently shown by ViewStack (This view represents the view that is shown by ViewStack.
• allowCloseChannelOnLastView - If true, the channel closes when the back button is pressed or if the previous view set the view's close field to true
• allowCloseLastViewOnBack - If true, the current view is closed, and the user can open another view through the new view's wasClosed callback
Notice that If another view without using ViewStack is shown, it wouldn't be reflected on the stack or could be accessed by the current view reference)
===============UPDATE==========
With the sample code of the original question (assuming you made the setup of the viewstack):
' To show the second screen
m.top.ComponentController.CallFunc("show", {
view: m.secondView
})
' to show another view on top.
m.thirdView = CreateObject("roSGNode", "thirdView")
m.top.ComponentController.CallFunc("show", {
view: m.thirdView
})
' to close third screen and go back to second screen
m.thirdView.close = true
回答3:
Add one thing in your code :
m.secondscreen.close = true
return true
Roku navigation first close screen is required. After the first screen is closed then the second screen will open. it's definitely work.
回答4:
I thought another way to navigate. simply add all widget or component add in a single group and apply Hide/show concept in ROKU. Its work for me to change the screen. ROKU doesn't provide any specific navigation.
来源:https://stackoverflow.com/questions/56576199/navigation-concept-in-roku