Nthily
05/26/2024, 11:28 AMzIndexInOverlay = 1f
) with a topBar and LazyColumn inside the content where clicking on the image navigates to the detail page, but it doesn't seem to be working when I also set zIndexInOverlay = 1f
, it doesn't seem to work, it covers the topBar when the image returns from the detail page 🤔Nthily
05/26/2024, 11:29 AMSharedTransitionLayout {
val navController = rememberNavController()
val navBackStackEntry = navController.currentBackStackEntryAsState().value
val currentRoute = navBackStackEntry?.destination
Scaffold(
bottomBar = {
AnimatedVisibility (
visible = currentRoute?.hasRoute<Route.List>() == true,
enter = slideInVertically { it },
exit = slideOutVertically { it },
modifier = Modifier.renderInSharedTransitionScopeOverlay(
zIndexInOverlay = 1f,
)
) {
Box(modifier = Modifier
.fillMaxWidth()
.height(56.dp)
.background(Color.Gray))
}
}
) {
NavHost(
navController = navController,
startDestination = Route.List
) {
composable<Route.List> {
val scope = this
Column {
Box(
modifier = Modifier
.fillMaxWidth()
.height(82.dp)
.background(Color.Cyan)
.renderInSharedTransitionScopeOverlay(
zIndexInOverlay = 1f,
)
)
LazyColumn(
verticalArrangement = Arrangement.spacedBy(24.dp)
) {
items(50) {
Image(
painter = painterResource(id = <http://R.drawable.cat|R.drawable.cat>),
modifier = Modifier
.fillMaxWidth()
.height(120.dp)
.clickable {
navController.navigate(Route.Detail(it))
}
.sharedElement(
state = rememberSharedContentState(key = "cat $it"),
animatedVisibilityScope = scope
),
contentDescription = null,
contentScale = ContentScale.Crop
)
}
}
}
}
composable<Route.Detail> {
val id = it.toRoute<Route.Detail>().item
Image(
painter = painterResource(<http://R.drawable.cat|R.drawable.cat>),
contentDescription = null,
modifier = Modifier.fillMaxSize()
.sharedElement(
state = rememberSharedContentState(key = "cat $id"),
animatedVisibilityScope = this
)
)
}
}
}
}
Doris Liu
05/28/2024, 9:49 PMrenderInSharedTransitionScopeOverlay
before background
and other content that you intend to render in overlay.Nthily
05/29/2024, 2:01 AMrenderInSharedTransitionScopeOverlay
in front of the background, and it just disappears after the animation ends, and it looks like this 🤔Doris Liu
05/29/2024, 5:01 PMrenderInSharedTransitionScopeOverlay
and rendering shared elements in overlay ignores alpha change coming down from the layout tree. That's why we recommend doing Modifier.renderIn...Overlay(..).animateEnterExit(..)
. See: https://developer.android.com/develop/ui/compose/animation/shared-elements/customize#clip-overlaysNthily
05/31/2024, 8:07 AMNthily
05/31/2024, 8:13 AMDoris Liu
05/31/2024, 4:56 PMNthily
06/01/2024, 2:21 AM