# TransformingLazyColumnState

Artifact: [androidx.wear.compose:compose-foundation](https://developer.android.com/jetpack/androidx/releases/wear-compose) [View Source](https://cs.android.com/search?q=file:androidx/wear/compose/foundation/lazy/TransformingLazyColumnState.kt+class:androidx.wear.compose.foundation.lazy.TransformingLazyColumnState) Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.5.0)


```
class TransformingLazyColumnState : ScrollableState
```

<br />

*** ** * ** ***

A state object that can be hoisted to control and observe scrolling in a `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumn.composable#TransformingLazyColumn(androidx.compose.ui.Modifier,androidx.wear.compose.foundation.lazy.TransformingLazyColumnState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.layout.Arrangement.Vertical,androidx.compose.ui.Alignment.Horizontal,androidx.compose.foundation.gestures.FlingBehavior,kotlin.Boolean,androidx.wear.compose.foundation.rotary.RotaryScrollableBehavior,androidx.compose.foundation.OverscrollEffect,androidx.wear.compose.foundation.lazy.TransformingLazyColumnFirstLayoutItemProvider,kotlin.Function1)`.

## Summary

| ### Public constructors |
|---|
| `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/annotation/RememberInComposition https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#TransformingLazyColumnState(kotlin.Int,kotlin.Int)( initialAnchorItemIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, initialAnchorItemScrollOffset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` |

| ### Public functions |
|---|---|
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#animateScrollToItem(kotlin.Int,kotlin.Int)(index: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, scrollOffset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Animate (smooth scroll) to the given item. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#dispatchRawDelta(kotlin.Float)(delta: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#requestScrollToItem(kotlin.Int,kotlin.Int)(index: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, scrollOffset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Requests the item at `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#requestScrollToItem(kotlin.Int,kotlin.Int)` to be at the center of the viewport during the next remeasure, offset by `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#requestScrollToItem(kotlin.Int,kotlin.Int)`. |
| `open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#scroll(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction1)(scrollPriority: https://developer.android.com/reference/kotlin/androidx/compose/foundation/MutatePriority, block: suspend https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#scrollToItem(kotlin.Int,kotlin.Int)(index: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, scrollOffset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Scrolls the item specified by `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#scrollToItem(kotlin.Int,kotlin.Int)` to the center of the screen. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#anchorItemIndex()` The index of the item that is used in scrolling. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#anchorItemScrollOffset()` The scroll offset of the anchor item. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#canScrollBackward()` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#canScrollForward()` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#isScrollInProgress()` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#lastScrolledBackward()` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#lastScrolledForward()` |
| `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnLayoutInfo` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#layoutInfo()` The object of LazyColumnLayoutInfo calculated during the last layout pass. |

| ### Extension functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnFirstLayoutItemProvider.ItemInfo?` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState.https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#(androidx.wear.compose.foundation.lazy.TransformingLazyColumnState).layoutItemInfoOf(kotlin.Any,androidx.wear.compose.foundation.lazy.TransformingLazyColumnFirstLayoutItemProvider.ItemEdge)( itemKey: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, itemEdge: https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnFirstLayoutItemProvider.ItemEdge )` Returns the `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnFirstLayoutItemProvider.ItemInfo` for the visible item with the given `https://developer.android.com/reference/kotlin/androidx/wear/compose/material3/lazy/package-summary#(androidx.wear.compose.foundation.lazy.TransformingLazyColumnState).layoutItemInfoOf(kotlin.Any,androidx.wear.compose.foundation.lazy.TransformingLazyColumnFirstLayoutItemProvider.ItemEdge)`, aligned to the specified `https://developer.android.com/reference/kotlin/androidx/wear/compose/material3/lazy/package-summary#(androidx.wear.compose.foundation.lazy.TransformingLazyColumnState).layoutItemInfoOf(kotlin.Any,androidx.wear.compose.foundation.lazy.TransformingLazyColumnFirstLayoutItemProvider.ItemEdge)`. |

| ### Extension properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnFirstLayoutItemProvider.ItemInfo?` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState.https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#(androidx.wear.compose.foundation.lazy.TransformingLazyColumnState).firstVisibleItemLayoutItemInfo()` Returns the `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnFirstLayoutItemProvider.ItemInfo` for the first visible item aligned to its `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnFirstLayoutItemProvider.ItemEdge#Start()` edge, or null if there are no visible items. |

### Inherited properties

From [androidx.compose.foundation.gestures.ScrollableState](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState) `open https://developer.android.com/reference/kotlin/androidx/compose/foundation/ScrollIndicatorState?` `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState#scrollIndicatorState()`

## Public constructors

### TransformingLazyColumnState

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.5.0)

```
@RememberInComposition
TransformingLazyColumnState(
    initialAnchorItemIndex: Int = -1,
    initialAnchorItemScrollOffset: Int = 0
)
```

| Parameters |
|---|---|
| `initialAnchorItemIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = -1` | The index of the item to be used as the anchor. If a non-negative index is provided, the state will attempt to center this item in the viewport. If a negative index is provided then the list will be initialized with the first item (index 0) pinned to the start of the viewport, respecting any content padding. This is the default behavior. |
| `initialAnchorItemScrollOffset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | The offset to be applied to the anchor item. Defaults to 0. This offset is ONLY used when a non-negative `initialAnchorItemIndex` is provided (i.e., when the item is being centered). It is ignored if `initialAnchorItemIndex` is less than 0. The offset is used when placing the item in the center of the screen; a positive value scrolls the item towards the end of the list, and a negative value scrolls it towards the start. This correlates with `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#anchorItemScrollOffset()`. |

## Public functions

### animateScrollToItem

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.5.0)

```
suspend fun animateScrollToItem(index: @IntRange(from = 0) Int, scrollOffset: Int = 0): Unit
```

Animate (smooth scroll) to the given item.

The scroll position `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#anchorItemIndex()` and `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#anchorItemScrollOffset()` will be updated to take into account the new layout. There is no guarantee that `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#animateScrollToItem(kotlin.Int,kotlin.Int)` will become the new `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#anchorItemIndex()` since requested `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#animateScrollToItem(kotlin.Int,kotlin.Int)` may position item with another index closer to the anchor point.

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.wear.compose.foundation.lazy.TransformingLazyColumn
import androidx.wear.compose.foundation.lazy.rememberTransformingLazyColumnState
import androidx.wear.compose.material.Text

val state =
    rememberTransformingLazyColumnState(
        // Customize initial scroll position of the TransformingLazyColumn.
        initialAnchorItemIndex = 10
    )
val coroutineScope = rememberCoroutineScope()

TransformingLazyColumn(
    modifier = Modifier.background(Color.Black),
    state = state,
    contentPadding = PaddingValues(vertical = 20.dp),
) {
    items(count = 20) {
        Text(
            "Item $it",
            modifier =
                Modifier.drawBehind {
                        val isCentered =
                            it == state.anchorItemIndex &&
                                abs(state.anchorItemScrollOffset) < size.height
                        drawRect(if (isCentered) Color.Green else Color.DarkGray)
                    }
                    .padding(5.dp)
                    .clickable { coroutineScope.launch { state.scrollToItem(it) } },
        )
    }

    item {
        Text(
            "Scroll to top",
            modifier =
                Modifier.clickable { coroutineScope.launch { state.animateScrollToItem(0) } },
        )
    }
}

LaunchedEffect(Unit) {
    snapshotFlow { state.anchorItemIndex }.collect { println("Anchor item index: $it") }
}
```

| Parameters |
|---|---|
| `index: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the index to which to scroll. Must be non-negative. |
| `scrollOffset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | The offset between the center of the screen and item's center. Positive offset means the item will be scrolled up. |

### dispatchRawDelta

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.5.0)

```
open fun dispatchRawDelta(delta: Float): Float
```

### requestScrollToItem

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.5.0)

```
fun requestScrollToItem(index: @IntRange(from = 0) Int, scrollOffset: Int = 0): Unit
```

Requests the item at `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#requestScrollToItem(kotlin.Int,kotlin.Int)` to be at the center of the viewport during the next remeasure, offset by `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#requestScrollToItem(kotlin.Int,kotlin.Int)`.

The scroll position `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#anchorItemIndex()` and `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#anchorItemScrollOffset()` will be updated to take into account the new layout. There is no guarantee that `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#requestScrollToItem(kotlin.Int,kotlin.Int)` will become the new `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#anchorItemIndex()` since requested `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#requestScrollToItem(kotlin.Int,kotlin.Int)` may position item with another index closer to the anchor point.

The scroll position will be updated to the requested position rather than maintain the index based on the center item key (when a data set change will also be applied during the next remeasure), but *only* for the next remeasure.

Any scroll in progress will be cancelled.

| Parameters |
|---|---|
| `index: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the index to which to scroll. Must be non-negative. |
| `scrollOffset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | The offset between the center of the screen and item's center. Positive offset means the item will be scrolled up. |

### scroll

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.5.0)

```
open suspend fun scroll(scrollPriority: MutatePriority, block: suspend ScrollScope.() -> Unit): Unit
```

### scrollToItem

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.5.0)

```
suspend fun scrollToItem(index: @IntRange(from = 0) Int, scrollOffset: Int = 0): Unit
```

Scrolls the item specified by `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#scrollToItem(kotlin.Int,kotlin.Int)` to the center of the screen.

The scroll position `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#anchorItemIndex()` and `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#anchorItemScrollOffset()` will be updated to take into account the new layout. There is no guarantee that `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#scrollToItem(kotlin.Int,kotlin.Int)` will become the new `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#anchorItemIndex()` since requested `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#scrollToItem(kotlin.Int,kotlin.Int)` may position item with another index closer to the anchor point.

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.wear.compose.foundation.lazy.TransformingLazyColumn
import androidx.wear.compose.foundation.lazy.rememberTransformingLazyColumnState
import androidx.wear.compose.material.Text

val state =
    rememberTransformingLazyColumnState(
        // Customize initial scroll position of the TransformingLazyColumn.
        initialAnchorItemIndex = 10
    )
val coroutineScope = rememberCoroutineScope()

TransformingLazyColumn(
    modifier = Modifier.background(Color.Black),
    state = state,
    contentPadding = PaddingValues(vertical = 20.dp),
) {
    items(count = 20) {
        Text(
            "Item $it",
            modifier =
                Modifier.drawBehind {
                        val isCentered =
                            it == state.anchorItemIndex &&
                                abs(state.anchorItemScrollOffset) < size.height
                        drawRect(if (isCentered) Color.Green else Color.DarkGray)
                    }
                    .padding(5.dp)
                    .clickable { coroutineScope.launch { state.scrollToItem(it) } },
        )
    }

    item {
        Text(
            "Scroll to top",
            modifier =
                Modifier.clickable { coroutineScope.launch { state.animateScrollToItem(0) } },
        )
    }
}

LaunchedEffect(Unit) {
    snapshotFlow { state.anchorItemIndex }.collect { println("Anchor item index: $it") }
}
```

This operation happens instantly without animation.

| Parameters |
|---|---|
| `index: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The index of the item to scroll to. Must be non-negative. |
| `scrollOffset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | The offset between the center of the screen and item's center. Positive offset means the item will be scrolled up. |

## Public properties

### anchorItemIndex

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.5.0)

```
val anchorItemIndex: Int
```

The index of the item that is used in scrolling. For the most cases that is the item closest to the center of viewport from `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnLayoutInfo#visibleItems()`, however it might change during scroll.

Note that this property is observable and if you use it in the composable function it will be recomposed on every change causing potential performance issues.

If you need to use it in the composition then consider wrapping the calculation into a derived state in order to only have recompositions when the derived value changes:

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.wear.compose.foundation.lazy.TransformingLazyColumn
import androidx.wear.compose.foundation.lazy.rememberTransformingLazyColumnState
import androidx.wear.compose.material.Text

val state =
    rememberTransformingLazyColumnState(
        // Customize initial scroll position of the TransformingLazyColumn.
        initialAnchorItemIndex = 10
    )
val coroutineScope = rememberCoroutineScope()

TransformingLazyColumn(
    modifier = Modifier.background(Color.Black),
    state = state,
    contentPadding = PaddingValues(vertical = 20.dp),
) {
    items(count = 20) {
        Text(
            "Item $it",
            modifier =
                Modifier.drawBehind {
                        val isCentered =
                            it == state.anchorItemIndex &&
                                abs(state.anchorItemScrollOffset) < size.height
                        drawRect(if (isCentered) Color.Green else Color.DarkGray)
                    }
                    .padding(5.dp)
                    .clickable { coroutineScope.launch { state.scrollToItem(it) } },
        )
    }

    item {
        Text(
            "Scroll to top",
            modifier =
                Modifier.clickable { coroutineScope.launch { state.animateScrollToItem(0) } },
        )
    }
}

LaunchedEffect(Unit) {
    snapshotFlow { state.anchorItemIndex }.collect { println("Anchor item index: $it") }
}
```

### anchorItemScrollOffset

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.5.0)

```
val anchorItemScrollOffset: Int
```

The scroll offset of the anchor item. Scrolling forward is positive - i.e., the amount that the item is offset backwards.

Note that this property is observable and if you use it in the composable function it will be recomposed on every scroll causing potential performance issues.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#anchorItemIndex()` | for samples with the recommended usage patterns. |

### canScrollBackward

```
open val canScrollBackward: Boolean
```

### canScrollForward

```
open val canScrollForward: Boolean
```

### isScrollInProgress

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.5.0)

```
open val isScrollInProgress: Boolean
```

### lastScrolledBackward

```
open val lastScrolledBackward: Boolean
```

### lastScrolledForward

```
open val lastScrolledForward: Boolean
```

### layoutInfo

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.5.0)

```
val layoutInfo: TransformingLazyColumnLayoutInfo
```

The object of LazyColumnLayoutInfo calculated during the last layout pass. For example, you can use it to calculate what items are currently visible. Note that this property is observable and is updated after every scroll or remeasure. If you use it in the composable function it will be recomposed on every change causing potential performance issues including infinite recomposition loop. Therefore, avoid using it in the composition. If you want to run some side effects like sending an analytics event or updating a state based on this value consider using "snapshotFlow":

## Extension functions

### TransformingLazyColumnState.layoutItemInfoOf

