Composable Function

derivedMediaQuery

Evaluates a query against the current UiMediaScope, wrapped in a derivedStateOf.

derivedMediaQuery

Source set: Common
@Deprecated(
    "Use `computedMediaQuery` instead, which offers better performance for trivial calculations",
    ReplaceWith("computedMediaQuery(query)", "androidx.compose.ui.computedMediaQuery"),
)
@Composable
public fun <T> derivedMediaQuery(query: UiMediaScope.() -> T): State<T>

Evaluates a query against the current UiMediaScope, wrapped in a derivedStateOf.

Use this function for queries that involve frequently changing values, such as UiMediaScope.windowWidth or UiMediaScope.windowHeight. It ensures that compositions only recompose when the result of the query changes, not on every small change to the underlying values (like a 1px size change).

For queries on stable properties, you can use the simpler mediaQuery function. For queries that don't benefit from the caching behavior of derivedStateOf, use computedMediaQuery for better performance.

Parameters

query The condition to evaluate against the UiMediaScope.

Return

A State holding the result of the query. The state will only update when the evaluated result of the query changes.

Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: