Compose Unstyled 2.0 is out! Check the official announcement blog ->
Compose Modifier

onFocusedBoundsChanged

Calls onPositioned whenever the bounds of the currently-focused area changes.

onFocusedBoundsChanged

Deprecated

onFocusedBoundsChanged doesn't reliably observe focus bounds changes through layout coordinate changes and focus changes. In a future release, the existing best-effort implementation will be removed, resulting in this becoming a no-op Modifier where onPositioned will never be called. Use FocusTargetModifierNode.getFocusedRect() instead to query this information on demand as needed.

Source set: Common
fun Modifier.onFocusedBoundsChanged(onPositioned: (LayoutCoordinates?) -> Unit): Modifier

Calls onPositioned whenever the bounds of the currently-focused area changes. If a child of this node has focus, onPositioned will be called immediately with a non-null LayoutCoordinates that can be queried for the focused bounds, and again every time the focused child changes or is repositioned. When a child loses focus, onPositioned will be passed null.

When an event occurs, it is bubbled up from the focusable node, so the nearest parent gets the event first, and then its parent, etc.

Note that there may be some cases where the focused bounds change but the callback is not invoked, but the last LayoutCoordinates will always return the most up-to-date bounds.

Last updated: