Skip to content

Instantly share code, notes, and snippets.

@hongbeomi
Created June 13, 2021 03:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hongbeomi/d9a1701ebd5fcbb8af709de6655e408d to your computer and use it in GitHub Desktop.
Save hongbeomi/d9a1701ebd5fcbb8af709de6655e408d to your computer and use it in GitHub Desktop.
@ExperimentalPagerApi
@Composable
fun MainPager(
list: List<HouseType>,
modifier: Modifier = Modifier,
onItemSelected: (HouseType) -> Unit
) {
val pagerState = rememberPagerState(pageCount = list.size)
HorizontalPager(
state = pagerState,
modifier = modifier,
itemSpacing = 16.dp
) { page ->
val logo = list[page].logo
val name = list[page].name
Column(
Modifier.clickable(
true,
onClick = { onItemSelected.invoke(list[page]) }
).graphicsLayer {
val pageOffset = calculateCurrentOffsetForPage(page).absoluteValue
lerp(
start = ScaleFactor(0.55f, 0.55f),
stop = ScaleFactor(1f, 1f),
fraction = 1f - pageOffset.coerceIn(0f, 1f)
).also { scale ->
scaleX = scale.scaleX
scaleY = scale.scaleY
}
alpha = lerp(
start = ScaleFactor(0.5f, 0.5f),
stop = ScaleFactor(1f, 1f),
fraction = 1f - pageOffset.coerceIn(0f, 1f)
).scaleX
},
horizontalAlignment = Alignment.CenterHorizontally
) {
Spacer(modifier = Modifier.height(16.dp))
Image(
painter = painterResource(id = logo),
contentDescription = "",
modifier = Modifier.size(320.dp),
contentScale = ContentScale.Fit
)
Spacer(modifier = Modifier.height(16.dp))
Text(
text = name,
fontSize = 24.sp,
fontWeight = FontWeight.Medium,
fontFamily = harryPotterFont,
color = colorResource(id = R.color.white),
modifier = Modifier.align(Alignment.CenterHorizontally)
)
Spacer(
modifier = Modifier.height(16.dp)
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment