{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

androidx.compose.foundation.pager

Interfaces

PageSize

This is used to determine how Pages are laid out in Pager.

Cmn
PagerScope

Receiver scope for Pager.

Cmn
PagerSnapDistance

PagerSnapDistance defines the way the Pager will treat the distance between the current page and the page where it will settle.

Cmn

Classes

PageSize.Fixed

Multiple pages in a viewport

Cmn
PagerState

The state that can be used to control VerticalPager and HorizontalPager

Cmn

Objects

PageSize.Fill

Pages take up the whole Pager size.

Cmn
PagerDefaults

Contains the default values used by Pager.

Cmn

Top-level functions summary

Unit
@Composable
@ExperimentalFoundationApi
HorizontalPager(
    state: PagerState,
    modifier: Modifier,
    contentPadding: PaddingValues,
    pageSize: PageSize,
    beyondBoundsPageCount: Int,
    pageSpacing: Dp,
    verticalAlignment: Alignment.Vertical,
    flingBehavior: SnapFlingBehavior,
    userScrollEnabled: Boolean,
    reverseLayout: Boolean,
    key: ((index: Int) -> Any)?,
    pageNestedScrollConnection: NestedScrollConnection,
    pageContent: @Composable PagerScope.(page: Int) -> Unit
)

A Pager that scrolls horizontally.

Cmn
Unit
@Composable
@ExperimentalFoundationApi
HorizontalPager(
    pageCount: Int,
    modifier: Modifier,
    state: PagerState,
    contentPadding: PaddingValues,
    pageSize: PageSize,
    beyondBoundsPageCount: Int,
    pageSpacing: Dp,
    verticalAlignment: Alignment.Vertical,
    flingBehavior: SnapFlingBehavior,
    userScrollEnabled: Boolean,
    reverseLayout: Boolean,
    key: ((index: Int) -> Any)?,
    pageNestedScrollConnection: NestedScrollConnection,
    pageContent: @Composable PagerScope.(page: Int) -> Unit
)

This function is deprecated. Please use the overload without pageCount. pageCount should be provided through PagerState.

Cmn
Unit
@Composable
@ExperimentalFoundationApi
VerticalPager(
    state: PagerState,
    modifier: Modifier,
    contentPadding: PaddingValues,
    pageSize: PageSize,
    beyondBoundsPageCount: Int,
    pageSpacing: Dp,
    horizontalAlignment: Alignment.Horizontal,
    flingBehavior: SnapFlingBehavior,
    userScrollEnabled: Boolean,
    reverseLayout: Boolean,
    key: ((index: Int) -> Any)?,
    pageNestedScrollConnection: NestedScrollConnection,
    pageContent: @Composable PagerScope.(page: Int) -> Unit
)

A Pager that scrolls vertically.

Cmn
Unit
@Composable
@ExperimentalFoundationApi
VerticalPager(
    pageCount: Int,
    modifier: Modifier,
    state: PagerState,
    contentPadding: PaddingValues,
    pageSize: PageSize,
    beyondBoundsPageCount: Int,
    pageSpacing: Dp,
    horizontalAlignment: Alignment.Horizontal,
    flingBehavior: SnapFlingBehavior,
    userScrollEnabled: Boolean,
    reverseLayout: Boolean,
    key: ((index: Int) -> Any)?,
    pageNestedScrollConnection: NestedScrollConnection,
    pageContent: @Composable PagerScope.(page: Int) -> Unit
)

This function is deprecated. Please use the overload without pageCount. pageCount should be provided through PagerState.

Cmn
PagerState
@ExperimentalFoundationApi
@Composable
rememberPagerState(initialPage: Int, initialPageOffsetFraction: Float)

This function is deprecated. Please use the overload where you can provide a source of truth for the pageCount.

Cmn
PagerState
@ExperimentalFoundationApi
@Composable
rememberPagerState(
    initialPage: Int,
    initialPageOffsetFraction: Float,
    pageCount: () -> Int
)

Creates and remember a PagerState to be used with a Pager

Cmn

Top-level functions

HorizontalPager

@Composable
@ExperimentalFoundationApi
fun HorizontalPager(
    state: PagerState,
    modifier: Modifier = Modifier,
    contentPadding: PaddingValues = PaddingValues(0.dp),
    pageSize: PageSize = PageSize.Fill,
    beyondBoundsPageCount: Int = 0,
    pageSpacing: Dp = 0.dp,
    verticalAlignment: Alignment.Vertical = Alignment.CenterVertically,
    flingBehavior: SnapFlingBehavior = PagerDefaults.flingBehavior(state = state),
    userScrollEnabled: Boolean = true,
    reverseLayout: Boolean = false,
    key: ((index: Int) -> Any)? = null,
    pageNestedScrollConnection: NestedScrollConnection = PagerDefaults.pageNestedScrollConnection( Orientation.Horizontal ),
    pageContent: @Composable PagerScope.(page: Int) -> Unit
): Unit

A Pager that scrolls horizontally. Pages are lazily placed in accordance to the available viewport size. By definition, pages in a Pager have the same size, defined by pageSize and use a snap animation (provided by flingBehavior to scroll pages into a specific position). You can use beyondBoundsPageCount to place more pages before and after the visible pages.

If you need snapping with pages of different size, you can use a SnapFlingBehavior with a SnapLayoutInfoProvider adapted to a LazyList.

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.rememberPagerState
import androidx.compose.material.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

// Creates a 1-pager/viewport horizontal pager with single page snapping
val state = rememberPagerState { 10 }
HorizontalPager(
    state = state,
    modifier = Modifier.fillMaxSize(),
) { page ->
    Box(
        modifier = Modifier
            .padding(10.dp)
            .background(Color.Blue)
            .fillMaxWidth()
            .aspectRatio(1f),
        contentAlignment = Alignment.Center
    ) {
        Text(text = page.toString(), fontSize = 32.sp)
    }
}
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp

// This is a sample using NestedScroll and Pager.
// We use the toolbar offset changing example from
// androidx.compose.ui.samples.NestedScrollConnectionSample

val pagerState = rememberPagerState { 10 }

val toolbarHeight = 48.dp
val toolbarHeightPx = with(LocalDensity.current) { toolbarHeight.roundToPx().toFloat() }
val toolbarOffsetHeightPx = remember { mutableStateOf(0f) }
val nestedScrollConnection = remember {
    object : NestedScrollConnection {
        override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
            val delta = available.y
            val newOffset = toolbarOffsetHeightPx.value + delta
            toolbarOffsetHeightPx.value = newOffset.coerceIn(-toolbarHeightPx, 0f)
            return Offset.Zero
        }
    }
}

