-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TabLayout] Fix TabView click listener customization #4107
base: master
Are you sure you want to change the base?
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
a9385fb
to
51649be
Compare
tab.select(); | ||
if (tab.onTabClickListener != null) { | ||
tab.onTabClickListener.onClick(tab); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to avoid overriding the default behavior unless there's a valid use case to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@drchen Hey, thanks for the comment.
The main idea is to have an option to override a default behavior.
A usecase is described in the #4105 issue.
tl.dr.
We need to override a default behaviour to add a validation logic when user clicks on the tab before selecting it.
With the existing implementation, I tried selecting the previous tab in case the data is not valid but it doesn't look good because the tab is selected with the animation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok cool. So I think there are several improvements I'll suggest here:
- Let's make
onTabClickListener
be non-null. - Let
OnTabClickListener .onClick()
return a boolean to indicate if the click event is handled, so we can simplify the logic like:
final boolean handled = super.performClick() || tab.onTabClickListener.onClick(tab);
... rest the same
- Refine the javadoc to make it more clear that how to override the default behavior.
tab.select(); | ||
if (tab.onTabClickListener != null) { | ||
tab.onTabClickListener.onClick(tab); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok cool. So I think there are several improvements I'll suggest here:
- Let's make
onTabClickListener
be non-null. - Let
OnTabClickListener .onClick()
return a boolean to indicate if the click event is handled, so we can simplify the logic like:
final boolean handled = super.performClick() || tab.onTabClickListener.onClick(tab);
... rest the same
- Refine the javadoc to make it more clear that how to override the default behavior.
@@ -2644,7 +2669,9 @@ public boolean performClick() { | |||
if (!handled) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be part of the default onClick behavior as well.
Closes #4105
Usage example: