https://kotlinlang.org logo
#compose
Title
# compose
m

Michael Marshall

10/27/2021, 5:22 AM
I’m using the Accompanist
HorizontalPager
and I’ve noticed that doing something like,
Copy code
val scope = rememberCoroutineScope()
val pagerState = rememberPagerState()
...
Tab (
    ...
    onClick = { scope.launch { pagerState.animateScrollToPage(index) } }
    ...
)
feels like a bit of an imperative programming anti-pattern compared to declaratively creating an
AnimatedContent
as described in the docs. I assume it’s doing something similar under the hood anyway, and this is just a convenience function, so it’s ok?
c

Csaba Kozák

10/27/2021, 7:58 AM
This is the correct way to to do this.
5 Views