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

[TabLayout] TabLayout Scroll Bug: Left Tab Misalignment After Fast Scroll

Aperta
#4,890 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug Widget: Tab
Lingua principale
Java
Stelle
17.4k
Fork
3.2k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Description:

When performing a fast horizontal scroll that moves the entire TabLayout to the right, we expect the leftmost tab to return to an x = 0 position.

However, it appears that the leftmost tab occasionally snaps back to a negative x-position instead.

When this happens, tapping on any tab has no immediate effect. Instead, multiple taps are required before the leftmost tab returns to a non-negative x-position.

Until it returns to the correct position, all tab taps become unresponsive, except that they seem to gradually nudge the layout back toward alignment.

In the video, you can observe a small gap between the leftmost tab and the screen’s edge immediately after a fast scroll - this gap indicates the misalignment.

https://youtu.be/tl8PDvkRHYo

Expected behavior: Left most tab will never reach negative x position

Source code:

private void initTabs() {
    if (noteFragmentStateAdapter == null) {
        noteFragmentStateAdapter = new NoteFragmentStateAdapter(this, tabInfos);
        viewPager.setAdapter(noteFragmentStateAdapter);

        new TabLayoutMediator(tabLayout, viewPager,
                (tab, position) -> tab.setText(noteFragmentStateAdapter.getPageTitle(position))
        ).attach();

        viewPager.unregisterOnPageChangeCallback(onPageChangeListener);
        viewPager.registerOnPageChangeCallback(onPageChangeListener);

        // http://stackoverflow.com/questions/9857420/viewpager-fragments-getting-destroyed-over-time
        viewPager.setOffscreenPageLimit(1);
    } else {
        noteFragmentStateAdapter.notifyDataSetChanged();
    }

    int selectedNoteTabIndex = WeNoteOptions.getSelectedNoteTabIndex();

    setSelectedNoteTab(selectedNoteTabIndex);
}

Minimal sample app repro: (Sorry. I will provide a sample in next few days)

Android API version: Android API 35

Material Library version: Material Android Library version you are using here (e.g., 1.1.0-alpha07)

Device: Emulator Pixel 8 Pro API 35 arm64-v8a

https://github.com/user-attachments/assets/dfc811b2-35a6-4a52-925b-78d1d94390fa

To help us triage faster, please check to make sure you are using the latest version of the library.

We also happily accept pull requests.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Parti dal punto di ingresso initTabs() mostrato nel report e riproduci lo scorrimento orizzontale rapido sull’emulatore Pixel 8 Pro API 35 con Material 1.12.0. Verifica che la scheda più a sinistra non raggiunga una posizione x negativa e che i tocchi sulle schede rispondano immediatamente dopo lo scorrimento.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
android, java
Ambito
mobile
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.