Android 12 Developer Preview is here! Try it out, and give us your feedback!

PopupPositionProvider

@Immutable interface PopupPositionProvider
androidx.compose.ui.window.PopupPositionProvider

Calculates the position of a Popup on screen.

Summary

Public methods
abstract IntOffset
calculatePosition(anchorBounds: IntRect, windowSize: IntSize, layoutDirection: LayoutDirection, popupContentSize: IntSize)

Calculates the position of a Popup on screen.

Public methods

calculatePosition

abstract fun calculatePosition(
    anchorBounds: IntRect,
    windowSize: IntSize,
    layoutDirection: LayoutDirection,
    popupContentSize: IntSize
): IntOffset

Calculates the position of a Popup on screen.

The window size is useful in cases where the popup is meant to be positioned next to its anchor instead of inside of it. The size can be used to calculate available space around the parent to find a spot with enough clearance (e.g. when implementing a dropdown). Note that positioning the popup outside of the window bounds might prevent it from being visible.

Parameters
anchorBounds: IntRect The window relative bounds of the layout which this popup is anchored to.
windowSize: IntSize The size of the window containing the anchor layout.
layoutDirection: LayoutDirection The layout direction of the anchor layout.
popupContentSize: IntSize The size of the popup's content.
Return
The window relative position where the popup should be positioned.