Skip to content

LayerStackManager

class LayerStackManager(parentComposition: CompositionContext)

Manages an ordered stack of Layers for a single screen.

The stack determines the rendering order (bottom to top) and input-dispatch priority (top layer receives events first). Overlays such as dialogs, dropdowns, and tooltips are each their own layer on top of the base screen content.

Obtain an instance via the LocalLayerManager composition local.

Parameters

  • parentComposition: The CompositionContext from the host screen, required when creating child Compositions for each layer.

Constructors

LayerStackManager

constructor(parentComposition: CompositionContext)

Parameters

  • parentComposition: The CompositionContext from the host screen, required when creating child Compositions for each layer.

Properties

layers

val layers: SnapshotStateList<Layer>

The ordered list of active layers. Layers are rendered bottom-to-top.

top

val top: Layer?

The topmost (most recently pushed) layer, which receives input events first. null if the stack is empty.

Functions

fun modal(
    alignment: Alignment = Alignment.Center, 
    dismissOnClickOutside: Boolean = true, 
    onDismissRequest: () -> Unit = {}, 
    content: @Composable



 ModalScope.() -> Unit
)

Pushes a new modal layer onto the stack.

Modals are opinionated, input-blocking overlays ideal for dialogs and confirmation prompts. A click outside the modal content area triggers onDismissRequest and, when dismissOnClickOutside is true, automatically removes the layer.

Parameters

  • alignment: Alignment of the modal within the full screen. Default Alignment.Center.

  • dismissOnClickOutside: Whether clicking outside the modal content closes it.

  • onDismissRequest: Optional callback invoked when the modal is dismissed.

  • content: The modal UI, a composable lambda with ModalScope receiver.

pop

fun pop(): Unit?

Removes and disposes the topmost layer.

popById

fun popById(id: UUID)

Removes and disposes the layer identified by id.

Does nothing if no layer with that id exists.

Parameters

  • id: The UUID of the layer to remove.

push

fun push(layerContent: @Composable



 (dismiss: () -> Unit) -> Unit): () -> Unit

Pushes a new generic layer onto the stack.

The content lambda receives a dismiss function it can call to remove itself from the stack. This overload is suitable for persistent overlays and custom layer types.

Return

A dismiss handle; call it to imperatively remove the layer.

Parameters

  • layerContent: The composable content for the new layer.