Skip to content

Instantly share code, notes, and snippets.

@fvilarino
Last active April 21, 2024 19:27
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 fvilarino/cb288c3b863db26ed7f464e86f9659b0 to your computer and use it in GitHub Desktop.
Save fvilarino/cb288c3b863db26ed7f464e86f9659b0 to your computer and use it in GitHub Desktop.
Shared Elem - Animated List
@Composable
// 1
fun SharedTransitionScope.ListScreen(
// 2
animatedVisibilityScope: AnimatedVisibilityScope,
onItemClick: (String) -> Unit,
modifier: Modifier = Modifier
) {
LazyColumn(
modifier = modifier,
verticalArrangement = Arrangement.spacedBy(8.dp),
contentPadding = PaddingValues(all = 16.dp),
) {
items(50) { item ->
val width = 340 + item * 20
val height = width * 4 / 3
val url = "https://loremflickr.com/$width/$height"
Row(
modifier = Modifier
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null
) {
onItemClick(url)
}
.fillMaxWidth(),
) {
AsyncImage(
model = url,
modifier = Modifier
.size(100.dp)
// 3
.sharedElement(
state = rememberSharedContentState(
key = "image-$url"
),
animatedVisibilityScope = animatedVisibilityScope,
),
contentScale = ContentScale.Crop,
contentDescription = null
)
Spacer(Modifier.size(16.dp))
LoremIpsum(
modifier = Modifier.fillMaxWidth(),
maxLines = 3,
)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment