Skip to content

Commit 17912e0

Browse files
ymarianpekingme
authored andcommitted
Bring back removed TabLayout method for compatibility
Resolves #903 We accidentally removed this since it wasn't in 1.0.0 and it was deprecated. It exists to keep compatibility with version 27.0 of the library. PiperOrigin-RevId: 289832106
1 parent 0a03911 commit 17912e0

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lib/java/com/google/android/material/tabs/TabLayout.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,8 @@ public interface BaseOnTabSelectedListener<T extends Tab> {
436436
boolean tabIndicatorFullWidth;
437437
boolean unboundedRipple;
438438

439+
@Nullable private OnTabSelectedListener selectedListener;
440+
439441
private final ArrayList<OnTabSelectedListener> selectedListeners = new ArrayList<>();
440442
@Nullable private OnTabSelectedListener currentVpSelectedListener;
441443
private final HashMap<BaseOnTabSelectedListener<? extends Tab>, OnTabSelectedListener>
@@ -725,6 +727,25 @@ private void addTabFromItemView(@NonNull TabItem item) {
725727
addTab(tab);
726728
}
727729

730+
/**
731+
* @deprecated Use {@link #addOnTabSelectedListener(OnTabSelectedListener)} and {@link
732+
* #removeOnTabSelectedListener(OnTabSelectedListener)}.
733+
*/
734+
@Deprecated
735+
public void setOnTabSelectedListener(@Nullable OnTabSelectedListener listener) {
736+
// The logic in this method emulates what we had before support for multiple
737+
// registered listeners.
738+
if (selectedListener != null) {
739+
removeOnTabSelectedListener(selectedListener);
740+
}
741+
// Update the deprecated field so that we can remove the passed listener the next
742+
// time we're called
743+
selectedListener = listener;
744+
if (listener != null) {
745+
addOnTabSelectedListener(listener);
746+
}
747+
}
748+
728749
/**
729750
* @deprecated Use {@link #addOnTabSelectedListener(OnTabSelectedListener)} and {@link
730751
* #removeOnTabSelectedListener(OnTabSelectedListener)}.
@@ -3090,7 +3111,7 @@ public void onAnimationUpdate(@NonNull ValueAnimator valueAnimator) {
30903111
public void onAnimationStart(Animator animator) {
30913112
selectedPosition = position;
30923113
}
3093-
3114+
30943115
@Override
30953116
public void onAnimationEnd(Animator animator) {
30963117
selectedPosition = position;

0 commit comments

Comments
 (0)