-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
70 changed files
with
8,730 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
components/SGDEX/ComponentController/ComponentController.brs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
' Copyright (c) 2018 Roku, Inc. All rights reserved. | ||
|
||
sub Init() | ||
m.top.ViewManager = createObject("roSGNode", "ViewManager") | ||
viewStackUI = m.top.findNode("ViewStack") | ||
m.top.ViewManager.viewStackUI = viewStackUI | ||
m.top.ViewManager.observeField("currentView","OnCurrentViewChange") | ||
m.top.observeField("allowCloseChannelOnLastView","OnAllowCloseChannel") | ||
m.top.allowCloseChannelOnLastView = true | ||
end sub | ||
|
||
function Show(config as Object) | ||
if GetInterface(config, "ifAssociativeArray") = invalid then | ||
? "Error: Component controller, received wrong config" | ||
|
||
return invalid | ||
end if | ||
View = config.View | ||
if View = invalid then View = config.view | ||
contentManager = config.contentManager | ||
|
||
data = {} | ||
|
||
if View <> invalid then | ||
subTypesSupported = { GridView: "" } | ||
subtype = View.subtype() | ||
parentType = View.parentSubtype(View.subtype()) | ||
createContentManager = false | ||
if subtype <> invalid and subTypesSupported[subtype] <> invalid then | ||
createContentManager = true | ||
else if parentType <> invalid and subTypesSupported[parentType] <> invalid then | ||
createContentManager = true | ||
end if | ||
|
||
if createContentManager then | ||
if contentManager = invalid then contentManager = CreateObject("roSgNode", "ContentManager") | ||
' attach this View to this content manager | ||
contentManager.Parent = m.top.getparent() | ||
|
||
contentManager.callFunc("setView", View) | ||
data.contentManager = contentManager | ||
end if | ||
end if | ||
|
||
m.top.ViewManager.callFunc("runProcedure", { | ||
fn: "addView" | ||
fp: [View, data] | ||
}) | ||
|
||
if contentManager <> invalid then | ||
contentManager.control = "start" | ||
end if | ||
'do other stuff for proper registering and unregistering events | ||
end function | ||
|
||
sub OnCurrentViewChange() | ||
m.top.currentView = m.top.ViewManager.currentView | ||
end sub | ||
|
||
sub OnAllowCloseChannel(event as Object) | ||
allowCloseChannel = event.getData() | ||
' need to pass this flag to View stack; it will set scene.exitChannel to true if no Views left | ||
m.top.ViewManager.allowCloseChannelWhenNoViews = allowCloseChannel | ||
end sub | ||
|
||
function onkeyEvent(key as String, press as Boolean) as Boolean | ||
handled = false | ||
if press AND key = "back" | ||
handled = closeView() | ||
end if | ||
|
||
return handled | ||
end function | ||
|
||
' handles closing View in View stack | ||
' if no View left, closes scene and exits channel | ||
function closeView() as Boolean | ||
' developer should receive back button when all Views are closed | ||
|
||
' save flags locally because developer can change it in wasClosed callback | ||
allowCloseLastViewOnBack = m.top.allowCloseLastViewOnBack | ||
allowCloseChannelOnLastView = m.top.allowCloseChannelOnLastView | ||
|
||
result = m.top.ViewManager.ViewCount > 1 | ||
|
||
' allowCloseLastViewOnBack is checked here because if it is set to true we need to close the View even it is last View in stack | ||
if result or allowCloseLastViewOnBack | ||
m.top.ViewManager.callFunc("runProcedure", { | ||
fn: "closeView" | ||
fp: ["", {}] | ||
}) | ||
|
||
' result is bool if count of Views is 2 or more, so View in stach is closed and back button successfully handled | ||
if result then return true | ||
|
||
' if last View is closed check if developer opens a new one in wasClosed callback, if so, back is handled | ||
if allowCloseLastViewOnBack and not allowCloseChannelOnLastView | ||
if m.top.ViewManager.ViewCount > 0 then return true | ||
end if | ||
|
||
if allowCloseLastViewOnBack then | ||
return false | ||
end if | ||
end if | ||
return not allowCloseChannelOnLastView | ||
end function |
47 changes: 47 additions & 0 deletions
47
components/SGDEX/ComponentController/ComponentController.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- Copyright (c) 2018 Roku, Inc. All rights reserved. --> | ||
|
||
<!-- @Public | ||
ComponentController (CC) is a node that responsible to make basic View interaction logic. | ||
From developer side, CC is used to show Views for different use cases. | ||
There are 2 flags to handle close behaviour: | ||
allowCloseChannelOnLastView:bool=true and allowCloseLastViewOnBack:bool=true | ||
@Sample: | ||
' in Scene context in channel | ||
m.top.ComponentController.callFunc("show", { | ||
view: View | ||
}) | ||
--> | ||
<component name="ComponentController" extends="Group" xsi:noNamespaceSchemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd"> | ||
<interface> | ||
<!-- @Public --> | ||
<!-- | ||
holds the reference to view that is currently shown. | ||
Can be used for checking in onkeyEvent | ||
--> | ||
<field id="currentView" type="node" /> | ||
|
||
<!-- @Public --> | ||
<!-- If developer set this flag channel closes when press back or set close=true on last view --> | ||
<field id="allowCloseChannelOnLastView" type="boolean" value="true" alwaysNotify="true" /> | ||
|
||
<!-- @Public --> | ||
<!-- If developer set this flag the last View will be closed and developer can open another in wasClosed callback --> | ||
<field id="allowCloseLastViewOnBack" type="boolean" value="true" alwaysNotify="true" /> | ||
|
||
<!-- @Public --> | ||
<!-- | ||
Function that has to be called when you want to add view to view stack | ||
--> | ||
<function name="show" /> | ||
|
||
<!-- View manager is a reference to node that handles all View stack functionality --> | ||
<field id="ViewManager" type="node" /> | ||
</interface> | ||
<script type="text/brightscript" uri="ComponentController.brs" /> | ||
|
||
<children> | ||
<ViewStack id="ViewStack" /> | ||
</children> | ||
</component> |
Oops, something went wrong.