# GlobalPositionAwareModifierNode

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

  ```
  interface GlobalPositionAwareModifierNode : DelegatableNode
  ```

*** ** * ** ***

A `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.Node` whose `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/GlobalPositionAwareModifierNode#onGloballyPositioned(androidx.compose.ui.layout.LayoutCoordinates)` is called with the final LayoutCoordinates of the Layout when the global position of the content may have changed. Note that it will be called after a composition when the coordinates are finalized.

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/OnGloballyPositionedModifier`

Usage example:

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.size
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.positionInRoot
import androidx.compose.ui.layout.positionInWindow
import androidx.compose.ui.unit.dp

Column(
    Modifier.onGloballyPositioned { coordinates ->
        // This will be the size of the Column.
        coordinates.size
        // The position of the Column relative to the application window.
        coordinates.positionInWindow()
        // The position of the Column relative to the Compose root.
        coordinates.positionInRoot()
        // These will be the alignment lines provided to the layout (empty here for Column).
        coordinates.providedAlignmentLines
        // This will be a LayoutCoordinates instance corresponding to the parent of Column.
        coordinates.parentLayoutCoordinates
    }
) {
    Box(Modifier.size(20.dp).background(Color.Green))
    Box(Modifier.size(20.dp).background(Color.Blue))
}
```

```kotlin
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.LayoutCoordinates
import androidx.compose.ui.layout.positionInRoot
import androidx.compose.ui.layout.positionInWindow
import androidx.compose.ui.node.GlobalPositionAwareModifierNode
import androidx.compose.ui.node.ModifierNodeElement
import androidx.compose.ui.platform.InspectorInfo

class PositionLoggerNode(var id: String) : GlobalPositionAwareModifierNode, Modifier.Node() {
    override fun onGloballyPositioned(coordinates: LayoutCoordinates) {
        // This will be the size of the Layout.
        coordinates.size
        // The position of the Layout relative to the application window.
        coordinates.positionInWindow()
        // The position of the Layout relative to the Compose root.
        coordinates.positionInRoot()
        // These will be the alignment lines provided to the Layout
        coordinates.providedAlignmentLines
        // This will be a LayoutCoordinates instance corresponding to the parent of the Layout.
        coordinates.parentLayoutCoordinates
    }
}

data class PositionLoggerElement(val id: String) : ModifierNodeElement<PositionLoggerNode>() {
    override fun create() = PositionLoggerNode(id)

    override fun update(node: PositionLoggerNode) {
        node.id = id
    }

    override fun InspectorInfo.inspectableProperties() {
        name = "logPosition"
        properties["id"] = id
    }
}

fun Modifier.logPosition(id: String) = this then PositionLoggerElement(id)
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/LayoutCoordinates` |   |

## Summary

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/GlobalPositionAwareModifierNode#onGloballyPositioned(androidx.compose.ui.layout.LayoutCoordinates)(coordinates: https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/LayoutCoordinates)` Called with the final LayoutCoordinates of the Layout after measuring. | 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

### onGloballyPositioned

Cmn Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.3.0)

```
fun onGloballyPositioned(coordinates: LayoutCoordinates): Unit
```

Called with the final LayoutCoordinates of the Layout after measuring. Note that it will be called after a composition when the coordinates are finalized. The position in the modifier chain makes no difference in either the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/LayoutCoordinates` argument or when the `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/GlobalPositionAwareModifierNode#onGloballyPositioned(androidx.compose.ui.layout.LayoutCoordinates)` is called.