Nino
05/08/2026, 4:10 PMAnimatedVisibility is not an option, this is a very simplified example, I need to switch between multiple UIs that may or may not have similar parts.
Thanks!Nino
05/08/2026, 4:10 PMColumn(
modifier = modifier.padding(16.dp),
) {
var shouldDisplayAction by remember { mutableStateOf(false) }
Crossfade(
modifier = Modifier.fillMaxWidth(),
targetState = shouldDisplayAction,
animationSpec = tween(easing = LinearEasing)
) { shouldDisplayAction ->
Row {
Text(
modifier = Modifier.weight(1F),
text = "Hello Compose!",
fontSize = 30.sp,
)
if (shouldDisplayAction) {
Text(
text = "MyAction",
fontSize = 16.sp,
)
}
}
}
Spacer(modifier = Modifier.height(16.dp))
Button(
modifier = Modifier.align(Alignment.CenterHorizontally),
onClick = { shouldDisplayAction = !shouldDisplayAction },
) {
Text("Click me!")
}
}romainguy
05/08/2026, 4:23 PMStylianos Gakis
05/08/2026, 4:23 PMStylianos Gakis
05/08/2026, 4:23 PMNino
05/08/2026, 4:28 PMStylianos Gakis
05/08/2026, 4:29 PMNino
05/08/2026, 4:30 PMRun the crossfade only on the part which changes, or make it an AnimatedContent block and make the persistent part of the UI be a shared elementUnfortunately impossible, every part of the UI can appear or disappear in some cases, but most of the transitions are happening between those "identical overlapping parts" that makes a very bad UX 😞
Stylianos Gakis
05/08/2026, 4:32 PMNino
05/08/2026, 4:48 PMColumn(
modifier = modifier.padding(16.dp),
) {
var alpha by remember { mutableFloatStateOf(0F) }
Box(
modifier = Modifier.fillMaxWidth(),
) {
Text(
modifier = Modifier.graphicsLayer {
this.alpha = alpha
},
text = "Hello Compose!",
fontSize = 30.sp,
)
Text(
modifier = Modifier.graphicsLayer {
this.alpha = 1 - alpha
},
text = "Hello Compose!",
fontSize = 30.sp,
)
}
Spacer(modifier = Modifier.height(16.dp))
Slider(
value = alpha,
onValueChange = { alpha = it }
)
Text(text = alpha.toString())
}seb
05/08/2026, 4:52 PMseb
05/08/2026, 4:53 PMNino
05/08/2026, 4:54 PManimationSpec = tween(easing = LinearEasing) for the Crossfade, isn't it enought?
And here's the result with the code above, it looks like alpha isn't additive on those superimposed pixels for some reasonseb
05/08/2026, 4:56 PMNino
05/08/2026, 4:57 PMseb
05/08/2026, 4:57 PMFedor Sorokin
05/08/2026, 6:16 PMFedor Sorokin
05/08/2026, 6:17 PMromainguy
05/08/2026, 6:49 PMromainguy
05/08/2026, 6:49 PMromainguy
05/08/2026, 6:50 PMromainguy
05/08/2026, 6:51 PMseb
05/08/2026, 6:51 PMromainguy
05/08/2026, 6:51 PMromainguy
05/08/2026, 6:52 PM