Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@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