# LayoutModifierNode

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/node/LayoutModifierNode.kt+class:androidx.compose.ui.node.LayoutModifierNode) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.3.0) Common/AllAndroid/JVM
- Cmn

  ```
  interface LayoutModifierNode : DelegatableNode
  ```
Known direct subclasses [ApproachLayoutModifierNode](https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/ApproachLayoutModifierNode)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/ApproachLayoutModifierNode` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/ApproachLayoutModifierNode` is designed to support gradually approaching the destination layout calculated in the lookahead pass. |

*** ** * ** ***

A `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.Node` that changes how its wrapped content is measured and laid out. It has the same measurement and layout functionality as the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Layout.composable#Layout(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.ui.layout.MeasurePolicy)` component, while wrapping exactly one layout due to it being a modifier. In contrast, the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Layout.composable#Layout(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.ui.layout.MeasurePolicy)` component is used to define the layout behavior of multiple children.

This is the `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.Node` equivalent of `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/LayoutModifier`

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.layout.LayoutModifier
import androidx.compose.ui.layout.Measurable
import androidx.compose.ui.layout.MeasureResult
import androidx.compose.ui.layout.MeasureScope
import androidx.compose.ui.layout.layout
import androidx.compose.ui.node.LayoutModifierNode
import androidx.compose.ui.node.ModifierNodeElement
import androidx.compose.ui.platform.InspectorInfo
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.offset

class VerticalPadding(var padding: Dp) : LayoutModifierNode, Modifier.Node() {
    override fun MeasureScope.measure(
        measurable: Measurable,
        constraints: Constraints,
    ): MeasureResult {
        val paddingPx = padding.roundToPx()
        val placeable = measurable.measure(constraints.offset(vertical = -paddingPx))
        return layout(placeable.width, placeable.height + paddingPx) {
            placeable.placeRelative(0, paddingPx)
        }
    }
}
data class VerticalPaddingElement(val padding: Dp) : ModifierNodeElement<VerticalPadding>() {
    override fun create() = VerticalPadding(padding)

    override fun update(node: VerticalPadding) {
        node.padding = padding
    }

    override fun InspectorInfo.inspectableProperties() {
        name = "verticalPadding"
        properties["padding"] = padding
    }
}
fun Modifier.verticalPadding(padding: Dp) = this then VerticalPaddingElement(padding)
Box(Modifier.background(Color.Gray).verticalPadding(50.dp)) {
    Box(Modifier.fillMaxSize().background(Color.DarkGray))
}
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Layout.composable#Layout(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.ui.layout.MeasurePolicy)` |   |

## Summary

| ### Public functions |
|---|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasureScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode#(androidx.compose.ui.layout.IntrinsicMeasureScope).maxIntrinsicHeight(androidx.compose.ui.layout.IntrinsicMeasurable,kotlin.Int)( measurable: https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable, width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` The lambda used to calculate `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable#maxIntrinsicHeight(kotlin.Int)`. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasureScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode#(androidx.compose.ui.layout.IntrinsicMeasureScope).maxIntrinsicWidth(androidx.compose.ui.layout.IntrinsicMeasurable,kotlin.Int)( measurable: https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable, height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` The function used to calculate `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable#maxIntrinsicWidth(kotlin.Int)`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasureResult` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasureScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode#(androidx.compose.ui.layout.MeasureScope).measure(androidx.compose.ui.layout.Measurable,androidx.compose.ui.unit.Constraints)(measurable: https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Measurable, constraints: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Constraints)` The function used to measure the modifier. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasureScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode#(androidx.compose.ui.layout.IntrinsicMeasureScope).minIntrinsicHeight(androidx.compose.ui.layout.IntrinsicMeasurable,kotlin.Int)( measurable: https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable, width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` The lambda used to calculate `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable#minIntrinsicHeight(kotlin.Int)`. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasureScope.https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode#(androidx.compose.ui.layout.IntrinsicMeasureScope).minIntrinsicWidth(androidx.compose.ui.layout.IntrinsicMeasurable,kotlin.Int)( measurable: https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable, height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` The function used to calculate `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable#minIntrinsicWidth(kotlin.Int)`. | Cmn |

| ### Extension functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode.https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode#(androidx.compose.ui.node.LayoutModifierNode).invalidateLayer()()` This will invalidate the current node's layer, and ensure that the layer is redrawn for the next frame. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode.https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode#(androidx.compose.ui.node.LayoutModifierNode).invalidateMeasurement()()` This invalidates the current node's measure result, and ensures that a re-measurement (the measurement block rerun) of this node will happen for the next frame. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode.https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode#(androidx.compose.ui.node.LayoutModifierNode).invalidatePlacement()()` This will invalidate the current node's placement result, and ensure that relayout (the placement block rerun) of this node will happen for the next frame . | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode.https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode#(androidx.compose.ui.node.LayoutModifierNode).remeasureSync()()` Performs the node remeasuring synchronously even if the node was not marked as needs remeasure before. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode.https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode#(androidx.compose.ui.node.LayoutModifierNode).updateLayerBlock(kotlin.Function1)(layerBlock: (https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/GraphicsLayerScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)?)` Updates the layer block of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode`. | Cmn |

### Inherited functions

From [androidx.compose.ui.node.DelegatableNode](https://developer.android.com/reference/kotlin/androidx/compose/ui/node/DelegatableNode) `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/annotation/EmptySuper
https://developer.android.com/reference/kotlin/androidx/compose/ui/node/DelegatableNode#onDensityChange()()`

Invoked when the density changes for this node.
Cmn `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/annotation/EmptySuper
https://developer.android.com/reference/kotlin/androidx/compose/ui/node/DelegatableNode#onLayoutDirectionChange()()`

Invoked when the layout direction changes for this node.
Cmn

### Inherited properties

From [androidx.compose.ui.node.DelegatableNode](https://developer.android.com/reference/kotlin/androidx/compose/ui/node/DelegatableNode) `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.Node` `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/DelegatableNode#node()`

A reference of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.Node` that holds this node's position in the node hierarchy.
Cmn

## Public functions

### IntrinsicMeasureScope.maxIntrinsicHeight

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/node/LayoutModifierNode.kt+function:maxIntrinsicHeight) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.3.0)

```
open fun IntrinsicMeasureScope.maxIntrinsicHeight(
    measurable: IntrinsicMeasurable,
    width: Int
): Int
```

The lambda used to calculate `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable#maxIntrinsicHeight(kotlin.Int)`.

### IntrinsicMeasureScope.maxIntrinsicWidth

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/node/LayoutModifierNode.kt+function:maxIntrinsicWidth) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.3.0)

```
open fun IntrinsicMeasureScope.maxIntrinsicWidth(
    measurable: IntrinsicMeasurable,
    height: Int
): Int
```

The function used to calculate `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable#maxIntrinsicWidth(kotlin.Int)`.

### MeasureScope.measure

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/node/LayoutModifierNode.kt+function:measure) Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
fun MeasureScope.measure(measurable: Measurable, constraints: Constraints): MeasureResult
```

The function used to measure the modifier. The `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode#(androidx.compose.ui.layout.MeasureScope).measure(androidx.compose.ui.layout.Measurable,androidx.compose.ui.unit.Constraints)` corresponds to the wrapped content, and it can be measured with the desired constraints according to the logic of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode`. The modifier needs to choose its own size, which can depend on the size chosen by the wrapped content (the obtained `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Placeable`), if the wrapped content was measured. The size needs to be returned as part of a `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasureResult`, alongside the placement logic of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Placeable`, which defines how the wrapped content should be positioned inside the `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode`. A convenient way to create the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasureResult` is to use the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasureScope#layout(kotlin.Int,kotlin.Int,kotlin.collections.Map,kotlin.Function1)` factory function.

A `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode` uses the same measurement and layout concepts and principles as a `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Layout.composable#Layout(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.ui.layout.MeasurePolicy)`, the only difference is that they apply to exactly one child. For a more detailed explanation of measurement and layout, see `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasurePolicy`.

### IntrinsicMeasureScope.minIntrinsicHeight

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/node/LayoutModifierNode.kt+function:minIntrinsicHeight) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.3.0)

```
open fun IntrinsicMeasureScope.minIntrinsicHeight(
    measurable: IntrinsicMeasurable,
    width: Int
): Int
```

The lambda used to calculate `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable#minIntrinsicHeight(kotlin.Int)`.

### IntrinsicMeasureScope.minIntrinsicWidth

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/node/LayoutModifierNode.kt+function:minIntrinsicWidth) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.3.0)

```
open fun IntrinsicMeasureScope.minIntrinsicWidth(
    measurable: IntrinsicMeasurable,
    height: Int
): Int
```

The function used to calculate `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasurable#minIntrinsicWidth(kotlin.Int)`.

## Extension functions

### LayoutModifierNode.invalidateLayer

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/node/LayoutModifierNode.kt+function:invalidateLayer)

```
fun LayoutModifierNode.invalidateLayer(): Unit
```

This will invalidate the current node's layer, and ensure that the layer is redrawn for the next frame.

### LayoutModifierNode.invalidateMeasurement

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/node/LayoutModifierNode.kt+function:invalidateMeasurement)

```
fun LayoutModifierNode.invalidateMeasurement(): Unit
```

This invalidates the current node's measure result, and ensures that a re-measurement (the measurement block rerun) of this node will happen for the next frame.

### LayoutModifierNode.invalidatePlacement

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/node/LayoutModifierNode.kt+function:invalidatePlacement)

```
fun LayoutModifierNode.invalidatePlacement(): Unit
```

This will invalidate the current node's placement result, and ensure that relayout (the placement block rerun) of this node will happen for the next frame .

### LayoutModifierNode.remeasureSync

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/node/LayoutModifierNode.kt+function:remeasureSync)

```
fun LayoutModifierNode.remeasureSync(): Unit
```

Performs the node remeasuring synchronously even if the node was not marked as needs remeasure before. Useful for cases like when during scrolling you need to re-execute the measure block to consume the scroll offset and remeasure your children in a blocking way.

### LayoutModifierNode.updateLayerBlock

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/node/LayoutModifierNode.kt+function:updateLayerBlock)

```
fun LayoutModifierNode.updateLayerBlock(layerBlock: (GraphicsLayerScope.() -> Unit)?): Unit
```

Updates the layer block of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/LayoutModifierNode`. This will mark the layer as invalidated and schedule a refresh of the layer.

Updating the layer lambda using this method is cheaper than invalidating placement and placing the layout with a new layer block. This API is expected to be used alongside `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Placeable#placeAt(androidx.compose.ui.unit.IntOffset,kotlin.Float,kotlin.Function1)` with a `layerBlock` parameter passed. This will override/update the layerBlock passed in that API. Whichever one was called last should "win".

| Parameters |
|---|---|
| `layerBlock: (https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/GraphicsLayerScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)?` | the snapshot-observed lambda used to set properties on the layer. if `null`, is provided it will remove the layer. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Placeable#placeAt(androidx.compose.ui.unit.IntOffset,kotlin.Float,kotlin.Function1)` |   |