GlimmerHorizontalPager

Functions summary

Unit
@Composable
GlimmerHorizontalPager(
    state: GlimmerPagerState,
    modifier: Modifier,
    contentPadding: PaddingValues,
    beyondViewportPageCount: Int,
    pageSpacing: Dp,
    verticalAlignment: Alignment.Vertical,
    userScrollEnabled: Boolean,
    reverseLayout: Boolean,
    key: ((page: Int) -> Any)?,
    pageContent: @Composable GlimmerPagerScope.(page: Int) -> Unit
)

GlimmerHorizontalPager is a lazily-composed, horizontally scrollable layout that arranges its pages sequentially.

Functions

GlimmerHorizontalPager

@Composable
fun GlimmerHorizontalPager(
    state: GlimmerPagerState,
    modifier: Modifier = Modifier,
    contentPadding: PaddingValues = PaddingValues(0.dp),
    beyondViewportPageCount: Int = 0,
    pageSpacing: Dp = 0.dp,
    verticalAlignment: Alignment.Vertical = Alignment.Bottom,
    userScrollEnabled: Boolean = true,
    reverseLayout: Boolean = false,
    key: ((page: Int) -> Any)? = null,
    pageContent: @Composable GlimmerPagerScope.(page: Int) -> Unit
): Unit

GlimmerHorizontalPager is a lazily-composed, horizontally scrollable layout that arranges its pages sequentially. It is similar to androidx.compose.foundation.pager.HorizontalPager, but contains Glimmer behaviors and default values. Only one page is prominently displayed at a time, and the pager uses snap animations to ensure that a page always settles exactly into the viewport boundaries after a user's scrolling gesture ends.

Note: When displaying text within a GlimmerHorizontalPager, it is strongly recommended to set androidx.compose.ui.text.TextStyle.textMotion to androidx.compose.ui.text.style.TextMotion.Animated. This ensures smooth rendering during layout animations or scaling transitions, preventing pixel-snapping artifacts.

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.ui.Modifier
import androidx.xr.glimmer.Card
import androidx.xr.glimmer.Text
import androidx.xr.glimmer.pager.GlimmerHorizontalPager
import androidx.xr.glimmer.pager.GlimmerPagerState
import androidx.xr.glimmer.pager.rememberGlimmerPagerState

val pagerState = rememberGlimmerPagerState(pageCount = { 10 })

GlimmerHorizontalPager(state = pagerState, modifier = Modifier.fillMaxSize()) { page ->
    Card(modifier = Modifier.fillMaxWidth()) { Text(text = "Page: $page") }
}
Parameters
state: GlimmerPagerState

the state object to be used to control or observe the pager's state.

modifier: Modifier = Modifier

the modifier to apply to this 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.

beyondViewportPageCount: Int = 0

Pages to compose and layout before and after the list of visible pages. Note: Be aware that using a large value for beyondViewportPageCount 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. This does not include the pages automatically composed and laid out by the pre-fetcher in the direction of the scroll during scroll events.

pageSpacing: Dp = 0.dp

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

verticalAlignment: Alignment.Vertical = Alignment.Bottom

how pages are aligned vertically within the pager's viewport.

userScrollEnabled: Boolean = true

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

reverseLayout: Boolean = false

reverse the direction of scrolling and layout.

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

a stable and unique key representing the item. When specified, the scroll position will be maintained based on the key. If null, the position in the pager will represent the key.

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

a block that describes the content of a single page.