xabre / xamarin-forms-tab-badge

Xamarin Forms bindable Tab badges for iOS, Android, UWP, MacOS and WPF
MIT License
307 stars 75 forks source link

[Bug] NavigationPages as TabbedPage Children #58

Closed Phenek closed 5 years ago

Phenek commented 5 years ago

Hello,

Setting Badges on Tabbed NavigationPages is showing the logo and text but no badges:

            var page = new SearchPage();
            var navigation = new NavigationPage(page)
            {
                Title = "Search",
                Icon = "Search",
            };

            navigation.SetBinding(TabBadge.BadgeTextProperty, nameof(BottomMenuViewModel.Count));
            navigation.SetBinding(TabBadge.BadgeColorProperty, nameof(BottomMenuViewModel.Color));
            navigation.SetBinding(TabBadge.BadgeTextColorProperty, nameof(BottomMenuViewModel.TextColor));
            navigation.BindingContext = viewModel;
            Children.Add(navigation);

Setting Badges, Icon & text on first stacked ContentPage is showing badge but no text & no Icon.

            var tab = new SearchPage()
            {
                Title = "Search",
                Icon = "Search",
            };
            var navigation = new NavigationPage(tab);

            tab.SetBinding(TabBadge.BadgeTextProperty, nameof(BottomMenuViewModel.Count));
            tab.SetBinding(TabBadge.BadgeColorProperty, nameof(BottomMenuViewModel.Color));
            tab.SetBinding(TabBadge.BadgeTextColorProperty, nameof(BottomMenuViewModel.TextColor));
            tab.BindingContext = viewModel;
            Children.Add(navigation);

Mixing Both works for iOS but on Android (Bottom position) it isn't showing the badge

            var tab = new AccountPage();
            var navigation = new NavigationPage(tab)
            {
                Title = "Profil",
                Icon = "Profile",
            };

            tab.SetBinding(TabBadge.BadgeTextProperty, nameof(BottomMenuViewModel.Count));
            tab.SetBinding(TabBadge.BadgeColorProperty, nameof(BottomMenuViewModel.Color));
            tab.SetBinding(TabBadge.BadgeTextColorProperty, nameof(BottomMenuViewModel.TextColor));
            tab.BindingContext = viewModel;
            Children.Add(navigation);

The NavigationPage should managed the badges not its first stacked ContentPage, don't you think? Regards,

xabre commented 5 years ago

@Phenek Ok a checked this issue out and found the following:

  1. Xamarin Forms (regardless of the badge plugin) only shows the icon/title in a tab if the child page directly has this set (i.e. if a navigation page wraps a content page as a child tab, the navigation page itself has to have the Tile and Icon property set).... this might even be a xamarin forms bug
  2. The current version of the padge plugin looks for the wrapped content page if any navigation page is found.
  3. It makes no logical sense to set tab badges on navigation page wrappers. The content page is usually declared in XAML where it also makes sense to define the tab badge bindings.

The workaround for the current plugin version would be to set the Tile and Icon of the naviagtion page to the wrapped page: var tab1NavigationPage = new NavigationPage(tab1) { Title = tab1.Title, Icon = tab1.Icon };

I will modify the plugin to look for tab badge properties also on navigation pages and if not found then use the wrapped page so it can handle both cases.

xabre commented 5 years ago

v2.1.1 realeased with fix for #63 and #58. Give it a try and let me know.

Phenek commented 5 years ago

👍 Nice Thanks!