material-components / material-components/material-components-android

TabLayoutMediator with smoothScroll = false, causes manual page (via swiping) to abruptly stop animating

Open
#1,865 1 comment 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Widget: Tab
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

Create a ViewPager2 and make sure isUserInputEnabled is true.

Tie the ViewPager2 to a TabLayout, ensuring that smoothScroll is false:

TabLayoutMediator(tabLayout, viewPager, true, false) { tab, position ->
    …
}.attach()

With these settings, we should expect user input (i.e. swipe) on the ViewPager2 to result in a smooth animation, while clicking on a tab should result in a non-animated (instant) change in page.

However, what actually happens is that the swipe animation abruptly stops as soon as the user lifts his/her finger.

This happens because of a circular relationship between TabLayoutMediator.ViewPagerOnTabSelectedListener and TabLayoutMediator.TabLayoutOnPageChangeCallback. The user swipe should just update the TabLayout UI and be done, but instead it triggers the TabLayoutOnPageChangeCallback, which in turn calls the ViewPagerOnTabSelectedListener, which then calls viewPager.setCurrentItem with smooth = false. That last piece aborts the animation in progress.

This a side effect of:

#813 [TabLayout] disable ViewPager2 smoothScroll with TabLayoutMediator

Note that passing smoothScroll = true is not a solution because it then causes unwanted animation after tab clicks.

Expected behavior: Swipe page animation should continue until ViewPager2 settles.

Source code: See mentioned classes in TabLayoutMediator.java.

Android API version: Any

Material Library version: 1.3.0-alpha03

Device: Any

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the mentioned classes in TabLayoutMediator.java and reproduce the issue using ViewPager2 with isUserInputEnabled enabled and smoothScroll set to false. Trace the interaction between ViewPagerOnTabSelectedListener and TabLayoutOnPageChangeCallback; done means swipes continue animating until ViewPager2 settles while tab clicks remain instant.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.