Box(
    modifier = Modifier
        .fillMaxSize()
        .nestedScroll(nestedScrollConnection)
) {
    TopAppBar(
        modifier = Modifier
            .height(toolbarHeight)
            .offset { IntOffset(x = 0, y = toolbarOffsetHeightPx.value.roundToInt()) },
        title = { Text("Toolbar offset is ${toolbarOffsetHeightPx.value}") }
    )

    val paddingOffset =
        toolbarHeight + with(LocalDensity.current) { toolbarOffsetHeightPx.value.toDp() }

    HorizontalPager(
        modifier = Modifier.fillMaxSize(),
        state = pagerState,
        contentPadding = PaddingValues(top = paddingOffset)
    ) {
        Column(
            modifier = Modifier
                .fillMaxWidth()
                .verticalScroll(rememberScrollState())
        ) {
            repeat(20) {
                Box(
                    modifier = Modifier
                        .fillMaxWidth()
                        .height(64.dp)
                        .padding(4.dp)
                        .background(if (it % 2 == 0) Color.Black else Color.Yellow),
                    contentAlignment = Alignment.Center
                ) {
                    Text(
                        text = it.toString(),
                        color = if (it % 2 != 0) Color.Black else Color.Yellow
                    )
                }
            }
        }
    }
}
Parameters
state: PagerState

The state to control this pager

modifier: Modifier = Modifier

A modifier instance to be applied to this Pager outer layout

contentPadding: PaddingValues = PaddingValues(0.dp)

a padding around the whole content. This will add padding for the content after it has been clipped, which is not possible via modifier param. You can use it to add a padding before the first page or after the last one. Use pageSpacing to add spacing between the pages.

pageSize: PageSize = PageSize.Fill

Use this to change how the pages will look like inside this pager.

beyondBoundsPageCount: Int = 0

Pages to load before and after the list of visible pages. Note: Be aware that using a large value for beyondBoundsPageCount will cause a lot of pages to be composed, measured and placed which will defeat the purpose of using lazy loading. This should be used as an optimization to pre-load a couple of pages before and after the visible ones.

pageSpacing: Dp = 0.dp

The amount of space to be used to separate the pages in this Pager

verticalAlignment: Alignment.Vertical = Alignment.CenterVertically

How pages are aligned vertically in this Pager.

flingBehavior: SnapFlingBehavior = PagerDefaults.flingBehavior(state = state)

The FlingBehavior to be used for post scroll gestures.

userScrollEnabled: Boolean = true

whether the scrolling via the user gestures or accessibility actions is allowed. You can still scroll programmatically using PagerState.scroll even when it is disabled.

reverseLayout: Boolean = false

reverse the direction of scrolling and layout.

key: ((index: Int) -> Any)? = null

a stable and unique key representing the item. When you specify the key the scroll position will be maintained based on the key, which means if you add/remove items before the current visible item the item with the given key will be kept as the first visible one.

pageNestedScrollConnection: NestedScrollConnection = PagerDefaults.pageNestedScrollConnection( Orientation.Horizontal )

A NestedScrollConnection that dictates how this Pager behaves with nested lists. The default behavior will see Pager to consume all nested deltas.

pageContent: @Composable PagerScope.(page: Int) -> Unit

This Pager's page Composable.

See also
SnapLayoutInfoProvider

for the implementation of a SnapLayoutInfoProvider that uses androidx.compose.foundation.lazy.LazyListState.

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

HorizontalPager

@Composable
@ExperimentalFoundationApi
fun HorizontalPager(
    pageCount: Int,
    modifier: Modifier = Modifier,
    state: PagerState = rememberPagerState { pageCount },
    contentPadding: PaddingValues = PaddingValues(0.dp),
    pageSize: PageSize = PageSize.Fill,
    beyondBoundsPageCount: Int = 0,
    pageSpacing: Dp = 0.dp,
    verticalAlignment: Alignment.Vertical = Alignment.CenterVertically,
    flingBehavior: SnapFlingBehavior = PagerDefaults.flingBehavior(state = state),
    userScrollEnabled: Boolean = true,
    reverseLayout: Boolean = false,
    key: ((index: Int) -> Any)? = null,
    pageNestedScrollConnection: NestedScrollConnection = PagerDefaults.pageNestedScrollConnection( Orientation.Horizontal ),
    pageContent: @Composable PagerScope.(page: Int) -> Unit
): Unit

A Pager that scrolls horizontally. Pages are lazily placed in accordance to the available viewport size. By definition, pages in a Pager have the same size, defined by pageSize and use a snap animation (provided by flingBehavior to scroll pages into a specific position). You can use beyondBoundsPageCount to place more pages before and after the visible pages.

If you need snapping with pages of different size, you can use a SnapFlingBehavior with a SnapLayoutInfoProvider adapted to a LazyList.

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.rememberPagerState
import androidx.compose.material.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

