# CompositionLocalAccessorScope

Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/CompositionLocal.kt+class:androidx.compose.runtime.CompositionLocalAccessorScope) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.7.0) Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  interface CompositionLocalAccessorScope
  ```
Known direct subclasses [CustomStyleScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/CustomStyleScope), [StyleResolverScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/StyleResolverScope)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/CustomStyleScope` | An interface that is the base interface for all styles scopes. |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/StyleResolverScope` | The type of the scope of `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/StyleResolver#resolve(kotlin.Function1)` that allows the `block` to read the fully resolved values from a style. |

Known indirect subclasses [CommonStyleScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/CommonStyleScope), [StyleScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/StyleScope)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/CommonStyleScope` | A `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/CommonStyleScope` is the scope used by a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/CommonStyle`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/StyleScope` | A `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/StyleScope` is the receiver scope of a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/Style` lambda. |

*** ** * ** ***

## Summary

| ### Public properties |
|---|---|---|
| `T` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/CompositionLocal<T>.https://developer.android.com/reference/kotlin/androidx/compose/runtime/CompositionLocalAccessorScope#(androidx.compose.runtime.CompositionLocal).currentValue()` An extension property that allows accessing the current value of a composition local in the context of this scope. | Cmn |

| ### Extension functions |
|---|---|---|
| `inline T` | `@https://developer.android.com/reference/kotlin/androidx/compose/ui/ExperimentalMediaQueryApi <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/CompositionLocalAccessorScope.https://developer.android.com/reference/kotlin/androidx/compose/runtime/CompositionLocalAccessorScope#(androidx.compose.runtime.CompositionLocalAccessorScope).mediaQuery(kotlin.Function1)(query: https://developer.android.com/reference/kotlin/androidx/compose/ui/UiMediaScope.() -> T)` Evaluates a query against the current `https://developer.android.com/reference/kotlin/androidx/compose/ui/UiMediaScope` from a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/CompositionLocalAccessorScope`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/ExperimentalFoundationStyleApi <T : https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/ContentPaddingScope & https://developer.android.com/reference/kotlin/androidx/compose/runtime/CompositionLocalAccessorScope> T.https://developer.android.com/reference/kotlin/androidx/compose/runtime/CompositionLocalAccessorScope#(androidx.compose.foundation.style.ContentPaddingScope).contentPadding(androidx.compose.foundation.layout.PaddingValues)( paddingValues: https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/PaddingValues )` Sets the padding for the component's content. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/ExperimentalFoundationStyleApi <T : https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/ExternalPaddingScope & https://developer.android.com/reference/kotlin/androidx/compose/runtime/CompositionLocalAccessorScope> T.https://developer.android.com/reference/kotlin/androidx/compose/runtime/CompositionLocalAccessorScope#(androidx.compose.foundation.style.ExternalPaddingScope).externalPadding(androidx.compose.foundation.layout.PaddingValues)( paddingValues: https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/PaddingValues )` Sets the external padding for the component. | Cmn |

## Public properties

### CompositionLocal.currentValue

Cmn Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/CompositionLocal.kt+symbol:currentValue)

```
val CompositionLocal<T>.currentValue: T
```

An extension property that allows accessing the current value of a composition local in the context of this scope. This scope is the type of the `this` parameter when in a computed composition. Computed composition locals can be provided by either using `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#compositionLocalWithComputedDefaultOf(kotlin.Function1)` or by using the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProvidableCompositionLocal#providesComputed(kotlin.Function1)` infix operator.

```kotlin
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.compositionLocalOf

val LocalValue = compositionLocalOf { 10 }
val LocalLargerValue = compositionLocalOf { 12 }

@Composable
fun App() {
    CompositionLocalProvider(
        LocalLargerValue providesComputed { LocalValue.currentValue + 10 }
    ) {
        SomeScreen()
    }
}
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProvidableCompositionLocal` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProvidableCompositionLocal#providesComputed(kotlin.Function1)` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProvidableCompositionLocal#provides(kotlin.Any)` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/CompositionLocalProvider.composable#CompositionLocalProvider(kotlin.Array,kotlin.Function0)` |   |

