Here’s a gist for an animated page indicator that ...
# compose
d
o
Am I tired or there is an issue in your index vs page count use?
d
Yes, there was. Just changed it 😅
👌 1
o
totalPages is a number of page I guess, but you do
Copy code
assert(
        value = currentPage in 0..totalPages,
and
for (in in 0..totalPages)
d
i replaced it with
until
in the gist
o
Yes
I don't understand the link between width and height
val width: Dp by animateDpAsState(if (selected) height * selectedMultiplier else height)
seems odd 🤔
I would rename it I would rename
height
to something like
indicatorSize
d
Well, when it’s not selected it’s a circle, so height = width. When it’s selected I used a multiplier for the width only.
o
Yes I got it but it would be clearer with a
size
name rather than a
height
used as
width
IMO 🙂
d
Yeah true, that’d be less confusing
o
That being said, I do not understand how the animation works 😄
1. how does width reduces to size "at some point" 2. how the animation works when coming from left or right
(might be dummy question)
d
1. When you use the composable, you put a parameter for the current page. When that changes, it recomposes and the
animatedDpAsState
inside changes the value used for the width with intermediary values that are between the shrinked width and the expanded width, so it doesn’t just skip to the new size immediately, but gradually changes size.
2. Each of the dots is represented by a Canvas composable inside the Row. The row is set to a fixed width that is the maximum it can be, and uses a
SpaceBetween
arrangement so it always spreads the available spacing between the dots. So, it looks the same in both directions.
👌 1
o
1. Yes, that's my understanding but how does it come back to reduced size once transition is done?
1. -> Oh, it doesn't in fact 😅 I checked your video too quickly. I was expecting the same behavior as we see sometimes, when the transition expands the bullets and then shrinks to its initial width
m
cc @adeyds