PdfSelectionMenu

fun BoxScope.PdfSelectionMenu(state: PdfViewState, items: List<PdfSelectionMenuItem>, modifier: Modifier = Modifier, highlightColors: List<Color> = emptyList(), onHighlightColorPicked: (TextSelection, Color) -> Unit? = null, clearSelectionOnColorPick: Boolean = true, alignment: Alignment = Alignment.TopCenter, showWhileSelecting: Boolean = false, containerColor: Color = PdfSelectionMenuDefaults.ContainerColor, contentColor: Color = PdfSelectionMenuDefaults.ContentColor, container: @Composable (selection: TextSelection, content: @Composable () -> Unit) -> Unit? = null, itemContent: @Composable (item: PdfSelectionMenuItem, selection: TextSelection) -> Unit? = null, colorSwatch: @Composable (color: Color, onPick: () -> Unit) -> Unit? = null)

The selection context menu: place it in PdfView's overlay slot and it appears whenever text is selected, listing items and, when highlightColors is non-empty, a wrapping row of colour swatches.

It waits for the finger to lift. While PdfViewState.selectionInProgress is true the menu stays hidden, because a popup over the page mid-drag covers the very words being chosen; it appears the moment the drag ends.

Every visual layer is replaceable:

  • container swaps the card the menu sits in (the default is a white rounded card); its content argument is the laid-out menu body.

  • itemContent swaps how one action renders (the default is a pill chip).

  • colorSwatch swaps how one colour renders (the default is a circle).

  • For a completely different menu, skip this composable and build your own against PdfViewState.selection and PdfViewState.selectionInProgress; this one is the default, not the contract.

PdfView(state, overlay = {
PdfSelectionMenu(
state = state,
items = listOf(
PdfSelectionMenuItem("Copy") { clipboard.setText(AnnotatedString(it.text)) },
PdfSelectionMenuItem("Highlight") { marks.add(it) },
),
highlightColors = listOf(Color.Yellow, Color.Green, Color.Cyan),
onHighlightColorPicked = { sel, color -> marks.add(sel, color) },
)
})