Steffen Funke
03/28/2023, 2:24 PMAnimatedVisibility
when using it within a Column
that has a verticalArrangement
+ spacing
. The animation appears to “jump” when the visibility state changes. However, when there’s no spacing, the animation is smooth.
(Not asking for help, rather if a bug report should be filed or not).
Code and Video in 🧵Steffen Funke
03/28/2023, 2:25 PMSteffen Funke
03/28/2023, 2:25 PMfun main() = singleWindowApplication(state = WindowState(width = 400.dp, height = 800.dp)) {
AnimatedVisibilityJumpingDemo()
}
@Composable
fun AnimatedVisibilityJumpingDemo() {
var isVisible by remember { mutableStateOf(true) }
Column {
Button(onClick = { isVisible = !isVisible }) {
Text("Toggle red's visibility")
}
Row {
Column(
modifier = Modifier.weight(1f).padding(8.dp),
verticalArrangement = Arrangement.spacedBy(32.dp)
) {
Text("With Spacing between Boxes")
AnimatedVisibility(isVisible) {
Box(
modifier = Modifier
.background(Color.Red)
.fillMaxWidth()
.height(40.dp)
)
}
Box(
modifier = Modifier
.background(Color.Green)
.fillMaxWidth()
.height(40.dp)
)
}
Column(
modifier = Modifier.weight(1f).padding(8.dp),
) {
Text("No Spacing between Boxes")
AnimatedVisibility(isVisible) {
Box(
modifier = Modifier
.background(Color.Red)
.fillMaxWidth()
.height(40.dp)
)
}
Box(
modifier = Modifier
.background(Color.Green)
.fillMaxWidth()
.height(40.dp)
)
}
}
}
}
Steffen Funke
03/28/2023, 2:26 PMFilip Wiesner
03/28/2023, 2:32 PMSteffen Funke
03/28/2023, 2:37 PMverticalArrangement
and add manual Spacers
, or similar).
I have the gut feeling that the framework somehow “magically” should handle it. But I might be wrong.Stylianos Gakis
03/28/2023, 3:00 PMAnimatedVisibility
and what you don’t.
the framework somehow “magically” should handle itAnd about this, I am so glad it doesn’t. A lot of these “magic” things are good until you don’t want them and then you’re ducked.
Filip Wiesner
03/28/2023, 3:22 PMA lot of these “magic” things are good until you don’t want them and then you’re ducked.
I couldn't agree more. This is my exact problem with SwiftUI. The "modifier based API" of SwiftUI is so confusing and IMO really bad compared to Compose.
Alex Vanyo
03/28/2023, 5:03 PMSteffen Funke
03/28/2023, 5:29 PMshikasd
03/29/2023, 5:37 AMSteffen Funke
03/29/2023, 5:45 AMDoris Liu
03/31/2023, 12:00 AMAnimatedVisibility
's API contract is that it animates its child, it can't influence the spacing that its parent put between it and its siblings. Here I would consider it as WAI. I also agree that there should be an easy way to animate that spacing as well. What could be helpful here is a position animation for the sibling (i.e. the green bar), rather than relying on the derived position animation from AnimatedVisibility of the red bar.
The lookahead system we are building is designed to solve this type of use cases. From your use case, it seems like we could use a notion of disappearing
in lookahead pass so that it's excluded from the parent's (i.e. Column in this case) measure and place logic. That way the parent can skip the disappearing layout as well as the spacing when calculating final position.