Skip to content
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

Merged
merged 3 commits into from
Mar 24, 2017
Merged

Adding OnTabShouldSelectListener #686

merged 3 commits into from
Mar 24, 2017

Conversation

mikecole20
Copy link
Contributor

@mikecole20 mikecole20 commented Mar 13, 2017

Adding a way to intercept tab selection.

EDIT

I've added an interface OnTabShouldSelectListener with a single method boolean 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. The BottomBar checks in private void handleClick(View v) for a non-null onTabShouldSelectListener 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).

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 56.883% when pulling 6aed335 on bellhops:feature/ShouldChange into 338ee86 on roughike:master.

@mikecole20
Copy link
Contributor Author

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.

@mikecole20
Copy link
Contributor Author

Ok, this works as expected. I've updated the original comment with more info on what this does.

@yombunker
Copy link
Collaborator

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.

@mikecole20
Copy link
Contributor Author

@yombunker we did try programmatically checking and returning, but it caused some side effects we didn't want.

It was inspired by iOS's UITabBarControllerDelegate which has a method like this: func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool. I'm happy to rename this method to shouldOverrideTabSelection or whatever else.

We are moving away from this specific use case, but I think others may find it useful in the future.

@yombunker
Copy link
Collaborator

@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.

@mikecole20
Copy link
Contributor Author

Sounds good.

@roughike
Copy link
Owner

I personally have nothing against this, given that the name is descriptive enough.

shouldOverrideTabSelection() is a great and descriptive name. @yombunker You can go ahead and add this to the stuff you're working on. If it's too late or you're busy, I can merge this later on myself.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 57.639% when pulling ea834e1 on bellhops:feature/ShouldChange into 1509078 on roughike:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 57.639% when pulling ea834e1 on bellhops:feature/ShouldChange into 1509078 on roughike:master.

@yombunker yombunker merged commit a2bd1f6 into roughike:master Mar 24, 2017
@yombunker
Copy link
Collaborator

@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.

@mikecole20
Copy link
Contributor Author

@yombunker awesome!

@yombunker
Copy link
Collaborator

@mikecole20 you can look at my changes in this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants