:library:core:ui
Purpose
Provides the reusable Compose presentation foundation: screen/ViewModel contracts, the shell's page frame, state handling, analytics hooks, and shared components.
Owns
utils.AppLauncher, which usesInstalledAppsRepositoryto look up launcher intents, then launches on the main dispatcher and owns the failure Toast. Package lookup remains in core common.The screen contracts, in
screen:ScreenViewModel,LoggedScreenViewModel,Loadable,TrackedStatus,UiMessage,ScreenHost,ScreenStateHandler,ScreenStates,StateContentandMessageHost.MessageToastHostpresents the same queue above modal sheets when a snackbar would be obscured. Toasts have no actions; errors default to a long duration. See Screen state and Screen visits.The shell's page frame, in
views/shell:PageScaffold,ShellTopAppBarandrememberTopBarScrollBehavior, the app bar's search field,LocalContentPaddingandcontentPadding,ContentWidthBox, the pane placeholders, and the page's snackbar host (LocalPageSnackbarHostState,rememberPageSnackbarHostState). See Page frame.The settings models, in
models/settings:SettingsConfig,SettingsCategoryandSettingsPreference, whose rows carry adestinationkey and an optional appaction. They live here, not in the settings feature, so the features that describe settings (permissions, the app's provider) need no dependency on that feature.Cross-feature contracts, such as
IssueReporterSheetinviews/sheets: one feature binds it in Koin and another resolves it, so neither depends on the other.The floating action button column, in
views/buttons/fab:ToolkitFabColumnandToolkitFloatingActionButtondraw theToolkitFabs of:library:core:designsystem, andScaffoldFabswithFabHostandLocalFabHostlet a screen put its own buttons in the scaffold around it. See Floating action buttons.The theme choices, in
views/theme:ThemeModePicker(light, dark and follow system cards) andThemePalettePicker(wallpaper color variants and static palettes on two tabs, or the static palettes alone without wallpaper colors), withThemePalettePagerand the mode previews under them. The theme settings page and the onboarding theme page both use them, so the two cannot drift apart; neither feature may depend on the other.ChoicePreferenceItem, the settings row that shows the chosen option and opens a radio-list dialog to change it. Itsiconis optional; the Toolkit's settings rows go without one, while their dialogs keep an icon on top throughdialogIcon.Reusable buttons, fields, preferences, layouts, grids, dialogs, snackbars, ads slots, effects, and adaptive-window helpers.
MainTopAppBar, the host main-screen app bar, its optional centre-aligned title, and its host-supplied Support overflow action.SearchTopAppBar, the same bar with a search field in place of its title, andSearchFilterAction, the filter toggle that sits inside that field.GeneralTextFieldand the Markdown authoring behind it: the length-preserving highlighter, the formatting bar, and the source edits it applies.Render models such as
AppVersionInfoandAdsConfig.The shared theme-mode preview composables used by both the onboarding and settings theme UI.
The single adaptive
GeneralButtonand FAB icon slots acceptToolkitIcon, including bundled Lottie icons. FAB ImageVector/custom-content overloads remain compatible; rendering and playback are delegated tocore:designsystem, while buttons retain feedback and analytics ownership.
Does not own
Business rules, repositories, DTOs, persistence, or HTTP behavior.
Color palette and root theme construction, owned by
:library:core:designsystem.Feature screens.
Depends on
:library:core:commonfor common models, Firebase contracts, and platform helpers.:library:core:datastorefor remaining persistence-backed UI adapters; reusable modifiers and ad slots consume design-system-provided values rather than DataStore.:library:core:designsystemfor theme primitives and theToolkitIconslot the buttons render.:library:navigationfor the navigator, the page key and pane role, and the layout the page frame reads.
Used by
:sampleand:library:apptoolkit.Every
:library:featuremodule.:library:integration:adsfor its settings screen and ad presentation.
Flow chart
flowchart TD
User[User interaction] --> Screen[Feature composable]
Screen --> Event[Feature event]
Event --> VM[ScreenViewModel]
VM -->|setState| State[StateFlow of the feature's state]
VM -->|showMessage| Messages[StateFlow of queued UiMessages]
State --> Handler[ScreenStateHandler per Loadable field]
Handler --> Loading[Loading / empty / failed / ready]
Loading --> Screen
Messages --> Host[MessageHost: snackbars in order]
Theme[AppTheme CompositionLocals] --> Components[Reusable components and ad slots]
Components --> Screen
Frame[PageScaffold page frame] --> ScreenArchitectural decisions
Ad slots keep no-fill and network failures in Logcat and telemetry breadcrumbs without recording nonfatal exceptions. Other SDK failures and requests that cannot start remain nonfatal reports.
ScreenViewModelowns unidirectional event-to-state processing; feature composables render data and forward user intent rather than reaching repositories.A screen's state is the feature's own type. The Toolkit puts the status on each piece of content that loads (
Loadable), not on the whole screen, so a screen that loads several things gives each its own status and a screen that starts with its content has none. A screen whose cases differ declares a sealed type of its own.Messages are queued state, not one-off events, so a configuration change cannot lose one, and every screen shows them the same way through
MessageHost.ScreenStateHandlerdraws every case but the content with the app'sScreenStates, so a failure always shows something. A screen passes only what differs:icon,retryWhenEmpty,showAd, or a case of its own for that one section. An app draws its own cases, or its own transition, once withLocalScreenStates; without one, cases cross-fade on the app's motion scheme.StateContentswitches on any other state, such as a flow's phases, the same way.Global UI preferences arrive through the design-system root. Reusable components must not start their own persistence collectors unless a documented adapter still requires it.
Public contracts
GeneralButtonis the action-button entry point for all five styles and labelled/icon-only content. See the 3.0 button contract and migration.GeneralTextFieldis the text-input entry point; see GeneralTextField.AppShowcase(views.showcase) is a stateless "more apps" carousel: a titled row of filled app cards with a "View all" action, snapping horizontally. It takesShowcaseAppitems, anAppShowcaseState(Loading,Ready,Empty,Failed) andAppShowcaseLabelsbuilt withappShowcaseLabels(...); the host fetches the apps and handlesonAppClick,onAppAction(open wheninstalled, store otherwise),onViewAllandonRetry. Its GeneralButton actions use Tonal style without colour overrides. OptionalonCardsVisibilityChangedreports whether at least half the cards row is visible; hosts own lifecycle, dwell time and telemetry. Cards aremin(86%, 360dp)wide on compact widths and fill whole columns of at least 260dp above 600dp.MainTopAppBarandSearchTopAppBarare the two host app bars; see Top app bars. Pages of the shell getShellTopAppBarfrom the page frame instead.PageScaffold,ShellTopAppBar,LocalContentPaddingandcontentPadding,ContentWidthBox,PanePlaceholder,ListPlaceholder,LocalPageSnackbarHostStateandrememberPageSnackbarHostState; see Page frame.SettingsConfig,SettingsCategoryandSettingsPreference. A row opens itsdestinationkey unless itsactionreturnstrue. Itsiconis aToolkitIcon, so a row can show an animated, Lottie or drawable icon as the navigation does; theImageVectorconstructor is deprecated.PreferenceItemandSettingsPreferenceItemtake either.SettingsSearchEntryandSettingsSearchProvider, the settings search's contract: each settings page's module binds a provider in Koin listing its rows (title, the page they live on, the key they open), and the settings list collects them all withgetAll, depending on none of the pages. A provider's one input is aSettingsSearchContext, the app'sShellGraphandShellCapabilities, to leave out rows the app does not show under the same rules as the page.settingsSearchProvider(section, destination) { preference(...) }builds one throughSettingsSearchScope, which readscapabilitiesandgraph, with the page's section and destination given once, andunregisteredDestinations(context)lets a test catch rows whose page the graph does not register. See Settings search.IssueReporterSheet, afun interfacewhoseShow(onDismissRequest)draws the issue reporter. Resolve it withgetKoin().getOrNull(): it is absent when the issue reporter is not installed.AnimatedIconButtonDirectionslides, fades and scales in and out from its edge, and crossfades its glyph wheniconchanges, so one button can turn from a menu button into a back arrow.GroupedGridis the grouped category/action block:GroupedGridItemcells,GroupedGridDefaultsfor radii, spacing, colors and the badge shape, andGroupedGridMeasurementsfor the size class. The corner and ad-placement rules aregroupedGridRows, which is unit tested; the composable renders the plan it returns. Its ad row goes throughNativeAdSlotlike every other ad surface, so a host that passes noadUnitIdpulls in no ad behaviour at all. The size class also chooses the ad'sNativeAdPresentation.GridRowmetrics, so the sponsored row matches the cells rather than the other ad surfaces.NativeAdCacheandrememberNativeAdCachekeep native ads alive while their slots scroll in and out of a lazy layout.NativeAdSlot,rememberNativeAd, andrememberNativeAdStatetake acacheand acacheKey; without both they keep the uncached behaviour of destroying the ad on disposal. See Ads inside a lazy list or grid.Modifier.animateVisibilitybrings an element in as its screen is shown, in a cascade. Inside aScreenHostthe screen owns the cascade: elements wait until the screen settles, then arrive one after another from the top of what is shown, eachstaggerDelay(50 ms) after the one before. An item scrolled in later starts at once. The entrance starts when the element is first placed, so items a lazy list composes ahead of time still enter on screen. The motion isMaterialTheme.motionScheme's springs in the style ofLocalEntranceStyle(Slide,Scale,FadeorNone), which the shell provides fromappToolkitDefaults { shell { entranceStyle = ... } }or the developer options.animateVisibility(visible)animates an element in and out as it comes and goes. Both run in aModifier.Node, without recomposing per frame; the cascade isVisibilityCascade, unit tested.Toolkit components enter on their own. Preference rows, switch cards, grouped action lists, info messages, filter chips,
NoDataScreenand native ad slots join their screen's cascade without a modifier. A component skips its own entrance outside aScreenHost, inside a dialog, sheet or popup (another window), inside an item that already enters, or when its modifier already holds an entrance, so nothing enters twice. Do not wrap them inanimateVisibility.animatedItems,animatedItemsIndexedandanimatedItemonLazyListScopeandLazyGridScopeareitemswith the entrance andanimateItem()built in, ordered by their index. Use them for an app's own rows and cards; a Toolkit component inside one does not enter again. Items move onMaterialTheme.motionSchemetoo, and an item's children stack as a plain item's do. The one exception is an item holding only filter chips or a native ad slot: keep it a plainitem, so the chips cascade one by one and the ad enters when it loads.Rows a scroll or fling brings into view still enter, but at once and on the fast springs, outside the screen's cascade.
ScreenHostwatches its content's nested scrolling to tell them from the rows the screen opens with, so a fast fling no longer leaves the list half-faded.EntranceReplayandLocalEntranceReplaydecide when a screen's entrance plays:OnOpen, the default, each time a screen is opened or its tab is picked from the navigation, but not on going back to it;EveryVisiton every return as well;FirstVisitonly for the first copy of each screen while the app runs. A host that opens a screen again while keeping it in its back stack, as the shell does for a tab picked again, raisesLocalScreenOpeningaround it. Returning from the background, rotating or scrolling back within a visit never replays it. An app picks its own default withappToolkitDefaults { shell { entranceReplay = ... } }, and the developer options override it.HorizontalWavyDivider,VerticalWavyDivider, andWavyDividerDefaultsdraw the design system'sil_wavy_lineas a divider. The wave is drawn rather than tiled from the drawable, so it scales with the divider's band and fits a whole number of half-waves into any length; the fitting iswavyLineGeometry, which is unit tested.AospPageIndicatorinviews/carouseldraws an Android 10-inspired page indicator whose active dot stretches into a rounded capsule across page transitions. ThePagerStateoverload reads continuous scroll offset during drawing so swipe and programmatic page transitions never queue stale targets; the(pageCount, selectedIndex)overload animates single-step changes and snaps across multi-page jumps. Long carousels use a continuous sliding window (pageIndicatorWindowStart), which is unit tested alongsidepageIndicatorPosition.
New ViewModels extend
core.ui.screen.ScreenViewModel, orcore.ui.screen.LoggedScreenViewModelwhen Firebase breadcrumbs and error reporting are required.ViewModels receive events through
onEvent, change their state only throughsetState, and queue messages withshowMessage. Operations run throughlaunchReport(a suspend call),collectReport(a flow whose values go into state, for the ViewModel's lifetime),observeReport(an expensive stream, collected only while the screen collectsstate, asWhileSubscribed(5_000)does) orcatchReport(a flow that keeps going), which report failures and pass cancellation through. ViewModels take repositories, use cases andTelemetryRepository, never aContext. Product analytics are reported here, in the UI layer; repositories report only diagnostics.Composables report through
LocalTelemetry(core.ui.views.analytics), never aTelemetryRepositoryparameter.ScreenHostand every component with aga4Eventread it themselves; a screen that logs its own interactions reads it once asval telemetry = LocalTelemetry.current.ShellHostprovides it. A composition started outsideShellHost, such as a sheet in its own window, wraps itself inProvideTelemetry { }. Where nothing provides it, as in a preview, it isNoOpTelemetryRepositoryand events are dropped.Initialization is represented by an event sent from
init; long-running work is owned and cancelled by the ViewModel.State/render models, reusable composables, lifecycle effects, and analytics APIs are intentional cross-module contracts.
Every button takes its icon as a single
ToolkitIcon, so a button can carry a Compose icon, a drawable resource, or an animated vector that plays on each click. See the design system README.
GeneralTextField
One field component, views/fields/GeneralTextField.kt, with the same shape as GeneralButton: the defaults render exactly the Material filled field, and every variation is a parameter rather than another component. Two overloads, String and TextFieldValue; take the second when the caret is part of the state a screen owns.
GeneralTextFieldStyle picks the treatment:
| Style | Renders |
|---|---|
Filled (default) | The Material TextField |
Outlined | The Material OutlinedTextField |
Grouped | A filled field with no indicator line, cut to position in a grouped block |
Search | The Material search input, pill-shaped, leading with a search icon |
SearchOutlined | The outlined field, fully rounded, leading with a search icon |
Grouped is the form treatment: a column of fields two dp apart reads as one card, so the indicator line is dropped (it would cut the block into strips) and position plus groupedOuterRadius cut the corners. Such a field usually carries no label either, because a floating label reserves height whether or not it is showing; placeholder and a described leadingIcon name it instead.
Search is the odd one out, and deliberately so: it is SearchBarDefaults.InputField rather than a rounded text field, for a box that filters the content behind it as it is typed, such as a top app bar that swaps its title for a search field, say. It is used on its own rather than inside a SearchBar because the collapsed bar intercepts the soft keyboard and only accepts typing once it expands into a surface that reserves 240dp for results this kind of field does not have. The parameters that describe a form field (label, supportingText, errorText, minLines, markdown, position) do not apply to it, and the TextFieldValue overload rejects it outright, because the Material input owns its text state and has no caret to hand over. onSearch reports the keyboard's search action; focus is dropped first either way.
SearchOutlined is the search box drawn as an ordinary outlined field instead, fully rounded. Take it where a filled pill would disappear into the surface behind it, or where the rest of the screen is outlined; every parameter applies to it, and the TextFieldValue overload accepts it.
trailingContent replaces the whole trailing slot with a row, for the field that ends in more than one action, such as a search box carrying a filter and a clear button. errorText marks the error state and replaces supportingText in one parameter, so a message and the state it describes cannot drift apart. trailingIcon with onTrailingIconClick becomes a GeneralButton, so a clear or reveal action keeps the toolkit's feedback. ga4Event is logged when the field gains focus, since a field is not a button, and a per-keystroke event is not an interaction.
GeneralTextFieldMarkdown turns the field into a Markdown editor:
Highlightstyles the syntax as it is typed. The transformation is length-preserving, so offsets stay identity-mapped and the markers stay visible, selectable and editable. A Markdown renderer cannot do this job, because the field is an editor.Editoradds the formatting bar underneath (bold, italic, inline code, code fences, bulleted and numbered lists, quotes and links) which edits the Markdown source and places the caret between the markers it inserts. The bar is cut and filled to match the style above it, so field and bar read as one block; a grouped field hands the lower half of itspositionto the bar.
Either mode replaces visualTransformation, since the field draws the source itself. onMarkdownFormat reports which action was used, as a MarkdownFormatAction whose analyticsName is a stable identity for hosts that log them. MarkdownFormatting, the source edits behind the bar, is plain string transformation and unit tested without a Compose runtime.
Top app bars
Two bars, one shape. Both take the same navigation icon, the same host-supplied Support overflow, and the same destination actions slot; they differ only in what occupies the title.
MainTopAppBar holds a title that crossfades when the destination changes. centerTitle picks the Material bar underneath it. Off, the default, keeps the small top app bar the toolkit has always rendered; on, it becomes a centre-aligned one. It is a parameter rather than a second composable because nothing else about the bar changes with it.
SearchTopAppBar is that bar for a screen that filters what is behind it. While showSearch is true the title crossfades into a GeneralTextFieldStyle.Search field; while it is false the bar is indistinguishable from MainTopAppBar. The bar owns only that swap. The query, and whether search is showing at all, stay with the caller, so one piece of state drives both the bar and the filtering underneath it, so the bar never holds a query the screen cannot see.
Title and field share one slot pinned to the field's height and crossfade in place. Letting the slot follow whichever was showing made the title snap up and settle back as the field left, and growing the field from its centre slid the placeholder across the title; both read as a jump. The title is centred in that slot rather than handed its full height, which would draw it above the navigation icon, and it animates between values exactly as MainTopAppBar's does. The state the bar is first composed in appears without an entrance, so a screen that opens into search shows no title flash, and the title still appears the first time search is turned off.
Filters are optional and live inside the field, in the filters slot to the left of the clear button, which is where a person looks for the controls that shape the results they are reading. SearchFilterAction is the ready-made toggle for one: tonal while the filter is applied, text while it is not, so an applied sort reads as applied without a second surface announcing it. A filter that only applies to some of a screen's content passes visible, and the toggle animates itself in and out. Actions belonging to the bar rather than to the query stay in actions.
Both bars default their strings, so a host that has nothing to say about them passes nothing: title falls back to the app name, and the search placeholder and clear-button description to core:ui's own search and clear_search.
Page frame
views/shell holds what a page of the shell is drawn in. ShellHost in :library:shell wraps every page registered with a title in PageScaffold: a ShellTopAppBar with a back button that closes the page through the navigator, and a body under it. Pages that need something under their app bar, such as tabs, call PageScaffold themselves.
The style is the page's, the size the window's. A page declares its
TopBarStyle; a large bar becomes a small one on a window too short for it, and inside a list-detail pane the frame draws no bar at all, because the scene draws one across both panes.LocalTopBarStyleOverridelets the developer options try one style across the app.What sits under the bar changes colour with it. A tab row flush under the app bar passes
containerColor = topBarContainerColor(), so the bar and the tabs tint together as content scrolls under them, blending as a large bar collapses.PageScaffoldand the shell's tabs provide the bar's tint throughLocalTopBarTint; elsewhere, and beside a tinted rail, where the bar is see-through, it is the bar's resting colour.A bar can stay static.
PageScaffold(topBarScrollMode = TopBarScrollMode.Static)keeps the bar expanded and visible, without scroll tint or frame tint, whatever the hide-on-scroll setting. The default followsLocalTopBarScrollMode, which the destination sets; the content, the buttons and an article's reading progress still follow the scroll.Extended buttons fold on scroll, including the scroll a collapsing or hiding bar takes before the content moves, so they fold on a page too short to scroll far. A scaffold of its own attaches its bar's connection through
FabScrollBehavior.observing.The bar can hide on scroll. With
LocalHideTopBarOnScroll, which the shell sets from its settings, the bar slides away as content scrolls down and returns as soon as it scrolls up, whatever its style; a large bar collapses first.HideOnScrollTopBarlays the bar out less the partTopBarHideStatehas slid away, which reaches all of it, from under the status bar too, and a scaffold of your own attaches the state'snestedScrollConnectionafter the bar's own scroll behaviour.A screen can turn the bar into an article bar.
PageScaffoldholds anArticleTopBarHostthat the screen inside declares into withScaffoldArticleTopBarfrom:library:navigation; inside a list-detail pane it passes the scene's host through instead.ShellTopAppBartakes the host asarticle: while one is declared it draws a large style small, shows the article's compact title instead of the page's, and draws the reading progress over its bottom edge.TopBarStyle.forArticle(host)gives the style it draws, for a scaffold of your own. See Article app bar.Beside a rail or permanent drawer, the page it opened is a tab. When
isTopLevelPagesays the navigation opened this page, the frame draws a small bar without a back button and, over a tinted frame, the tab's content card. Back still closes it.The content colour is set. The frame provides
onBackgroundasLocalContentColor, so text in a page follows the theme even where no MaterialSurfacesets it.Content is edge to edge at the bottom. The body reaches behind the system navigation bar and, on tabs, the bottom bar, banner and player. What covers it arrives as
LocalContentPadding, so a list addscontentPadding()to its own padding and scrolls under the bars instead of stopping above them.The back button is
AnimatedIconButtonDirection, the same button the shell's app bar uses, with its slide, press bounce, click sound and haptic.The scaffolds show the snackbars.
PageScaffoldand the shell's tab scaffold each draw one host above their bars, buttons and the system bars, and provide it to the screen inside asLocalScaffoldSnackbars(aScaffoldSnackbars) andLocalPageSnackbarHostState. A screen shows a message withrememberScaffoldSnackbars():post(...)from a click handler, orshow(...)from a coroutine, with theToolkitSnackbarStyle.NormalorErrorlook, an action (actionLabel,onAction), a close button, an icon, its ownToolkitSnackbarColors, or its own drawing throughcontent. A view model's messages go throughMessageHost(viewModel), which uses the scaffold's host by default and callsonActionwhen a message's action is performed. It draws a host of its own only when given a different one, so a screen never shows two (drawHostoverrides that). An app's own messages, such as those of its activity's view model, go to the host it handsShellHost(snackbarHostState), shown by the tabs' scaffold.DefaultSnackbarHostdraws every snackbar withToolkitSnackbar, the default look, unless its visuals carry their owncontent.ContentWidthBoxcentres content no wider than the layout policy's maximum width, andPanePlaceholderandListPlaceholderfill a detail pane nothing is open in.
Floating action buttons
A screen's floating action buttons are described, and the Toolkit's scaffolds draw them: a column at the bottom end, the last button in the corner, each with the Toolkit's click sound, haptic, press bounce and animated icon, scaling in and out on its own.
A screen hands its buttons to the scaffold around it, so a screen that draws its own PageScaffold declares them inside it: PageScaffold { ScreenHost(fabs = ...) { ... } }. A ScreenHost wrapped around the page sends its buttons and messages past it, and they never show.
ScaffoldFabs(
listOf(
ToolkitFab(ToolkitIcon.Vector(Icons.Outlined.Search), onClick = ::search, contentDescription = searchLabel, size = FabSize.Small, color = FabColor.Secondary),
ToolkitFab(ToolkitIcon.Vector(Icons.Outlined.Add), onClick = ::add, label = newLabel),
),
)ToolkitFabtakes an icon, an action and, for an extended button, a label; aFabSize(small, regular, medium, large, for plain and extended buttons alike), aFabColor(the primary, secondary or tertiary container, or a raised surface), andexpandedandvisible.From the graph:
fabs = { listOf(...) }on a tab, child or page, read in composition.From the screen:
ScaffoldFabs(listOf(...)), for buttons that depend on the screen's own state. They leave with the screen.PageScaffoldand the shell's tab scaffold each keep aFabHostfor the screen inside; outside a Toolkit scaffoldScaffoldFabsdraws nothing.Directly:
PageScaffold(fabs = ...), orToolkitFabColumnin a scaffold of your own.They fold while the content scrolls. The Toolkit's scaffolds attach a
FabScrollBehaviorto their content: extended buttons fold to their icon while it scrolls down and unfold as soon as it scrolls back, and a new tab or page starts unfolded. A button's ownexpandedstill applies. In a scaffold of your own, attachrememberFabScrollBehavior().nestedScrollConnectionand pass itsexpandedtoToolkitFabColumn.
Screen state
The screen package is how a screen holds and shows its state. :library:feature:about is the first feature on it and the reference for the rest.
data class AboutUiState(val items: Loadable<ImmutableList<AboutItem>> = Loadable.Loading)
class AboutViewModel(/* ... */) : LoggedScreenViewModel<AboutUiState, AboutEvent>(
initialState = AboutUiState(), telemetryRepository = telemetryRepository,
screenName = "About", viewModelName = "AboutViewModel",
) {
override fun handleEvent(event: AboutEvent) { /* ... */ }
private fun load() = launchReport(
action = "loadAboutInfo",
onError = { setState { copy(items = Loadable.Failed(failedText)) } },
) {
setState { copy(items = Loadable.Ready(repository.getAboutInfo().toAboutItems())) }
}
}
// AboutScreen, stateful: ViewModel, the screen's boundary, navigation.
val state by viewModel.state.collectAsStateWithLifecycle()
ScreenHost(screen = ABOUT_SCREEN, status = state.items, viewModel = viewModel) {
AboutScreenContent(state, onEvent = viewModel::onEvent, onOpenLicenses = { navigator.navigate(LicensesRoute) })
}
// AboutScreenContent, stateless and previewable: renders the state, reports through callbacks.
ScreenStateHandler(state.items, contentPadding = padding, onRetry = { onEvent(AboutEvent.Load) }) { ready ->
AboutList(ready.value)
}The full setup, with the file tree, templates and the migration steps, is the android-ui-layer skill.
The state is the feature's own type. Content that is there from the start needs no status. Content that loads gets a
Loadablefield, and nothing makes it start atLoading: a screen that shows nothing until its content arrives starts atEmptyand goes straight toReady.Loadable.Readycan berefreshingorstale, for a newer copy loading behind the shown one or a saved copy shown offline, without a case of its own.Other statuses are a sealed type the feature declares. Implementing
TrackedStatushas them reported byScreenHostlikeLoadable'sloading,success,no_dataanderror.Messages go through
showMessage(UiMessage(...))andMessageHost, which shows them one at a time and removes each once it has left. A screen needs no dismiss event.LoggedScreenViewModellogsvm_initandvm_eventitself;launchReport,collectReportandobserveReporttake the same arguments and logvm_op_startand, on failure,vm_op_errorand a Crashlytics report before callingonError.observeReportlogs a start each time the screen comes back after five seconds away, and its tests subscribe first withcollectInBackground(viewModel.state)from:library:core:testing.catchReportreports a failure of a flow that keeps going, and hands it to a block that can emit a fallback. The messages, keys and events are fixed, because dashboards and Crashlytics filters read them.Failures are mapped here. The data layer throws
NetworkException,StorageExceptionor a feature's own exception. InonError,toFailed(fallback)builds theLoadable.FailedandtoErrorMessage(fallback)the errorUiMessage. Both usetoUiText, which gives every screen the same text for the failures a user can act on (offline, timeout, busy server, full storage) and the screen's ownfallbackfor the rest, bugs included. A screen with failures of its own maps them first and passes the rest on.Floating action buttons follow the state through
ScreenHost(fabs = ...), declared once for the screen rather than inside the cases of aStateContent.There is no action stream. One-off effects such as navigation are added with the first screen that needs them; messages, the common case, are state.
Screen visits
ScreenHost(screen, status, viewModel, onMessageAction) { content } is every screen's boundary, the only screen tracking a screen calls. It reports visits, reports the status, and hosts the ViewModel's messages. It adds no layout, renders no Loadable (each section goes through ScreenStateHandler inside content), owns no navigation and injects nothing. A static screen passes no status and no viewModel; a screen with several loading sections passes the one that says how the screen is doing, or a TrackedStatus of its own. TrackedScreen, the stable name and class, is in :library:core:common's telemetry.models, so an analytics contract module needs no UI dependency.
A visit starts when the screen is visible and active, when its
LocalLifecycleOwnerreachesRESUMED. Navigation 3 caps each scene's lifecycle atSTARTEDuntil its transition settles and while an overlay covers it, and the shell's tabs inherit the pages' cap, so a screen that only animates, is kept for a back gesture or sits under an overlay is not reported. A cancelled back gesture or a dismissed overlay returns to the same visit.A visit ends when the screen leaves composition or the app is stopped. Switching tabs, a page over the shell, popping and backgrounding all end it; the next
RESUMEDis a new visit. Both panes of a list-detail scene are separate destinations and report separately.A configuration change keeps the visit; process death does not. The visit lives in a small holder in the destination's
ViewModelStoreOwner, which survives rotation and not process death. Outside a destination it falls back to the activity's store, and in a preview to the composition.The visit also times the screen's entrance. Elements with
animateVisibility, Toolkit components andanimatedItemswait until the screen settles, then cascade in. It settles when it isRESUMED, or before that, while it isSTARTED, once itsLocalEntranceCueis reached: the shell reaches it 60% into the transition bringing a page or tab in, so content arrives as the screen lands instead of after a blank half-second. After its first resume only resuming settles it, so nothing starts entering under an overlay.The loading content hands over to the entrance. A
ScreenStateHandlershowing its loading case keeps it while the screen has not settled, so a result that arrives during the transition waits behind it and the loading fades as the result's elements enter. A slow result replaces it as soon as it arrives. Put a screen's loading inonLoadingor the app'sScreenStates, not beside the handler, to get this. A screen opened anew enters again; going back to it does not, unlessLocalEntranceReplayisEveryVisit.FirstVisitremembers each screen opened while the app runs, by itsTrackedScreen, and plays only its first copy. A configuration change keeps the current entrance.screen_stateis reported at the start of each visit and when the label changes, never twice in a row for the same label. The event and itsscreenandstateparameters are unchanged.
Internal implementations
Component rendering, animation, native-ad hosting, snackbar orchestration, and default state-handler behavior.
Current risks
Feature-specific theme, onboarding-preview, and display-dialog code lives in this generic core module. The native-ad UI also exposes an advertising concern from the shared UI foundation.
views/ads holds only primitives now: the slot, the renderer, the palette, the presentations, and the two generic containers a host can place anywhere. Single-screen cards moved to the features that draw them, and the sample's to the sample. Do not add a one-screen wrapper back here: write it next to its screen, or add a NativeAdPresentation if the shape itself is new. The primitives themselves belong in :library:integration:ads; the reason they have not moved is recorded in that module's README.
Migration notes
Ad surfaces must fail closed and remain host-styleable
Native and banner ad requests previously assumed the Mobile Ads SDK had already initialized. When the preference/UI path disagreed with initialization, SDK calls could throw synchronously from a Compose effect and kill the host process, reported as IllegalStateException: MobileAds.initialize must be called before using the Google Mobile Ads SDK with NativeAdLoader.load under DisposableEffectImpl.onRemembered. Preserve the current behavior:
rememberAdsEnabledobserves the sameAdsSettingsRepository.adsEnabledused byAppOpenAdController; it must not choose its own default.Ad slots take their unit id from a host-bound
AdsConfigresolved by Koin qualifier, andNoDataScreeninjectsNO_DATA_NATIVE_ADwithout a fallback, a host that has not bound it crashes on the empty state rather than rendering without an ad. The host checklist lives in:library:integration:ads.BottomAppBarNativeAdBannerdefaults toenabled = false, with no rendering or ad request, and reportsonAdLoaded(false). A host must explicitly opt in. Native ads next to navigation can cause accidental clicks; review the placement warning and Google links before enabling this placement. The sample keeps the bottom-bar placement configured but disabled.rememberNativeAdandAdBannerwait forAdsSdkState, retry when readiness changes, and treat a synchronous SDK exception as a failed/empty ad slot rather than a fatal UI error.Loaded native ads are destroyed when their unit ID changes, when ads are disabled, or when the composable leaves composition.
NativeAdSlot.containerColoris a call-site override. Its default remains an unstyled Material card, while exceptional toolkit screens and consumer apps may match their own surfaces without changing every native ad.The shared native-ad CTA view wraps its label and padding; do not restore a toolkit-wide custom minimum height merely to align one screen.
Featured/no-data presentations retain the sponsored-label container, a clipped 16:9 media frame, and an end-aligned CTA. Grid presentations keep their content centered.
NativeAdPresentation.GridRowis the one presentation whose metrics the caller supplies, because it has to match the grid it is interleaved with. It keeps the disclosure chip inline with the body so the row stays as short as a cell; do not restore a stacked label there. Its badge silhouette comes fromrememberNativeAdBadgeShape, and is deliberately excluded from the presentation's equality: the renderer keys its view tree on the presentation, so comparing the badge by identity would tear down and restart the ad request whenever a caller rebuilt the shape. The badge is repainted in the palette pass instead. The ad icon is inset rather than clipped, which is what lets the badge carry a silhouette no view outline could express.
These are compatibility safeguards for host applications, not incidental styling details.