# rememberPagerState

Common/All

## Functions summary

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/rememberPagerState.composable#rememberPagerState(kotlin.Int,kotlin.Float,kotlin.Function0)( initialPage: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, initialPageOffsetFraction: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = -0.5, to = 0.5) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, pageCount: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Creates and remember a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState` to be used with a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/package-summary#Pager(androidx.compose.ui.Modifier,androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.gestures.Orientation,androidx.compose.foundation.gestures.TargetedFlingBehavior,kotlin.Boolean,androidx.compose.foundation.OverscrollEffect,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.foundation.pager.PageSize,androidx.compose.ui.input.nestedscroll.NestedScrollConnection,kotlin.Function1,androidx.compose.ui.Alignment.Horizontal,androidx.compose.ui.Alignment.Vertical,androidx.compose.foundation.gestures.snapping.SnapPosition,androidx.compose.foundation.gestures.BringIntoViewSpec,kotlin.Function2)` | Cmn |

## Functions

### rememberPagerState

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/pager/PagerState.kt+function:rememberPagerState) Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.5.0)

```
@Composable
fun rememberPagerState(
    initialPage: Int = 0,
    initialPageOffsetFraction: @FloatRange(from = -0.5, to = 0.5) Float = 0.0f,
    pageCount: () -> Int
): PagerState
```

Creates and remember a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState` to be used with a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/package-summary#Pager(androidx.compose.ui.Modifier,androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.gestures.Orientation,androidx.compose.foundation.gestures.TargetedFlingBehavior,kotlin.Boolean,androidx.compose.foundation.OverscrollEffect,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.foundation.pager.PageSize,androidx.compose.ui.input.nestedscroll.NestedScrollConnection,kotlin.Function1,androidx.compose.ui.Alignment.Horizontal,androidx.compose.ui.Alignment.Vertical,androidx.compose.foundation.gestures.snapping.SnapPosition,androidx.compose.foundation.gestures.BringIntoViewSpec,kotlin.Function2)`

Please refer to the sample to learn how to use this API.

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

// You can use PagerState to define an initial page
val state = rememberPagerState(initialPage = 5) { 10 }
HorizontalPager(modifier = Modifier.fillMaxSize(), state = state) { page ->
    Box(
        modifier =
            Modifier.padding(10.dp).background(Color.Blue).fillMaxWidth().aspectRatio(1f),
        contentAlignment = Alignment.Center,
    ) {
        Text(text = page.toString(), fontSize = 32.sp)
    }
}
```

| Parameters |
|---|---|
| `initialPage: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | The pager that should be shown first. |
| `initialPageOffsetFraction: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = -0.5, to = 0.5) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = 0.0f` | The offset of the initial page as a fraction of the page size. This should vary between -0.5 and 0.5 and indicates how to offset the initial page from the snapped position. |
| `pageCount: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The amount of pages this Pager will have. |