// Creates a 1-pager/viewport horizontal pager with single page snapping
val state = rememberPagerState { 10 }
HorizontalPager(
    state = state,
    modifier = Modifier.fillMaxSize(),
) { page ->
    Box(
        modifier = Modifier
            .padding(10.dp)
            .background(Color.Blue)
            .fillMaxWidth()
            .aspectRatio(1f),
        contentAlignment = Alignment.Center
    ) {
        Text(text = page.toString(), fontSize = 32.sp)
    }
}
Parameters
pageCount: Int

The number of pages this Pager will contain

modifier: Modifier = Modifier

A modifier instance to be applied to this Pager outer layout

state: PagerState = rememberPagerState { pageCount }

The state to control this pager

contentPadding: PaddingValues = PaddingValues(0.dp)

a padding around the whole content. This will add padding for the content after it has been clipped, which is not possible via modifier param. You can use it to add a padding before the first page or after the last one. Use pageSpacing to add spacing between the pages.

pageSize: PageSize = PageSize.Fill

Use this to change how the pages will look like inside this pager.

beyondBoundsPageCount: Int = 0

Pages to load before and after the list of visible pages. Note: Be aware that using a large value for beyondBoundsPageCount will cause a lot of pages to be composed, measured and placed which will defeat the purpose of using lazy loading. This should be used as an optimization to pre-load a couple of pages before and after the visible ones.

pageSpacing: Dp = 0.dp

The amount of space to be used to separate the pages in this Pager

verticalAlignment: Alignment.Vertical = Alignment.CenterVertically

How pages are aligned vertically in this Pager.

flingBehavior: SnapFlingBehavior = PagerDefaults.flingBehavior(state = state)

The FlingBehavior to be used for post scroll gestures.

userScrollEnabled: Boolean = true

whether the scrolling via the user gestures or accessibility actions is allowed. You can still scroll programmatically using PagerState.scroll even when it is disabled.

reverseLayout: Boolean = false

reverse the direction of scrolling and layout.

key: ((index: Int) -> Any)? = null

a stable and unique key representing the page. When you specify the key the scroll position will be maintained based on the key, which means if you add/remove pages before the current visible page the page with the given key will be kept as the first visible one.

pageNestedScrollConnection: NestedScrollConnection = PagerDefaults.pageNestedScrollConnection( Orientation.Horizontal )

A NestedScrollConnection that dictates how this Pager behaves with nested lists. The default behavior will see Pager to consume all nested deltas.

pageContent: @Composable PagerScope.(page: Int) -> Unit

This Pager's page Composable.

See also
SnapLayoutInfoProvider

for the implementation of a SnapLayoutInfoProvider that uses androidx.compose.foundation.lazy.LazyListState.

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

VerticalPager

@Composable
@ExperimentalFoundationApi
fun VerticalPager(
    state: PagerState,
    modifier: Modifier = Modifier,
    contentPadding: PaddingValues = PaddingValues(0.dp),
    pageSize: PageSize = PageSize.Fill,
    beyondBoundsPageCount: Int = 0,
    pageSpacing: Dp = 0.dp,
    horizontalAlignment: Alignment.Horizontal = Alignment.CenterHorizontally,
    flingBehavior: SnapFlingBehavior = PagerDefaults.flingBehavior(state = state),
    userScrollEnabled: Boolean = true,
    reverseLayout: Boolean = false,
    key: ((index: Int) -> Any)? = null,
    pageNestedScrollConnection: NestedScrollConnection = PagerDefaults.pageNestedScrollConnection( Orientation.Vertical ),
    pageContent: @Composable PagerScope.(page: Int) -> Unit
): Unit

A Pager that scrolls vertically. Pages are lazily placed in accordance to the available viewport size. By definition, pages in a Pager have the same size, defined by pageSize and use a snap animation (provided by flingBehavior to scroll pages into a specific position). You can use beyondBoundsPageCount to place more pages before and after the visible pages.

