Skip to content

Instantly share code, notes, and snippets.

@aqua30
Created June 12, 2022 20:16
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 aqua30/54de8136cb56d711bc10c16a72125458 to your computer and use it in GitHub Desktop.
Save aqua30/54de8136cb56d711bc10c16a72125458 to your computer and use it in GitHub Desktop.
@Composable
fun ImageParallaxScroll() {
val scrollState = rememberScrollState()
Column(
modifier = Modifier
.fillMaxWidth()
.verticalScroll(scrollState),
) {
Box(
modifier = Modifier
.fillMaxWidth()
.height(500.dp)
.background(Color.White)
.graphicsLayer {
alpha = 1f - ((scrollState.value.toFloat() / scrollState.maxValue) * 1.5f)
translationY = 0.5f * scrollState.value
},
contentAlignment = Alignment.Center
) {
Image(
painterResource(id = R.drawable.ic_tiger),
contentDescription = "tiger parallax",
contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize()
)
}
Text(
text = stringResource(R.string.dummy_text),
modifier = Modifier.background(
Color.White
),
style = TextStyle(
fontSize = 24.sp
)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment