OverlayHost

An OverlayHost can be used overlaysOverlay with content on top of other content. This is useful for one-off request/result flows such as:

  • Bottom sheets

  • Modals/dialogs

  • Tooltips

  • Full-screen takeover prompts

  • etc.

The suspend show function is generically typed and can be suspended on to await the result of whatever overlay was launched.

currentOverlayData is read-only and can be used to observe the current overlay data. This is generally intended to be used wherever the OverlayHost is provided via LocalOverlayHost.

In Android, this can be managed via the ContentWithOverlays composable function.

To avoid accidentally capturing unnecessary state, it's recommended to create extension functions on OverlayHost that call show with the appropriate overlay and result type.

private suspend fun OverlayHost.confirm(message: String): ConfirmationResult {
return show(ConfirmationOverlay(message))
}

Properties

Link copied to clipboard

The current OverlayHostData or null if no overlay is currently showing.

Functions

Link copied to clipboard
abstract suspend fun <Result : Any> show(overlay: Overlay<Result>): Result

Shows the given overlay and suspends until the overlay is finished with a Result. The overlay should always signal a result (even if it's just something like Result.Dismissed) so that the OverlayHost can properly clear its currentOverlayData.