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

[TabLayoutMediator] populateTabsFromPagerAdapter() is called on every notify type in RecyclerView adapter

Aperta
#887 4 commenti 4 reazioni 1 assegnatario 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 you instantiate TabLayoutMediator(... autoRefresh = true) you register PageDataObserver that invokes populateTabsFromPagerAdapter() on every type of notify(notifydataSetChange(),notifyItemChanged(int position)...) and every time the method will remove all the tabs and create a new ones and triger onConfigureChange(TabLayout.Tab tab, Int position) * (adapter.getItemCount()). Ask yourselves what if I notify only one item or maybe remove one item. Why do we need to recreate the whole TabLayout. What if our adapter list has 100 and more items?

Expected behavior:
I would expect if you call notifyItemChange(int position) that you call onConfigureChange to only that specific item or if you remove an item then remove that selected tab not recreate the whole TabLayout data.

Source code:
private class PagerAdapterObserver extends RecyclerView.AdapterDataObserver {
PagerAdapterObserver() {}

@Override
public void onChanged() {
  populateTabsFromPagerAdapter();
}

@Override
public void onItemRangeChanged(int positionStart, int itemCount) {
  populateTabsFromPagerAdapter();
}

@Override
public void onItemRangeChanged(int positionStart, int itemCount, @Nullable Object payload) {
  populateTabsFromPagerAdapter();
}

@Override
public void onItemRangeInserted(int positionStart, int itemCount) {
  populateTabsFromPagerAdapter();
}

@Override
public void onItemRangeRemoved(int positionStart, int itemCount) {
  populateTabsFromPagerAdapter();
}

@Override
public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) {
  populateTabsFromPagerAdapter(int positionStart, int itemCount);
}

}
}

Proposed solution I would suggest implementing case methods : updateTabFromPageAdapter(), updateTabsRangePageAdapter(int positionStart, int itemCount), removeTabsFromPageAdapter(int positionStart, int itemCount) etc... there will be no need for attaching and detaching the TabLayoutMediator when you call other types of notify in the adapter and also TabLayout scrollTo animation bug when TabLayout is
Scrollable not Fixed.

Material Library version: 1.2.0-alpha03
Device: On every device

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.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.