-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Adding OnTabShouldSelectListener #686
Conversation
Didn't mean to open this against the main repo yet. Still testing this out with our fork. I'll follow up later on if this is working as intended. |
Ok, this works as expected. I've updated the original comment with more info on what this does. |
I don't think the name is very descriptive about what it does, i'm think something similar to what the webview does "shouldOverrideTabSelection()", but, that being said, it seems like this is a very specific use case that i don't know if it should be part of the library. Have you tried using badges to notify that there are pending changes in that tab? or if you don't change color of the BAR then maybe you can get away with it by adding a Tab selected listener and in there check if you should allow that change, and if not, programmatically "return" him to the previous tab. |
@yombunker we did try programmatically checking and returning, but it caused some side effects we didn't want. It was inspired by iOS's We are moving away from this specific use case, but I think others may find it useful in the future. |
@mikecole20 well let's see what @roughike thinks about this request, currently i'm working on adding some "advance" features without compromising the default simple behavior that you currently get. If he agrees with this feature i can add some functionality like this into the change, so that if you call the "super" method it actually moves, if not it will not do anything, in that way you can prevent the tab change. In that way you can get this behavior by just overriding the base class and passing it to the BottomBar. But, then again i'll only add that if he agrees with this change. |
Sounds good. |
I personally have nothing against this, given that the name is descriptive enough.
|
@roughike @mikecole20 i merged the change, now i'm just renaming the class to OverrideTabSelectionListener and adding test for it so that the change is covered in the tests. |
@yombunker awesome! |
@mikecole20 you can look at my changes in this PR |
Adding a way to intercept tab selection.
EDIT
I've added an interface
OnTabShouldSelectListener
with a single methodboolean onTabShouldSelect(@IdRes int oldTabId, @IdRes int newTabId)
. The purpose of this is to be able to add logic to stop tab changes. There may be a better name for this interface and/or method. TheBottomBar
checks inprivate void handleClick(View v)
for a non-nullonTabShouldSelectListener
and calls out to it to see if it should proceed with the tab change. This technically intercepts both select and reselect. I could also break the interface into two different methods, or rename the interface to something more encompassing.Our use case is that we want to warn the user of unsaved changes before they go (and then programmatically proceed with the tab change if they want to discard their unsaved changes).