{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

OnRemeasuredModifierKt

public final class OnRemeasuredModifierKt


Summary

Public methods

static final @NonNull Modifier
onSizeChanged(
    @NonNull Modifier receiver,
    @NonNull Function1<@NonNull IntSizeUnit> onSizeChanged
)

Invoked with the size of the modified Compose UI element when the element is first measured or when the size of the element changes.

Public methods

onSizeChanged

public static final @NonNull Modifier onSizeChanged(
    @NonNull Modifier receiver,
    @NonNull Function1<@NonNull IntSizeUnit> onSizeChanged
)

Invoked with the size of the modified Compose UI element when the element is first measured or when the size of the element changes.

There are no guarantees onSizeChanged will not be re-invoked with the same size.

Using the onSizeChanged size value in a MutableState to update layout causes the new size value to be read and the layout to be recomposed in the succeeding frame, resulting in a one frame lag.

You can use onSizeChanged to affect drawing operations. Use Layout or SubcomposeLayout to enable the size of one component to affect the size of another.

Example usage:

import androidx.compose.material.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onSizeChanged

// Use onSizeChanged() for diagnostics. Use Layout or SubcomposeLayout if you want
// to use the size of one component to affect the size of another component.
Text(
    "Hello $name",
    Modifier.onSizeChanged { size ->
        println("The size of the Text in pixels is $size")
    }
)