Created
August 26, 2023 07:23
-
-
Save gold24park/2f390ed1befb877c84326dba0391208e to your computer and use it in GitHub Desktop.
arc_animation_pager1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@OptIn(ExperimentalFoundationApi::class) | |
@Composable | |
fun TestScreen() { | |
val pageCount = 3 | |
val rotateDegree = 15F | |
val pagerState = rememberPagerState() | |
HorizontalPager( | |
modifier = Modifier.fillMaxSize().background(Color.LightGray), | |
pageCount = pageCount, | |
state = pagerState, | |
) { page -> | |
Box( | |
modifier = Modifier.fillMaxSize() | |
) { | |
Card( | |
page = page, | |
modifier = Modifier | |
.align(Alignment.Center) | |
.height(300.dp) | |
.graphicsLayer { | |
val pageOffset = pagerState.offsetForPage(page) | |
rotationZ = -rotateDegree * pageOffset | |
} | |
) | |
} | |
} | |
} | |
@Composable | |
fun Card(page: Int, modifier: Modifier = Modifier) { | |
Surface( | |
modifier = modifier, | |
color = Color.DarkGray, | |
shape = RoundedCornerShape(16.dp) | |
) { | |
Box(modifier = Modifier.fillMaxSize()) { | |
Text( | |
text = "Page $page", | |
modifier = Modifier.align(Alignment.Center), | |
style = MaterialTheme.typography.headlineLarge, | |
color = Color.White | |
) | |
} | |
} | |
} | |
@OptIn(ExperimentalFoundationApi::class) | |
fun PagerState.offsetForPage(page: Int) = (currentPage - page) + currentPageOffsetFraction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment