xamarin-forms-tab-badge icon indicating copy to clipboard operation
xamarin-forms-tab-badge copied to clipboard

Android: Adding and removing tabs causing badges to shift tab

Open gregersen79 opened this issue 5 years ago • 3 comments

On Android, when removing or adding a tab, the badges are on the wrong tabs. It seems it is only with bottom tab placement. I have recreated this issue with the sample app on Samsung Galaxy S8 running Android 8.0.0:

  • Select "Use bottom tab placement"
  • Press ex. "Tabbed page root with children as navigation pages".
  • Press "Remove tab".

Before pressing remove tab: Screenshot_20190604-103529

After pressing remove tab: Screenshot_20190604-104548

Pressing "Add tab" instead of "Remove tab": Screenshot_20190604-103539

gregersen79 avatar Jun 04 '19 08:06 gregersen79

I'm experiencing a similar behavior with top tabs on android using the BadgedTabbedPageRenderer.

I think this issue is best described as the badges staying on the original tab index after tab pages are add/removed at runtime.

Setting up a simple example where tabs can be added and removed at either the left or right at runtime reproduces this issue.

Adding tabs to the left Before add

Add 2 tabs to the left: After add

Observed behavior The badges were on page 1, 2, and 4 (tab indices 0, 1, and 3) before adding new pages, but after adding pages the badges are on page L2, L1, and 2 (tab indices 0, 1, and 3).

Expected behavior The badges are on page 1, 2, and 4 (new tab indices 2, 3, and 5)

Removing and adding tabs to the right Before remove right

Remove 2 tabs on the right: After remove right 2

Add 1 tab on the right: After add right

Observed behavior The badges were on pages 1, 2, and 4 (tab indices 0, 1, and 3) before removing pages and adding new pages, but after they were on pages 1, 2, and R1 (tab indices 0, 1, and 3)

Expected behavior The badges are on page 1 and 2 (page 4 was removed)

Adam-- avatar Oct 03 '19 15:10 Adam--

I'd like to help with fixing this bug, but I'm struggling a bit. It seems we should try to "refresh" all of the tab view's badge views. To do this I've tried a few approaches, most notable are the following.

Iterating over the BadgeViews collection and calling UpdateFromElement on the view using the page whenever tabs are added or removed (OnTabAdded, OnTabRemoved), but it doesn't seem to do anything.

            foreach (var (element, badgeView) in BadgeViews)
            {
                badgeView.UpdateFromElement((Page)element);
            }

Calling AddTabBadge for all of the pages. AddTabBadge refreshes the badge if one already exists and creates a new one if it doesn't. This fixed the "Adding tabs to the left" case above, but not the "Removing and adding tabs to the right" case.

            for (var i = 0; i < Element.Children.Count; i++)
            {
                AddTabBadge(i);
            }

These attempts did not seem to affect the bottom tab behavior.

Any thoughts on this issue?

Adam-- avatar Oct 03 '19 16:10 Adam--

Was there a version where this had previously worked? It's shown as supported in the readme.

Adam-- avatar Oct 03 '19 16:10 Adam--