Screen Flow
Overview
screenFlow is a document asset that describes a mutually exclusive switching state machine for a group of top-level screens within the same document. A
document can declare multiple flows, but a given screen can belong to only one flow. A flow handles only screen
mount / unmount; it runs no script callbacks, does not cross documents, and does not manage the app lifecycle.
Asset Field Table
Key |
Type |
Default |
Required |
Description |
|---|---|---|---|---|
|
string |
none |
yes |
fixed to |
|
string |
none |
yes |
flow id, unique within the document |
|
string[] |
none |
yes |
the list of top-level screen ids managed by this flow, without |
|
string |
none |
yes |
initial state id; must be in |
|
object[] |
|
no |
transition list; omitted or an empty array declares only a static initial screen |
Transitions[]
Key |
Type |
Default |
Required |
Description |
|---|---|---|---|---|
|
string[] |
|
no |
source state list; omitted or an empty array means any current state |
|
string |
none |
yes |
transition action name |
|
string |
none |
yes |
target state; must be in |
Rules:
a state id directly uses the top-level screen's
id; for example, screen/homecorresponds to statehome.every state in
screensmust reference an existing top-level screen in the current document.the same top-level screen cannot be included in the
screensof multiplescreenFlowassets.the state ids in
initial,to,from[]must belong to the current flow'sscreens.an omitted
fromorfrom: []means any current state.the same
(from_state, action)may be defined only once; multiple emptyfromwith the same action also raise an error.a transition with an exact
fromtakes precedence over a wildcard (emptyfrom) transition.triggering to the current state while the current screen is still mounted on the flow target is treated as a no-op success.
if
transitionsis omitted or empty, the flow is still valid; starting the flow mounts theinitialscreen, but triggering a transition fails.
Example
root.json:
{
"version": "0.1.0",
"assets": [
"screens/home.json",
"screens/settings.json",
"flows/main.json"
]
}
flows/main.json:
{
"type": "screenFlow",
"id": "main",
"screens": ["home", "settings"],
"initial": "home",
"transitions": [
{"from": [], "action": "open_home", "to": "home"},
{"from": ["home", "settings"], "action": "open_settings", "to": "settings"}
]
}
Runtime API
Runtime::start_screen_flow(document_id, flow_id, target): start the flow and mount theinitialscreen; if the flow is already running, it is idempotent and does not re-mount.Runtime::trigger_screen_flow(document_id, flow_id, action)Runtime::stop_screen_flow(document_id, flow_id)Runtime::get_screen_flow_state(document_id, flow_id)Runtime::has_screen_flow(document_id, flow_id): only checks whether the flow is defined in the document; it does not mean the flow is running.
screenFlow does not declare a layer. target is specified by the host that calls start_screen_flow(...); when unspecified, the default display's
GuiLayer::Default is used.