Skip to content

Commit af17252

Browse files
Fix pager snippets (#160)
* Update PagerSnippets.kt rectified error 1. Modifer.align(Alignment.BottomCenter) is replaced by verticalArrangement property which is no more working 2. wrong value 10 is replaced by 4 for pageCount 3. made text more visible by putting it inside a box * fix pager snippets --------- Co-authored-by: Karthi Keyan <[email protected]>
1 parent a54690d commit af17252

File tree

1 file changed

+9
-10
lines changed
  • compose/snippets/src/main/java/com/example/compose/snippets/layouts

1 file changed

+9
-10
lines changed

compose/snippets/src/main/java/com/example/compose/snippets/layouts/PagerSnippets.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import androidx.compose.foundation.layout.height
3636
import androidx.compose.foundation.layout.padding
3737
import androidx.compose.foundation.layout.size
3838
import androidx.compose.foundation.layout.sizeIn
39+
import androidx.compose.foundation.layout.wrapContentHeight
3940
import androidx.compose.foundation.layout.wrapContentSize
4041
import androidx.compose.foundation.pager.HorizontalPager
4142
import androidx.compose.foundation.pager.PageSize
@@ -361,38 +362,36 @@ fun PagerWithTabs() {
361362
@Preview
362363
@Composable
363364
fun PagerIndicator() {
364-
Box {
365+
Box(modifier = Modifier.fillMaxSize()) {
365366
// [START android_compose_pager_indicator]
366-
val pageCount = 10
367367
val pagerState = rememberPagerState(pageCount = {
368368
4
369369
})
370370
HorizontalPager(
371-
state = pagerState
371+
state = pagerState,
372+
modifier = Modifier.fillMaxSize()
372373
) { page ->
373374
// Our page content
374375
Text(
375376
text = "Page: $page",
376-
modifier = Modifier
377-
.fillMaxSize()
378377
)
379378
}
380379
Row(
381380
Modifier
382-
.height(50.dp)
381+
.wrapContentHeight()
383382
.fillMaxWidth()
384-
.align(Alignment.BottomCenter),
383+
.align(Alignment.BottomCenter)
384+
.padding(bottom = 8.dp),
385385
horizontalArrangement = Arrangement.Center
386386
) {
387-
repeat(pageCount) { iteration ->
387+
repeat(pagerState.pageCount) { iteration ->
388388
val color = if (pagerState.currentPage == iteration) Color.DarkGray else Color.LightGray
389389
Box(
390390
modifier = Modifier
391391
.padding(2.dp)
392392
.clip(CircleShape)
393393
.background(color)
394-
.size(20.dp)
395-
394+
.size(16.dp)
396395
)
397396
}
398397
}

0 commit comments

Comments
 (0)