## Extension functions

### CompositionLocalAccessorScope.mediaQuery

Cmn Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/MediaQuery.kt+function:mediaQuery)

```
@ExperimentalMediaQueryApi
inline fun <T : Any?> CompositionLocalAccessorScope.mediaQuery(query: UiMediaScope.() -> T): T
```

Evaluates a query against the current `https://developer.android.com/reference/kotlin/androidx/compose/ui/UiMediaScope` from a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/CompositionLocalAccessorScope`.

If called within a snapshot-aware context, the specific property reads within the query will be tracked, and the scope will be invalidated when any of those properties change.

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.style.MutableStyleState
import androidx.compose.foundation.style.Style
import androidx.compose.foundation.style.hovered
import androidx.compose.foundation.style.pressed
import androidx.compose.foundation.style.size
import androidx.compose.foundation.style.styleable
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.UiMediaScope.PointerPrecision
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.mediaQuery
import androidx.compose.ui.unit.dp

// Create a styleable clickable box
@Composable
fun ClickableStyleableBox(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    style: Style = Style,
) {
    val interactionSource = remember { MutableInteractionSource() }
    val styleState = remember { MutableStyleState(interactionSource) }
    Box(
        modifier =
            modifier
                .clickable(interactionSource = interactionSource, onClick = onClick)
                .styleable(styleState, style)
    )
}

ClickableStyleableBox(
    onClick = {},
    style = {
        background(Color.Green)

        // Dynamic size based on window Size
        if (mediaQuery { windowWidth > 600.dp && windowHeight > 400.dp }) {
            size(200.dp)
        } else {
            size(150.dp)
        }

        // Hover state for fine pointer input
        if (mediaQuery { pointerPrecision == PointerPrecision.Fine }) {
            hovered { background(Color.Yellow) }
        }
        pressed { background(Color.Red) }
    },
)
```

| Parameters |
|---|---|
| `query: https://developer.android.com/reference/kotlin/androidx/compose/ui/UiMediaScope.() -> T` | A lambda expression with `https://developer.android.com/reference/kotlin/androidx/compose/ui/UiMediaScope` as its receiver, representing the condition to evaluate. |

| Returns |
|---|---|
| `T` | The immediate result of the query. |

### T.contentPadding

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/style/StyleScope.kt+function:contentPadding)

```
@ExperimentalFoundationStyleApi
fun <T : ContentPaddingScope & CompositionLocalAccessorScope> T.contentPadding(
    paddingValues: PaddingValues
): Unit
```

Sets the padding for the component's content. Content padding is the space between the component's border (if any) and its content. The width/height of the component includes content padding.

This property is *not* inherited

| Parameters |
|---|---|
| `paddingValues: https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/PaddingValues` | The `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/PaddingValues` to apply to the content. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/package-summary#(androidx.compose.foundation.style.ContentPaddingScope).contentPadding(androidx.compose.foundation.layout.PaddingValues)` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/padding.modifier#(androidx.compose.ui.Modifier).padding(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)` |   |

### T.externalPadding

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/style/StyleScope.kt+function:externalPadding)

```
@ExperimentalFoundationStyleApi
fun <T : ExternalPaddingScope & CompositionLocalAccessorScope> T.externalPadding(
    paddingValues: PaddingValues
): Unit
```

Sets the external padding for the component. The external padding is the space between the edge of the component and its border (if any). The width/height of the component includes external padding.

This property is *not* inherited

| Parameters |
|---|---|
| `paddingValues: https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/PaddingValues` | The `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/PaddingValues` to apply to the external padding. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/package-summary#(androidx.compose.foundation.style.ExternalPaddingScope).externalPadding(androidx.compose.foundation.layout.PaddingValues)` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/padding.modifier#(androidx.compose.ui.Modifier).padding(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp)` |   |