https://kotlinlang.org logo
Title
c

Colton Idle

10/01/2021, 7:43 PM
If I have a generic list of composables...
List<@Composable () -> Unit>
is it possible to write an if/when statement on what to do if
mylist[0]
is of type
MySpecialButton
?
z

Zach Klippenstein (he/him) [MOD]

10/01/2021, 7:45 PM
There’s no way to peek into a function and see what other functions it calls, but depending on what you’re actually trying to do there are probably other ways to approach the problem
c

Colton Idle

10/01/2021, 7:53 PM
I've been trying and failing to recreate this airbnb-like carousel using accompanist horizontalPager. Which has led me down a rabbit hole to ask the above question. 🤣
It seems like horizontalPager only lets you have 1 item on the screen plus 1 that's peeking in.
But trying to get multiple items (via setting a width on the item composable of like 100.dp) just doesn't work. HorizontalPager just keeps adding a huge gap between items. 🤔 Can't tell if I'm an idiot, or maybe it's not a use case of HP, or if its an HP bug.
o

Orhan Tozan

10/01/2021, 7:57 PM
@Colton Idle Unless I'm missing something, you can just use a scrollable Row or a LazyRow for this
c

Casey Brooks

10/01/2021, 8:04 PM
Modifier.swipeable
might be the thing you need. Put the items in a horizontal row, and make it swipeable to "snap" to each item in the row. Or just a normal horizontally-scrolling row if you don't need the snapping behavior https://developer.android.com/jetpack/compose/gestures#swiping
c

Colton Idle

10/01/2021, 8:04 PM
I need the pager dots at the bottom of this too (which isn't shown in the airbnb example), but yes you're right I could do it with a scrollable row.
So... more accurately I want the airbnb carousel with dots. here are the "dots" if anyone is unfamiliar.
also. a nicer benefit too of horizontalPager (that my UX team likes) is that you get item "snapping" with horizontalPager vs just a scollable Row
i

Ian Lake

10/01/2021, 9:17 PM
It sounds like you don't actually want a pager, you just want the snap behavior. Did you see Chris's recent work to separate the snap positioning into something you can apply to any list? https://twitter.com/chrisbanes/status/1442909344597635072
c

Colton Idle

10/01/2021, 9:18 PM
I can't use pager dots with that though can I?
h

Hachemi Hamadi

10/04/2021, 8:03 AM
It used to work for me on version 0.17.0 but when i upgraded to 0.19.0 I am facing the same issue.