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

Support for Font Icons #308

Open
donniefitz2 opened this issue May 8, 2020 · 4 comments
Open

Support for Font Icons #308

donniefitz2 opened this issue May 8, 2020 · 4 comments
Assignees

Comments

@donniefitz2
Copy link

Now that Xamarin supports font icons, would it be possible to support font icons in the tabbed navigation container? So, instead of passing an icon name, I'd like to be able to pass a font icon name for the tab icons. Looking for guidance on this.

@rid00z
Copy link
Owner

rid00z commented May 8, 2020

We can add this as a feature but if you need it now then you can inherit the tabbed container.

@rid00z rid00z self-assigned this May 8, 2020
@donniefitz2
Copy link
Author

Thanks for the quick reply. I'll dig into creating my own tabbed container. If all goes well, I'll submit a PR.

@protokovich
Copy link

protokovich commented Jun 17, 2020

using System.Collections.Generic;
using FreshMvvm;
using Xamarin.Forms;

namespace RmedAgent3
{
    //
    public class MyTabbedNavigationContainer: FreshTabbedNavigationContainer
    {
        public Page AddTab<T>(string title, ImageSource imageSource, object data = null) where T : FreshBasePageModel
        {
            Page page = FreshPageModelResolver.ResolvePageModel<T>(data);
            page.GetModel().CurrentNavigationServiceName = NavigationServiceName;

            var tabs = TabbedPages as List<Page>;
            tabs.Add(page);
            Page page2 = MyCreateContainerPageSafe(page);
            page2.Title = title;
            if (imageSource != null && !imageSource.IsEmpty)
            {
                //page2.Icon = icon;
                page2.IconImageSource = imageSource;
            }
            base.Children.Add(page2);
            return page2;
        }

        public Page MyCreateContainerPageSafe(Page page)
        {
            if (page is NavigationPage || page is MasterDetailPage || page is TabbedPage)
            {
                return page;
            }

            return CreateContainerPage(page);
        }
    }
}

usage:

public App()
{
    //RegisterSampleServices();
    RegisterServices();

    InitializeComponent();

    //MainPage = new MainPage();
    /*
    var loginPage = FreshPageModelResolver.ResolvePageModel<LoginPageModel>();
    MainPage = loginPage;
    */

    var mainPage = new MyTabbedNavigationContainer();

    mainPage.AddTab<HomePageModel>("Главная"  , GetMaterialIconSource(MaterialIcons.Home));
    mainPage.AddTab<HomePageModel>("Задания", GetMaterialIconSource(MaterialIcons.Inbox));
    mainPage.AddTab<HomePageModel>("Заявки", GetMaterialIconSource(MaterialIcons.Assignment));
    mainPage.AddTab<HomePageModel>("Сканер", GetMaterialIconSource(MaterialIcons.CenterFocusStrong));
    mainPage.AddTab<HomePageModel>("Еще" , GetMaterialIconSource(MaterialIcons.MoreHoriz));
    

    mainPage.On<Xamarin.Forms.PlatformConfiguration.Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);
    mainPage.BarTextColor = Color.White;
    mainPage.BarBackgroundColor = App.GetColor("BrandColor");
    mainPage.SelectedTabColor = Color.White;
    mainPage.UnselectedTabColor = App.GetColor("UnselectedTabColor");

    MainPage = mainPage;
}

public FontImageSource GetMaterialIconSource(string iconName)
{
    return new FontImageSource()
    {
        FontFamily = (string) Application.Current.Resources["MaterialFont"]
        , Glyph = iconName,
    };
}

result:


tabbedpage_bottom_font_icons

@donniefitz2
Copy link
Author

@protokovich Thanks for posting this. I meant to do the same but had other priorities.

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