Skip to content

Commit

Permalink
Bring back removed TabLayout method for compatibility
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ymarian authored and pekingme committed Jan 15, 2020
1 parent 0a03911 commit 17912e0
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/java/com/google/android/material/tabs/TabLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ public interface BaseOnTabSelectedListener<T extends Tab> {
boolean tabIndicatorFullWidth;
boolean unboundedRipple;

@Nullable private OnTabSelectedListener selectedListener;

private final ArrayList<OnTabSelectedListener> selectedListeners = new ArrayList<>();
@Nullable private OnTabSelectedListener currentVpSelectedListener;
private final HashMap<BaseOnTabSelectedListener<? extends Tab>, OnTabSelectedListener>
Expand Down Expand Up @@ -725,6 +727,25 @@ private void addTabFromItemView(@NonNull TabItem item) {
addTab(tab);
}

/**
* @deprecated Use {@link #addOnTabSelectedListener(OnTabSelectedListener)} and {@link
* #removeOnTabSelectedListener(OnTabSelectedListener)}.
*/
@Deprecated
public void setOnTabSelectedListener(@Nullable OnTabSelectedListener listener) {
// The logic in this method emulates what we had before support for multiple
// registered listeners.
if (selectedListener != null) {
removeOnTabSelectedListener(selectedListener);
}
// Update the deprecated field so that we can remove the passed listener the next
// time we're called
selectedListener = listener;
if (listener != null) {
addOnTabSelectedListener(listener);
}
}

/**
* @deprecated Use {@link #addOnTabSelectedListener(OnTabSelectedListener)} and {@link
* #removeOnTabSelectedListener(OnTabSelectedListener)}.
Expand Down Expand Up @@ -3090,7 +3111,7 @@ public void onAnimationUpdate(@NonNull ValueAnimator valueAnimator) {
public void onAnimationStart(Animator animator) {
selectedPosition = position;
}

@Override
public void onAnimationEnd(Animator animator) {
selectedPosition = position;
Expand Down

0 comments on commit 17912e0

Please sign in to comment.