Skip to content

Commit

Permalink
bugfix: onTabSelected is called double time. #941
Browse files Browse the repository at this point in the history
  • Loading branch information
cgspine committed Jun 8, 2020
1 parent a9ffc8f commit 25b3377
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,17 +317,21 @@ public void setMode(@Mode int mode) {
}


void onClickTab(int index) {
protected void onClickTab(QMUITabView view, int index) {
if (mSelectAnimator != null || needPreventEvent()) {
return;
}

if (mOnTabClickListener != null) {
if (mOnTabClickListener.onTabClick(view, index)) {
return;
}
}

QMUITab model = mTabAdapter.getItem(index);
if (model != null) {
selectTab(index, mSelectNoAnimation, true);
}
if (mOnTabClickListener != null) {
mOnTabClickListener.onTabClick(index);
}
}

protected boolean needPreventEvent() {
Expand Down Expand Up @@ -499,12 +503,13 @@ public void onAnimationStart(Animator animation) {

@Override
public void onAnimationEnd(Animator animation) {
mSelectAnimator = null;
prevView.setSelectFraction(0f);
nowView.setSelectFraction(1f);
mSelectAnimator = null;
// set current selected index first, dispatchTabSelected may call selectTab again.
mCurrentSelectedIndex = index;
dispatchTabSelected(index);
dispatchTabUnselected(prev);
mCurrentSelectedIndex = index;
if (mPendingSelectedIndex != NO_POSITION && !needPreventEvent()) {
selectTab(mPendingSelectedIndex, true, false);
mPendingSelectedIndex = NO_POSITION;
Expand Down Expand Up @@ -711,9 +716,12 @@ public interface OnTabClickListener {
/**
* 当某个 Tab 被点击时会触发
*
* @param tabView 被点击的View
* @param index 被点击的 Tab 下标
*
* @return true 拦截 selectTab 事件
*/
void onTabClick(int index);
boolean onTabClick(QMUITabView tabView, int index);
}

public interface OnTabSelectedListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected void onBindTab(QMUITab item, QMUITabView view, int position) {
@Override
public void onClick(QMUITabView view) {
int index = getViews().indexOf(view);
mTabSegment.onClickTab(index);
mTabSegment.onClickTab(view, index);
}

@Override
Expand Down

0 comments on commit 25b3377

Please sign in to comment.