ShellHost

fun ShellHost(graph: ShellGraph, modifier: Modifier = Modifier, start: NavKey? = null, resolveStart: suspend () -> NavKey?? = null, preferences: ShellPreferencesRepository? = null, defaults: ShellSettings = ShellSettings(), onReady: () -> Unit = {}, onDestinationChanged: (NavKey) -> Unit = {}, layoutPolicy: ShellLayoutPolicy = graph.defaults.layoutPolicy, snackbarHostState: SnackbarHostState? = null)(source)

The whole app below the activity: every tab, page, bar, rail, drawer and transition described by graph.

Call it once, from the activity's setContent, inside the app's theme (AppTheme), with edge-to-edge enabled. The activity stays the only one the app has; pages replace the activities it would otherwise open, including their animation and the system back gesture.

The intents the activity receives, the one it was launched with and any that arrive while it runs, open the destinations the graph's deepLinks map them to. An activity that should receive new intents instead of being recreated declares launchMode="singleTop".

Work that needs the activity itself, such as a consent form, an in-app review, an update flow, a purchase, or a permission request, is done from the page that needs it, with LocalActivity.current and rememberLauncherForActivityResult: every page is composed inside the one activity.

Parameters

start

Where a fresh launch opens, instead of the graph's start: a tab, or a page shown as a start screen before the shell.

resolveStart

Decides start at launch from stored state, such as a welcome screen until the person has seen it once. Nothing is drawn until it returns; null keeps start. Keep the splash screen up until onReady.

preferences

Where the shell keeps its settings. By default a DataStore of its own; an app with a settings store supplies its own implementation, which then owns its defaults.

defaults

The app's own shell defaults, usually appToolkitDefaults { }.shell: what a setting nobody chose in the developer options reads as, and what a reset returns to. Only used for the shell's own store, when preferences is null.

onReady

Called once the first frame of the app is composed, the settings and the start decided: the moment to let the splash screen go.

onDestinationChanged

Called with the destination on top whenever it changes, first with the one the app opens on: for analytics and the like.

layoutPolicy

The window widths at which the navigation changes form, and how wide content may grow on large windows. The graph's NavigationDefaults.layoutPolicy unless given.

snackbarHostState

Where the tabs' scaffold shows its snackbars. Pass one to show messages that belong to the whole app, such as those of the activity's own view model, above the bottom bar with the rest: MessageHost(viewModel, snackbarHostState = it, drawHost = false). While no tab is on screen, on a start screen or under a page, the shell shows them at the bottom of the window instead. The shell keeps a host of its own by default.