We just launched Compose Examples featuring over 150+ components! Check it out →

HorizontalPagerScaffold

Android

Component in Wear Material 3 Compose

[HorizontalPagerScaffold] is one of the Wear Material3 scaffold components.

The scaffold components [AppScaffold] and [HorizontalPagerScaffold] lay out the structure of a Pager and coordinate transitions of the [HorizontalPageIndicator] and [TimeText] components.

[HorizontalPagerScaffold] displays the [HorizontalPageIndicator] at the center-end of the screen by default and coordinates showing/hiding [TimeText] and [HorizontalPageIndicator] according to whether the Pager is being paged, this is determined by the [PagerState].

Last updated:

Installation

dependencies {
   implementation("androidx.wear.compose:compose-material3:1.0.0-alpha27")
}

Overloads

@Composable
fun HorizontalPagerScaffold(
    pagerState: PagerState,
    modifier: Modifier = Modifier,
    pageIndicator: (@Composable BoxScope.() -> Unit)? = { HorizontalPageIndicator(pagerState) },
    pageIndicatorAnimationSpec: AnimationSpec<Float>? = null,
    rotaryScrollableBehavior: RotaryScrollableBehavior? = null,
    content: @Composable PagerScope.(page: Int) -> Unit,
)

Parameters

namedescription
pagerStateThe state of the pager controlling the page content.
modifierThe modifier to be applied to the scaffold.
pageIndicatorA composable function that defines the page indicator to be displayed. By default, it uses a [HorizontalPageIndicator].
pageIndicatorAnimationSpec- An optional parameter to set whether the page indicator should fade out when paging has finished. This is useful for when the underlying page content conflicts with the page indicator. By default this is null, so the page indicator will be visible at all times, setting this to [PagerScaffoldDefaults.FadeOutAnimation] ensures the indicator only shows during paging, and fades out when the Pager is idle.
rotaryScrollableBehaviorParameter for changing rotary behavior. By default rotary support is disabled for [HorizontalPagerScaffold]. It can be enabled by passing [RotaryScrollableDefaults.snapBehavior] with pagerState parameter.
contentA composable function that takes the current page index as a parameter and defines the content to be displayed on that page.

Code Example

HorizontalPagerScaffoldSample

@Composable
fun HorizontalPagerScaffoldSample() {
    AppScaffold {
        val pagerState = rememberPagerState(pageCount = { 10 })

        HorizontalPagerScaffold(pagerState = pagerState) { page ->
            ScreenScaffold {
                Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
                    Text("Page $page")
                }
            }
        }
    }
}
by @alexstyl