Kevin Worth
02/20/2025, 4:15 PMLazyColumn
where several items start GONE
VISIBLE
Kevin Worth
02/20/2025, 4:23 PMKevin Worth
02/20/2025, 4:28 PMKevin Worth
02/21/2025, 4:09 PMSkaldebane
02/21/2025, 4:10 PMGONE
and VISIBLE
to describe composable visibility is kinda trippy , I thought you're talking about View interop 😅Kevin Worth
02/21/2025, 4:11 PMSkaldebane
02/21/2025, 4:12 PMKevin Worth
02/21/2025, 4:15 PMSkaldebane
02/21/2025, 4:19 PMjolo
02/21/2025, 5:03 PMKevin Worth
02/21/2025, 9:36 PMKevin Worth
02/24/2025, 11:27 PMTgo1014
02/25/2025, 8:53 AMDoris Liu
03/07/2025, 11:57 PMKevin Worth
03/08/2025, 3:37 PMKevin Worth
03/08/2025, 3:43 PMAnimatedVisibility
, the list “suddenly” makes room for the first x number of rows in the expanding accordion(I believe from the look-ahead), and you see the first X rows all animate simultaneously. This causes the feel of jank because the title of accordion 2 “suddenly” disappears (scrolled off the bottom of the screen) rather than sliding down at a velocity that matches the accordion expansion.Kevin Worth
03/08/2025, 3:47 PMAnimatedVisibility
starts out as true - it does not transition from false to true).Kevin Worth
03/08/2025, 3:52 PMKevin Worth
03/08/2025, 3:52 PMSkaldebane
03/09/2025, 7:53 PMfalse
to true
for each item with a little delay. This is a little complicated, as it'll require you to maintain a "delayed" state (probably a List<Boolean>
) that reacts to the original state (the one that determines if the accordion is open), and changes with a delay (e.g. at first it's [true, false, false]
, then after the delay we switch one more [true, true, false]
, and keep going until everything is true
, where each accordion item takes its visibility from this list/map based on its index in the accordion or something like that). I don't like this approach, because of how verbose and complicated it is, its effect on cancelling the animation mid-way (you'll have to handle it yourself, otherwise it might look broken), and just the general extra overhead it may have.Skaldebane
03/09/2025, 8:05 PManimationSpec
of the EnterTransition
and ExitTransition
of AnimatedVisibility
.
You just have to get the "index" of each item in the accordion (however you wish), and then multiply that by some amount of delay.
For exit animation, you'll wanna reverse those delays.
You'll have to use tween
since it's the only way to specify a delay afaik.
(@Doris Liu Compose seems to have an internal delayed
function that looks super useful to delay e.g. a spring
or any other spec, any idea why it's internal
? Or is there a catch?)
Given the total number of items is called maxIndex
this is how that would look like:
val enterSpec = tween(delayMillis = index * 200)
val exitSpec = tween(delayMillis = (maxIndex - index) * 200)
AnimatedVisibility(
visible = ...,
enter = fadeIn(enterSpec) + expandVertically(enterSpec),
exit = fadeOut(exitSpec) + shrinkVertically(exitSpec)
)
Note that I haven't tried any of this myself, so take it with a grain of salt. Try it out and see how it goes.Kevin Worth
03/10/2025, 10:34 AMdelayMillis
! How did I miss that?! Thank you so much! It totally works. Fantastic.Doris Liu
03/10/2025, 11:26 PMKevin Worth
03/11/2025, 10:50 AMAnimatedVisibility(
visible = expandedGroups.contains(groupIndex),
enter =
fadeIn(tween(200, easing = LinearEasing)) +
expandVertically(
tween(
durationMillis = if (itemIndex < 10) 30 else 0,
delayMillis = if (modifierIndex < 10) modifierIndex * 30 else 300,
easing = LinearEasing
),
expandFrom = Alignment.Top,
),
exit =
fadeOut(tween(500, easing = LinearEasing)) +
shrinkVertically(
tween(
30,
delayMillis = if (itemIndex > 10) 0 else 300 - (modifierIndex * 30),
easing = LinearEasing,
),
shrinkTowards = Alignment.Top,
),
...
)
This gives us a "total" animation about 300 milliseconds long, and the user sees the first 10 items animate. That way, if the list is really long, the user doesn't have to wait for all of the lower (likely off screen) items to shrink before they see the animation start. The LinearEasing
was chosen so that it's all one fluid motion (you don't have each row accelerating and decelerating itself). If anyone sees room for improvement/correction, do let me know. Thanks everyone!Skaldebane
03/17/2025, 2:24 AMspring
in particular to have a delay (maybe this use case, where I'd want the more physics-like animations? bounciness?), but I was just wondering about the delayed
function that's private in Compose... If we use a spring inside of that, would it even work? And how would they even play together? The idea for a generic delaying mechanism still sounds attractive technically, if it works well in a way that's intuitive to us, but yeah there might not be a use-case for such a thing to begin with 🤷♂️