If you need snapping with pages of different size, you can use a SnapFlingBehavior with a SnapLayoutInfoProvider adapted to a LazyList.

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.VerticalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material.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

// Creates a 1-pager/viewport vertical pager with single page snapping
val state = rememberPagerState { 10 }
VerticalPager(
    state = state,
    modifier = Modifier.fillMaxSize()
) { page ->
    Box(
        modifier = Modifier
            .padding(10.dp)
            .background(Color.Blue)
            .fillMaxWidth()
            .aspectRatio(1f),
        contentAlignment = Alignment.Center
    ) {
        Text(text = page.toString(), fontSize = 32.sp)
    }
}
Parameters
state: PagerState

The state to control this pager

modifier: Modifier = Modifier

A modifier instance to be apply to this Pager outer layout

contentPadding: PaddingValues = PaddingValues(0.dp)

a padding around the whole content. This will add padding for the content after it has been clipped, which is not possible via modifier param. You can use it to add a padding before the first page or after the last one. Use pageSpacing to add spacing between the pages.

pageSize: PageSize = PageSize.Fill

Use this to change how the pages will look like inside this pager.

beyondBoundsPageCount: Int = 0

Pages to load before and after the list of visible pages. Note: Be aware that using a large value for beyondBoundsPageCount will cause a lot of pages to be composed, measured and placed which will defeat the purpose of using lazy loading. This should be used as an optimization to pre-load a couple of pages before and after the visible ones.

pageSpacing: Dp = 0.dp

The amount of space to be used to separate the pages in this Pager

horizontalAlignment: Alignment.Horizontal = Alignment.CenterHorizontally

How pages are aligned horizontally in this Pager.

flingBehavior: SnapFlingBehavior = PagerDefaults.flingBehavior(state = state)

The FlingBehavior to be used for post scroll gestures.

userScrollEnabled: Boolean = true

whether the scrolling via the user gestures or accessibility actions is allowed. You can still scroll programmatically using PagerState.scroll even when it is disabled.

reverseLayout: Boolean = false

reverse the direction of scrolling and layout.

key: ((index: Int) -> Any)? = null

a stable and unique key representing the item. When you specify the key the scroll position will be maintained based on the key, which means if you add/remove items before the current visible item the item with the given key will be kept as the first visible one.

pageNestedScrollConnection: NestedScrollConnection = PagerDefaults.pageNestedScrollConnection( Orientation.Vertical )

A NestedScrollConnection that dictates how this Pager behaves with nested lists. The default behavior will see Pager to consume all nested deltas.

pageContent: @Composable PagerScope.(page: Int) -> Unit

This Pager's page Composable.

See also
SnapLayoutInfoProvider

for the implementation of a SnapLayoutInfoProvider that uses androidx.compose.foundation.lazy.LazyListState.

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

VerticalPager

@Composable
@ExperimentalFoundationApi
fun VerticalPager(
    pageCount: Int,
    modifier: Modifier = Modifier,
    state: PagerState = rememberPagerState { pageCount },
    contentPadding: PaddingValues = PaddingValues(0.dp),
    pageSize: PageSize = PageSize.Fill,
    beyondBoundsPageCount: Int = 0,
    pageSpacing: Dp = 0.dp,
    horizontalAlignment: Alignment.Horizontal = Alignment.CenterHorizontally,
    flingBehavior: SnapFlingBehavior = PagerDefaults.flingBehavior(state = state),
    userScrollEnabled: Boolean = true,
    reverseLayout: Boolean = false,
    key: ((index: Int) -> Any)? = null,
    pageNestedScrollConnection: NestedScrollConnection = PagerDefaults.pageNestedScrollConnection( Orientation.Vertical ),
    pageContent: @Composable PagerScope.(page: Int) -> Unit
): Unit

A Pager that scrolls vertically. Pages are lazily placed in accordance to the available viewport size. By definition, pages in a Pager have the same size, defined by pageSize and use a snap animation (provided by flingBehavior to scroll pages into a specific position). You can use beyondBoundsPageCount to place more pages before and after the visible pages.

If you need snapping with pages of different size, you can use a SnapFlingBehavior with a SnapLayoutInfoProvider adapted to a LazyList.

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.VerticalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material.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

// Creates a 1-pager/viewport vertical pager with single page snapping
val state = rememberPagerState { 10 }
VerticalPager(
    state = state,
    modifier = Modifier.fillMaxSize()
) { page ->
    Box(
        modifier = Modifier
            .padding(10.dp)
            .background(Color.Blue)
            .fillMaxWidth()
            .aspectRatio(1f),
        contentAlignment = Alignment.Center
    ) {
        Text(text = page.toString(), fontSize = 32.sp)
    }
}
Parameters
pageCount: Int

The number of pages this Pager will contain

modifier: Modifier = Modifier

A modifier instance to be apply to this Pager outer layout

state: PagerState = rememberPagerState { pageCount }

The state to control this pager

contentPadding: PaddingValues = PaddingValues(0.dp)

a padding around the whole content. This will add padding for the content after it has been clipped, which is not possible via modifier param. You can use it to add a padding before the first page or after the last one. Use pageSpacing to add spacing between the pages.

pageSize: PageSize = PageSize.Fill

Use this to change how the pages will look like inside this pager.

beyondBoundsPageCount: Int = 0

Pages to load before and after the list of visible pages. Note: Be aware that using a large value for beyondBoundsPageCount will cause a lot of pages to be composed, measured and placed which will defeat the purpose of using lazy loading. This should be used as an optimization to pre-load a couple of pages before and after the visible ones.

pageSpacing: Dp = 0.dp

The amount of space to be used to separate the pages in this Pager

horizontalAlignment: Alignment.Horizontal = Alignment.CenterHorizontally

How pages are aligned horizontally in this Pager.

flingBehavior: SnapFlingBehavior = PagerDefaults.flingBehavior(state = state)

The FlingBehavior to be used for post scroll gestures.

userScrollEnabled: Boolean = true

whether the scrolling via the user gestures or accessibility actions is allowed. You can still scroll programmatically using PagerState.scroll even when it is disabled.

reverseLayout: Boolean = false

reverse the direction of scrolling and layout.

key: ((index: Int) -> Any)? = null

a stable and unique key representing the page. When you specify the key the scroll position will be maintained based on the key, which means if you add/remove pages before the current visible page the page with the given key will be kept as the first visible one.

pageNestedScrollConnection: NestedScrollConnection = PagerDefaults.pageNestedScrollConnection( Orientation.Vertical )

A NestedScrollConnection that dictates how this Pager behaves with nested lists. The default behavior will see Pager to consume all nested deltas.

pageContent: @Composable PagerScope.(page: Int) -> Unit

This Pager's page Composable.

See also
SnapLayoutInfoProvider

for the implementation of a SnapLayoutInfoProvider that uses androidx.compose.foundation.lazy.LazyListState.

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

rememberPagerState

@ExperimentalFoundationApi
@Composable
fun rememberPagerState(
    initialPage: Int = 0,
    initialPageOffsetFraction: Float = 0.0f
): PagerState

Creates and remember a PagerState to be used with a Pager

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

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.rememberPagerState
import androidx.compose.material.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: Int = 0

The pager that should be shown first.

initialPageOffsetFraction: Float = 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.

rememberPagerState

@ExperimentalFoundationApi
@Composable
fun rememberPagerState(
    initialPage: Int = 0,
    initialPageOffsetFraction: Float = 0.0f,
    pageCount: () -> Int
): PagerState

Creates and remember a PagerState to be used with a Pager

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

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.rememberPagerState
import androidx.compose.material.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: Int = 0

The pager that should be shown first.

initialPageOffsetFraction: Float = 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: () -> Int

The amount of pages this Pager will have.