Artifact: [androidx.wear.compose:compose-material3](https://developer.android.com/jetpack/androidx/releases/wear-compose) [View Source](https://cs.android.com/search?q=file:androidx/wear/compose/material3/lazy/TransformingLazyColumnFirstLayoutItemProvider.kt+function:layoutItemInfoOf)

```
fun TransformingLazyColumnState.layoutItemInfoOf(
    itemKey: Any,
    itemEdge: TransformingLazyColumnFirstLayoutItemProvider.ItemEdge
): TransformingLazyColumnFirstLayoutItemProvider.ItemInfo?
```

Returns the `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnFirstLayoutItemProvider.ItemInfo` for the visible item with the given `https://developer.android.com/reference/kotlin/androidx/wear/compose/material3/lazy/package-summary#(androidx.wear.compose.foundation.lazy.TransformingLazyColumnState).layoutItemInfoOf(kotlin.Any,androidx.wear.compose.foundation.lazy.TransformingLazyColumnFirstLayoutItemProvider.ItemEdge)`, aligned to the specified `https://developer.android.com/reference/kotlin/androidx/wear/compose/material3/lazy/package-summary#(androidx.wear.compose.foundation.lazy.TransformingLazyColumnState).layoutItemInfoOf(kotlin.Any,androidx.wear.compose.foundation.lazy.TransformingLazyColumnFirstLayoutItemProvider.ItemEdge)`. Returns null if the item is not currently visible on screen.

This helper is useful when building a custom `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnFirstLayoutItemProvider` that needs to track and stabilize the position of a specific key (e.g. an expanding item) during content size animations.

```kotlin
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.wear.compose.foundation.lazy.TransformingLazyColumn
import androidx.wear.compose.foundation.lazy.TransformingLazyColumnFirstLayoutItemProvider
import androidx.wear.compose.foundation.lazy.rememberTransformingLazyColumnState
import androidx.wear.compose.material3.AppScaffold
import androidx.wear.compose.material3.Card
import androidx.wear.compose.material3.CardDefaults
import androidx.wear.compose.material3.OutlinedCard
import androidx.wear.compose.material3.ScreenScaffold
import androidx.wear.compose.material3.SurfaceTransformation
import androidx.wear.compose.material3.Text
import androidx.wear.compose.material3.lazy.layoutItemInfoOf
import androidx.wear.compose.material3.lazy.rememberTransformationSpec
import androidx.wear.compose.material3.lazy.rememberTransformingLazyColumnFirstLayoutItemProvider
import androidx.wear.compose.material3.lazy.transformedHeight

val state = rememberTransformingLazyColumnState()
val transformationSpec = rememberTransformationSpec()

// This sample demonstrates how to use rememberTransformingLazyColumnFirstLayoutItemProvider
// to control the expansion direction of a dynamically resizing item. By using the voice input
// card's Bottom/End edge as the layout reference, the card predictably expands upwards.
// The constant key safely falls back to default layout behavior when scrolled off-screen.
val firstLayoutItemProvider = rememberTransformingLazyColumnFirstLayoutItemProvider {
    state.layoutItemInfoOf(
        itemKey = "voice_input",
        itemEdge = TransformingLazyColumnFirstLayoutItemProvider.ItemEdge.End,
    )
}

var isListening by remember { mutableStateOf(false) }
var lineCount by remember { mutableIntStateOf(0) }
// Simple loop simulating text lines arriving over time
LaunchedEffect(isListening) {
    if (isListening) {
        while (lineCount < 5) {
            delay(300)
            lineCount++
        }
        isListening = false
    }
}

AppScaffold {
    ScreenScaffold(state) { contentPadding ->
        TransformingLazyColumn(
            state = state,
            contentPadding = contentPadding,
            firstLayoutItemProvider = firstLayoutItemProvider,
        ) {
            items(count = 3, key = { "message_$it" }) { index ->
                Card(
                    onClick = {},
                    modifier =
                        Modifier.minimumVerticalContentPadding(
                                CardDefaults.minimumVerticalListContentPadding
                            )
                            .transformedHeight(this, transformationSpec)
                            .animateItem(placementSpec = null),
                    transformation = SurfaceTransformation(transformationSpec),
                ) {
                    Text("Previous message $index")
                }
            }

            item(key = "voice_input") {
                val voiceText = (1..lineCount).joinToString("\n") { "Voice Input line $it" }

                OutlinedCard(
                    onClick = {
                        if (lineCount >= 5) lineCount = 0
                        isListening = !isListening
                    },
                    modifier =
                        Modifier.minimumVerticalContentPadding(
                                CardDefaults.minimumVerticalListContentPadding
                            )
                            .transformedHeight(this, transformationSpec)
                            .animateItem(placementSpec = null),
                    transformation = SurfaceTransformation(transformationSpec),
                ) {
                    Text(text = voiceText.ifEmpty { "Tap to speak" })
                }
            }
        }
    }
}
```

| Parameters |
|---|---|
| `itemKey: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html` | The unique key of the item to search for. |
| `itemEdge: https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnFirstLayoutItemProvider.ItemEdge` | The `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnFirstLayoutItemProvider.ItemEdge` (Start or End) of the item to use for the layout reference. |

## Extension properties

### TransformingLazyColumnState.firstVisibleItemLayoutItemInfo

Artifact: [androidx.wear.compose:compose-material3](https://developer.android.com/jetpack/androidx/releases/wear-compose) [View Source](https://cs.android.com/search?q=file:androidx/wear/compose/material3/lazy/TransformingLazyColumnFirstLayoutItemProvider.kt+symbol:firstVisibleItemLayoutItemInfo) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.7.0)

```
val TransformingLazyColumnState.firstVisibleItemLayoutItemInfo: TransformingLazyColumnFirstLayoutItemProvider.ItemInfo?
```

Returns the `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnFirstLayoutItemProvider.ItemInfo` for the first visible item aligned to its `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnFirstLayoutItemProvider.ItemEdge#Start()` edge, or null if there are no visible items.

This extension is useful when building a custom `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnFirstLayoutItemProvider` that needs to ensure the first visible item maintains a static start edge during dynamic content updates (such as item additions, removals, or size changes), avoiding visual jumps in the viewport.

Since the first visible item changes rapidly during an active scroll, tracking it continuously does not provide a stable visual reference. When using this property with `https://developer.android.com/reference/kotlin/androidx/wear/compose/material3/lazy/rememberTransformingLazyColumnFirstLayoutItemProvider.composable#rememberTransformingLazyColumnFirstLayoutItemProvider(kotlin.Function0)`, it is highly recommended to yield to the default layout behavior by returning null when `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/lazy/TransformingLazyColumnState#isScrollInProgress()` is true. This allows the list to fall back to its default layout behavior, which accurately tracks the scroll gesture, while also avoiding unnecessary computational overhead.

```kotlin
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.wear.compose.foundation.lazy.TransformingLazyColumn
import androidx.wear.compose.foundation.lazy.TransformingLazyColumnFirstLayoutItemProvider
import androidx.wear.compose.foundation.lazy.itemsIndexed
import androidx.wear.compose.foundation.lazy.rememberTransformingLazyColumnState
import androidx.wear.compose.material3.AppScaffold
import androidx.wear.compose.material3.Button
import androidx.wear.compose.material3.Card
import androidx.wear.compose.material3.CardDefaults
import androidx.wear.compose.material3.CompactButton
import androidx.wear.compose.material3.ScreenScaffold
import androidx.wear.compose.material3.SurfaceTransformation
import androidx.wear.compose.material3.Text
import androidx.wear.compose.material3.lazy.firstVisibleItemLayoutItemInfo
import androidx.wear.compose.material3.lazy.rememberTransformationSpec
import androidx.wear.compose.material3.lazy.rememberTransformingLazyColumnFirstLayoutItemProvider
import androidx.wear.compose.material3.lazy.transformedHeight

val transformationSpec = rememberTransformationSpec()
val state = rememberTransformingLazyColumnState()
var elements by remember { mutableStateOf(listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) }
var nextElement by remember { mutableIntStateOf(10) }

fun addCardAfter(index: Int) {
    elements =
        elements.subList(0, index + 1) +
            listOf(nextElement++) +
            elements.subList(index + 1, elements.count())
}

fun removeCardAt(index: Int) {
    elements = elements.subList(0, index) + elements.subList(index + 1, elements.count())
}

// This sample demonstrates how to use rememberTransformingLazyColumnFirstVisibleItemProvider
// to maintain a stable viewport top when items are added or removed dynamically.
// It achieves this by using the first visible item as the layout reference.
AppScaffold {
    ScreenScaffold(state) { contentPadding ->
        TransformingLazyColumn(
            state = state,
            contentPadding = contentPadding,
            firstLayoutItemProvider =
                rememberTransformingLazyColumnFirstLayoutItemProvider {
                    if (state.isScrollInProgress) null else state.firstVisibleItemLayoutItemInfo
                },
        ) {
            itemsIndexed(elements, key = { _, key -> key }) { index, cardKey ->
                Card(
                    onClick = {},
                    modifier =
                        Modifier.minimumVerticalContentPadding(
                                CardDefaults.minimumVerticalListContentPadding
                            )
                            .transformedHeight(this, transformationSpec)
                            .animateItem(),
                    transformation = SurfaceTransformation(transformationSpec),
                ) {
                    Text("Card $cardKey")
                    Row {
                        Spacer(modifier = Modifier.weight(1f))
                        CompactButton(
                            onClick = { removeCardAt(index) },
                            enabled = elements.count() > 1,
                        ) {
                            Text("-")
                        }
                        CompactButton(onClick = { addCardAfter(index) }) { Text("+") }
                    }
                }
            }
        }
    }
}
```