Glass Bottom Sheet

Create a glass bottom sheet

Goals

  • Create a glass bottom sheet based on the code:

Box(Modifier.fillMaxSize()) {
    val backgroundColor = Color.White
    val backdrop = rememberLayerBackdrop {
        drawRect(backgroundColor)
        drawContent()
    }

    MainNavHost(
        modifier = Modifier.layerBackdrop(backdrop)
    )

    GlassBottomSheet(backdrop = backdrop)
}

What you will learn

  • Handle the case of "glass on glass"

  • Make use of exportedBackdrop parameter of the drawBackdrop modifier

Steps

1

Create a GlassBottomSheet

The backdrop for the glass button is backdrop, but we want to include the bottom sheet.

2

Use the bottom sheet as a backdrop for the glass button (WRONG code)

The WRONG idea is to set a new LayerBackdrop after drawBackdrop .

You will get a crash:

Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x__ in tid __ (RenderThread), pid __

Because the layerBackdrop modifier will draw the content to the bottomSheetBackdrop, and the content will draw the bottomSheetBackdrop, it's a loop!

3

Use the bottom sheet as a backdrop for the glass button (CORRECT code)

Use exportedBackdrop in drawBackdrop modifier, it will skip drawing the content.

Final code

chevron-rightFinal codehashtag

Last updated