ScreenHost

fun ScreenHost(screen: TrackedScreen, status: TrackedStatus? = null, viewModel: ScreenViewModel<*, *>? = null, onMessageAction: (UiMessage) -> Unit = {}, fabs: List<ToolkitFab>? = null, content: @Composable () -> Unit)(source)

The boundary of one screen: reports each visit to it, reports its status, and shows its ViewModel's messages. Every screen, tab, page, sheet or pane with a screen name of its own is wrapped in one.

ScreenHost(screen = AppScreens.NEWS, status = state.articles, viewModel = viewModel) {
NewsScreenContent(state = state, onEvent = viewModel::onEvent)
}

It adds no layout and draws nothing of its own: no scaffold, no app bar, no padding, and it does not render status; its fabs are drawn by the scaffold around it. content renders the state, each Loadable section through ScreenStateHandler. Navigation and the ViewModel stay with the caller.

A screen that draws its own PageScaffold puts ScreenHost inside it, as the page's content. Wrapped around the page instead, its fabs and messages go to the scaffold around the page, where a page has none, so they never show.

Visits. A visit is reported as a GA4 screen view when the screen becomes visible and active: when its LocalLifecycleOwner reaches RESUMED. In the shell that is once its transition settles and nothing covers it, so a screen that is only animating in or out, kept for a back gesture, or under an overlay is not reported. The visit lasts until the screen leaves composition (another tab, a page over it, popped) or the app goes to the background, and the next RESUMED starts a new one. A configuration change keeps the visit, so rotating reports nothing; after process death, the return is a new visit. Both panes of a list-detail layout are separate destinations, so each reports its own visits.

Status. status, when given, is reported as a screen_state event at the start of each visit and whenever its TrackedStatus.trackingLabel changes, never twice in a row for the same label. A screen with nothing that loads passes none, and a screen with several loading sections passes the one that says how the screen is doing, or a status of its own.

Parameters

screen

the stable name and class reported for this screen.

status

what the screen shows now, such as its main Loadable, or null.

viewModel

whose queued messages are shown through the surrounding Toolkit scaffold. A screen that shows its messages in a snackbar host of its own calls MessageHost itself.

onMessageAction

called when a message's action is pressed.

fabs

the screen's floating action buttons for its state now, drawn by the surrounding Toolkit scaffold like ScaffoldFabs; null declares none, leaving the destination's own. Declared here, once for the screen, they follow its state without the cases of a StateContent both declaring buttons while one fades into the other.

Entrances. The screen's animateVisibility elements cascade in once it settles, in the order they are shown: once it is resumed, or earlier, while it is started, when its LocalEntranceCue is reached, which the shell does well into the transition bringing it in, so its content arrives as it lands. A loading case of ScreenStateHandler stays until then. They play each time the screen is opened, not on going back to it, unless LocalEntranceReplay says every visit (EntranceReplay.EveryVisit) or only the first copy in a run (EntranceReplay.FirstVisit); coming back from the background, rotating or scrolling within the visit never replays them.