Swipeable Tab Rows - UX With Material3

Sdílet
Vložit
  • čas přidán 8. 09. 2024
  • In this video you will learn how you can create a tab layout in Material3 and Jetpack Compose so you can swipe between pages.
    ⭐ Let me be your mentor and I'll make you an industry-ready Android developer in 10 weeks
    ⭐ Apply now:
    pl-coding.com/...
    Get the source code for this video on GitHub:
    github.com/phi...

Komentáře • 74

  • @Alchemist10241
    @Alchemist10241 Před 10 měsíci +2

    This is the simplest and easiest solution for implementing swipeable tab rows in jetpack compose I've seen so far, well done and thanks Phillips

  • @Luffy_2804
    @Luffy_2804 Před 11 měsíci +3

    you are one of the best just because of you i just switched to jetpack , initially i was hating this jetpack stuff and finding xml , easy as compared to jetpack , but now i started liking jetpack too much , it is really amazing , initially it becomes way to difficult , not able to understand what is happening with regular practice efforts and i am able to understand how it is working

  • @tusharbhatia6777
    @tusharbhatia6777 Před 6 měsíci +13

    For anyone facing the delay in indicator changing , i fixed the issue
    code:
    val scope = rememberCoroutineScope()
    LaunchedEffect(pagerState.currentPage) {
    selectedTabIndex = pagerState.currentPage
    }
    in Tab ,onclick = {
    scope.launch {
    pagerState.animateScrollToPage(index)
    }
    selectedTabIndex = index
    }
    remove the other LauchedEffect he typed in video

  • @teovladusic
    @teovladusic Před 8 měsíci +4

    PagerState has a property called "targetPage", it works better than what Philipp suggested as there is some delay when waiting pager animation to finish.

    • @tonymont72
      @tonymont72 Před 7 měsíci

      How did you handle the delay?

  • @azickri
    @azickri Před 5 měsíci

    This is the best of Tutorial, you explain all need we must learn without chitchat 🎉🎉🎉

  • @ChrisAthanas
    @ChrisAthanas Před 11 měsíci +7

    @Phillip Lackner The Source code link is responding with 404... is the link correct?

  • @Ayor88
    @Ayor88 Před 6 měsíci

    First, thank you very much for all of your content, I watch almost all of your videos.
    While it works, The tab doesn't update until the end of the scrolling. It would be better if booth where synchronized

  • @nastenkaoo
    @nastenkaoo Před 6 měsíci

    thanks Philipp, you are great

  • @JJSS90
    @JJSS90 Před 5 měsíci

    Philp you are the best

  • @kirwakelvinkering3122
    @kirwakelvinkering3122 Před 11 měsíci +1

    Philip you've been my best teacher in Kotlin .was just wondering if we could modify the Tab indicator to have rounded corners like that of twitter .

  • @lucachangretta2025
    @lucachangretta2025 Před 3 měsíci

    Dude ur so so so underrated

  • @funclips767
    @funclips767 Před rokem +1

    keep the good work❤

  • @johnoricha7088
    @johnoricha7088 Před rokem

    Did something very similar on flutter very recently 😅. My implementation was for 2 tabs and 2 pages.

  • @saeedghiassy5435
    @saeedghiassy5435 Před rokem

    Like always great videos , thanks you very much ! :)

  • @unknownBoy85lover
    @unknownBoy85lover Před rokem

    Thank you so useful it's I need it just right now 😂❤

  • @wikigerman
    @wikigerman Před 8 měsíci

    Thank you very much Philipp,, is it possible to reduce the space between tabs?
    the current default value is: private val ScrollableTabRowMinimumTabWidth = 90.dp

  • @david_whyte
    @david_whyte Před 3 měsíci

    Hi why are you not using button nav bar in the scaffold?

  • @anthonydanyameabuah4542

    Funny thing I spent almost the last two days figuring this thing out and now it's here. Should've waited.
    Question : When using the scrollable tab, how do you keep the selected tab focused on the screen when swiping the horizontal pager to a tab that isn't on the screen yet(say the last screen). I hope my question is clear

  • @dreW1-
    @dreW1- Před rokem

    you just solved me a bug with the horizontal pager to get the index, i was executing a method inside the horizontal pager instead of launched effect.... those timings insane

  • @Leon-un2ii
    @Leon-un2ii Před rokem

    So this could also easily be bottom Navigation bar or should we then stick to the other video for this topic? I am a bit confused. Your way in this video now looks better and has more features.

  • @abada-s
    @abada-s Před rokem +3

    Why didn't you use the pagerState.currentPage as the index of the selected tab? also tab onClick will animate the pager state to the selected index

    • @PhilippLackner
      @PhilippLackner  Před rokem

      Does that also behave correctly when switching from start to end tab?

    • @abada-s
      @abada-s Před rokem

      @@PhilippLackner I didn't test it but it should be fine because we are dealing with one state

    • @PhilippLackner
      @PhilippLackner  Před rokem +2

      @@abada-s if that works well, it seems like the better solution. Thanks for adding 👍🏼

    • @wesd3fer
      @wesd3fer Před rokem

      @@abada-s Just wanted to chime in and say that I tested this and it works as expected. The only minor thing is that for the onClick you have to account for PagerState.animateScrollToPage being a suspending function.

  • @wyneci
    @wyneci Před rokem +1

    Hi Phillip, please make a tutorial with MongoDB 🙏

  • @gamecool2110
    @gamecool2110 Před 6 měsíci

    thanks so much you saved me

  • @John-qt6qk
    @John-qt6qk Před rokem

    Awesome!! well done

  • @TheFlexath
    @TheFlexath Před 10 měsíci

    Thank you Sir

  • @zulhijananda5772
    @zulhijananda5772 Před 8 měsíci +1

    Source code is 404, where can i get it. I have problem, my pager does not change when tab is changed

  • @rakam.a8070
    @rakam.a8070 Před rokem +1

    Can you make a video how to combine TabRows with TopAppBar that has scroll behaviour?

    • @anthonydanyameabuah4542
      @anthonydanyameabuah4542 Před rokem

      Especially how to keep the selected tab in focus. This would be very helpful as I'm struggling to figure out

  • @DmitryZatuchny
    @DmitryZatuchny Před 4 měsíci

    Page not found for repo in description

  • @luciferGOD1234
    @luciferGOD1234 Před rokem

    What will be best way achieve bottom bar? I mean viewpager is better or bottom bar layout?

  • @wilianc.b.3065
    @wilianc.b.3065 Před 6 měsíci +1

    Hi! Thanks for the video.
    One question please: When I use isScrollInProgress, there is a bit of a lag to move the selectedTabIndex in the TabRow. Is there a solution for this lag?

    • @nadirseddaoui8136
      @nadirseddaoui8136 Před 6 měsíci

      Hi! I have the same issue. Did you got any solution ?
      when i dont use isScrollInProgress there is still a very little lag. I mean this is not smooth as Watsapp swip for exemple.

    • @itsusinn
      @itsusinn Před 6 měsíci

      i came into this wired situation too

    • @itsusinn
      @itsusinn Před 6 měsíci +1

      @wilianc.b.3065 @nadirseddaoui8136
      LaunchedEffect(pagerState.targetPage){
      selectedTabIndex= pagerState.targetPage
      }
      should fix this problem

    • @JJSS90
      @JJSS90 Před 5 měsíci

      @@itsusinn Thanks, this fixed the issue

  • @m777rmc3
    @m777rmc3 Před rokem

    Thank you!!!!!

  • @denisk3852
    @denisk3852 Před rokem

    Great 👍

  • @زيد_اليماني

    amazing

  • @nijithebuji
    @nijithebuji Před rokem +2

    Source code link is saying 404 not found

  • @padmakargarg9720
    @padmakargarg9720 Před 9 měsíci

    Hi ,XIaomi device does not dismiss lockscreen when opening Activity from background (VOIP Call) please help me out regarding this
    point

  • @divyathakur5885
    @divyathakur5885 Před 9 měsíci

    How can I make multiple pages with different stateflow list?? spwiping pages are worling terrible and recreating multiple ties if using live data inside it.

  • @dr.paradoxdelusionsofgrandeur

    I still have difficulty in using jetpack compose because it doesn't have the xml view where you can just drag and drop your designs (from figma) then code the functions in the background.

  • @goole-k3z
    @goole-k3z Před 2 měsíci

    고아워여

  • @user-ey5hl9nv5o
    @user-ey5hl9nv5o Před rokem

    Hy Philip.
    Sorry if asking off topic.
    I've seen your video creating an Instagram profile page. I want to ask, how can the list of "content" that appears continue to scroll down?

  • @thelight786
    @thelight786 Před 4 měsíci

    github url not taking me to the code. ?

  • @DasBy768
    @DasBy768 Před 10 měsíci

    Hi everyone, I repeated exactly the code from the video, but when I got to two Lauchedeffect's, they did not change the operation of the application in any way and even with them the application works the same as without them. I don't understand what's wrong here. Thanks to everyone who can help me

  • @ritikrawat2447
    @ritikrawat2447 Před měsícem

    What if we need to add composables in side these tab rows how can we do it can anyone help pls

    • @ritikrawat2447
      @ritikrawat2447 Před měsícem

      Answer
      HorizontalPager(state = pagerState, modifier = Modifier
      .fillMaxWidth()
      .weight(1f)
      ){ index ->
      Box(
      modifier = Modifier.fillMaxSize(),
      contentAlignment = Alignment.Center
      ){
      when ( index ){
      0 -> PersonalScreen()
      1 -> ServicesScreen()
      2 -> BusinessScreen()
      }
      }
      }

  • @lariniabdellah1820
    @lariniabdellah1820 Před 10 měsíci

    tabrow is deprecated now so what alternative can i use

  • @jishnupdileep3143
    @jishnupdileep3143 Před 5 měsíci

  • @tushar_mahale
    @tushar_mahale Před rokem

    Please provide a good promo code for your " Ultimate PL course bundle"

  • @lawrence1519
    @lawrence1519 Před rokem

    heeey :D Can you make a video about cucumber(BDD) in android (with hilt)?

  • @MohdAflah.k
    @MohdAflah.k Před 25 dny

    Mool😮😅

  • @goole-k3z
    @goole-k3z Před 2 měsíci

    방해해..누가

  • @goole-k3z
    @goole-k3z Před 2 měsíci

    😂😂

  • @goole-k3z
    @goole-k3z Před 2 měsíci

    😂

  • @GRIFTYRODRIGUEZ
    @GRIFTYRODRIGUEZ Před 9 měsíci +1

    bruh why you make your voice sound so weird. sounds like metal gear solid and the codec is running out of batteries

  • @Relax-4-Relax
    @Relax-4-Relax Před 5 měsíci +1

    Hello, I am writing through a translator so it may not be clear...
    In the place where there is a comment ( //Some screen)
    I place my screen.
    In your example, there are a lot of unnecessary recompositions.
    see if I made the changes correctly.
    Thank you
    Surface(
    modifier = Modifier.fillMaxSize(),
    color = MaterialTheme.colorScheme.background
    ) {

    val pagerState = rememberPagerState { tabItem.size }
    val coroutineScope = rememberCoroutineScope()
    Column(
    modifier = Modifier.fillMaxSize()
    ) {
    TabRow(selectedTabIndex = pagerState.currentPage) {
    tabItem.forEachIndexed { index, tabItem ->
    Tab(
    selected = true,
    onClick = {
    coroutineScope.launch { pagerState.animateScrollToPage(index) }
    },
    text = { Text(text = tabItem.title) },
    icon = {
    Icon(
    imageVector =
    if (index == pagerState.currentPage) tabItem.selected else tabItem.unselected,
    contentDescription = null
    )
    })
    }
    }
    HorizontalPager(
    modifier = Modifier.weight(1f),
    state = pagerState
    ) { index ->
    //Some screen
    }
    }
    }

    • @enriqueajin6016
      @enriqueajin6016 Před 3 měsíci

      Thanks! I this approach works perfectly.

    • @tech_ch1211
      @tech_ch1211 Před 2 měsíci +1

      This solution is better than the one provided in the video, and without lags and workarounds.
      Thanks