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

Shakil Karim

02/09/2021, 8:07 AM
Is there any Example of using ViewPager2 with Compose?
t

Timo Drick

02/09/2021, 11:58 AM
You can not use ViewPager. There is BottomNavigation and Tab which you can use.
n

nglauber

02/09/2021, 12:39 PM
Do you know if it’s already possible to swap between the tabs using gesture in compose?
t

Timo Drick

02/09/2021, 12:41 PM
Not out of the box as far as i know. But attach a modifier to detect swipes and change the tab should be easy.
Of course if you want animation it is a little bit harder.
👍 1
c

Cyril Find

02/09/2021, 1:46 PM
yeah i tried to that and uh...gave up for now 😅
s

Shakil Karim

02/09/2021, 2:44 PM
@Cyril Find What problems you faced? I was thinking of using AndroidView for that?
c

Cyril Find

02/09/2021, 2:48 PM
oh I mean I tried doing the swipe modifier thing and it was quite complicated...but it shouldn't be too hard using interoperability (I think you're gonna use
ComposeView
inside your view pager fragments, not
AndroidView
though)
s

Shakil Karim

02/09/2021, 4:07 PM
@Cyril Find "`ComposeView` inside your view pager fragments" is good option also, but I'm not using Fragments in my app, i was thinking to create a composable for native ViewPager2 and each View Pager item will be composeView.
c

Cyril Find

02/09/2021, 4:13 PM
oh ok yeah i usually use it with fragments but i guess that works too !
d

Dejan Predovic

02/11/2021, 3:51 PM
There is a swipe pager implementation in Jetcaster sample
It worked up to alpha-11, but got totally broken in alpha 12
c

Cyril Find

02/11/2021, 11:39 PM
ah, well thanks anyways !
a

Afzal Najam

02/21/2021, 6:26 AM
The one in the main branch works: https://github.com/android/compose-samples/blob/main/Jetcaster/app/src/main/java/com/example/jetcaster/util/Pager.kt But it doesn't have any state saving it seems
16 Views