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

BottomBarPageExtensions.SetBadgeCount doesn't work on iOS #87

Open
mosflex opened this issue Dec 19, 2017 · 2 comments
Open

BottomBarPageExtensions.SetBadgeCount doesn't work on iOS #87

mosflex opened this issue Dec 19, 2017 · 2 comments

Comments

@mosflex
Copy link

mosflex commented Dec 19, 2017

BottomBarPageExtensions.SetBadgeCount work on Android but not iOS. I forgot something ?

@tahirmehraj
Copy link

Do you found any Solution for this as I am stuck with the same!

@shivanimangla13
Copy link

Add custom renderer for iOS. It worked for me :) .

"using System;
using BottomBar.XamarinForms;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using SchoolApp.iOS;
using System.ComponentModel;

[assembly: ExportRenderer(typeof(BottomBarPage), typeof(BottomBarPageRenderer))]
namespace SchoolApp.iOS
{
class BottomBarPageRenderer : TabbedRenderer
{

protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
    base.OnElementChanged(e);

    if (e.NewElement != null)
    {
        BottomBarPage bottomBarPage = e.NewElement as BottomBarPage;
        AddPropertyChangedHandlersForPages();
    }
}

void AddPropertyChangedHandlersForPages()
{
    BottomBarPage bottomBarPage = Element as BottomBarPage;
    foreach (var page in bottomBarPage.Children)
    {
        page.PropertyChanged += OnPagePropertyChanged;
        UpdateTabBadge(page);
    }
}
public override void ViewWillAppear(bool animated)
{
    base.ViewWillAppear(animated);

    BottomBarPage bottomBarPage = Element as BottomBarPage;
    foreach (var page in bottomBarPage.Children)
    {
        UpdateTabBadge(page);
    }
}

void OnPagePropertyChanged(object sender, PropertyChangedEventArgs e)
{
    if (e.PropertyName == BottomBarPageExtensions.BadgeCountProperty.PropertyName)
    {
        UpdateTabBadge((Page)sender);
    }
}
private void UpdateTabBadge(Page page)
{
    if (TabBar != null && TabBar.Items != null)
    {
        var badgeCount = BottomBarPageExtensions.GetBadgeCount(page);
        var tabIndex = Tabbed.Children.IndexOf(page);
        TabBar.Items[tabIndex].BadgeValue = (badgeCount == 0 ? null : badgeCount.ToString());
    }
}

}
}
"

screen shot 2018-07-03 at 3 34 54 pm

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

No branches or pull requests

3 participants