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

Presence of badges messes up unselection of tabs #266

Closed
henhal opened this issue Jun 1, 2016 · 1 comment · Fixed by #271
Closed

Presence of badges messes up unselection of tabs #266

henhal opened this issue Jun 1, 2016 · 1 comment · Fixed by #271

Comments

@henhal
Copy link
Contributor

henhal commented Jun 1, 2016

I have three tabs. Before using badges, selection and unselection works just fine.
After adding badges (but even without showing them), unselection does not work.

For example, if initially tab 0 is selected and I click on tab 2, tab 2 becomes visually selected and tab 0 is visually unselected. But if I then click tab 0 again, both tabs 0 and 2 stay visually selected. In this case I have debugged it enough to see that what happens is an unselect(0) followed by a select(0) instead of unselect(2) followed by select(0).

Since the presence of badges apparently mean you are adding one more container layout, I suppose the tags used for tracking active and inactive tabs doesn't work.

I am using 1.3.3.

@henhal
Copy link
Contributor Author

henhal commented Jun 1, 2016

The problem is that when badges are added, the newly created FrameLayout inherits the current tag from the LinearLayout carrying the pre-badge-tab, but the tag is not cleared on the LinearLayout.
So after the first selection of tab 2, the FrameLayouts will have tags INACTIVE, INACTIVE, ACTIVE as expected, but the embedded LinearLayouts will remain at ACTIVE, INACTIVE, INACTIVE.

Then when the user selects tab 0 again, BottomBar.findViewWithTag(ACTIVE) will erroneously find the obsolete LinearLayout inside tab 0 instead of the expected FrameLayout at position 2, and proceed to unselect the LinearLayout of tab 0 and select the FrameLayout of tab 0. After this we effectively have two selected tabs.

One solution would be to reset the tag of all LinearLayouts when converting tabs to badge-tabs (BottomBarBadge constructor):

    ViewGroup parent = (ViewGroup) tabToAddTo.getParent();
    parent.removeView(tabToAddTo);

    container.setTag(tabToAddTo.getTag());
    tabToAddTo.setTag(null); // <- this
    container.addView(tabToAddTo);
    container.addView(this);

To be honest, I think a cleaner solution would be to always use the FrameLayouts, it seems unnecessarily complex to convert the views in runtime just to make room for a badge inside the same container. One extra ViewGroup level around each tab even when they don't have badges likely won't impact performance?

As a temporary ugly workaround in my application code I managed to solve the problem like this:

BottomBarBadge badge = mBottomBar.makeBadgeForTabAt(pos, color, count);
((ViewGroup)badge.getParent()).getChildAt(0).setTag(null); // Remove tag of LinearLayout

henhal added a commit to henhal/BottomBar that referenced this issue Jun 2, 2016
When using badges, an extra FrameLayout is inserted as the container
for each tab. This container inherits the tag of the pre-badge tab view,
but the tag is not reset on the pre-badge tab view. This causes selection
and unselection of tabs to fail because findViewWithTag will erroneously
find the now obsolete tab views when searching for active tabs, resulting
in multiple tabs being visually selected when changing tabs.

By clearing the tag of the old (now inner) view when putting it in the new
tab container, we can ensure that findViewWithTag will only find relevant
views.

This fixes roughike#266.
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 a pull request may close this issue.

1 participant