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-alpha34")
}
Overloads
@Composable
fun HorizontalPagerScaffold(
pagerState: PagerState,
modifier: Modifier = Modifier,
pageIndicator: (@Composable BoxScope.() -> Unit)? = { HorizontalPageIndicator(pagerState) },
pageIndicatorAnimationSpec: AnimationSpec<Float>? = null,
content: @Composable () -> Unit,
): Unit
Parameters
name | description |
---|---|
pagerState | The state of the pager controlling the page content. |
modifier | The modifier to be applied to the scaffold. |
pageIndicator | A 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. |
content | A composable function where a [HorizontalPager] can be added. |
Code Example
HorizontalPagerScaffoldSample
@Composable
fun HorizontalPagerScaffoldSample(navigateBack: () -> Unit) {
AppScaffold {
val pagerState = rememberPagerState(pageCount = { 10 })
HorizontalPagerScaffold(pagerState = pagerState) {
HorizontalPager(
state = pagerState,
flingBehavior =
PagerScaffoldDefaults.snapWithSpringFlingBehavior(state = pagerState),
rotaryScrollableBehavior = null,
) { page ->
AnimatedPage(page = page, pagerState = pagerState) {
ScreenScaffold {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
if (page == 0) {
Column {
Text("Page 0")
Spacer(modifier = Modifier.height(16.dp))
Button(onClick = navigateBack) { Text("Exit") }
}
} else {
Text("Page $page")
}
}
}
}
}
}
}
}