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

IOS: Custom font icon is not rendered in a shell tabbar tab #8244

Closed
lnaie opened this issue Jun 22, 2022 · 35 comments · Fixed by #22437
Closed

IOS: Custom font icon is not rendered in a shell tabbar tab #8244

lnaie opened this issue Jun 22, 2022 · 35 comments · Fixed by #22437
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout has-workaround p/2 Work that is important, but is currently not scheduled for release platform/iOS 🍎 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@lnaie
Copy link

lnaie commented Jun 22, 2022

Description

Did attach some screenshots and a code sample.

android_emul_sample
Screenshot 2022-06-22 at 16 52 40

MauiApp3.zip

Steps to Reproduce

  1. It's all in the sample code.

Version with bug

6.0.400 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 15

Did you find any workaround?

No response

Relevant log output

No response

@lnaie lnaie added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels Jun 22, 2022
@Eilon Eilon added the area-controls-shell Shell Navigation, Routes, Tabs, Flyout label Jun 22, 2022
@PureWeen PureWeen added platform/android 🤖 and removed s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels Jun 22, 2022
@kristinx0211 kristinx0211 added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jun 23, 2022
@kristinx0211
Copy link

verified repro on IOS15.4 with vs 17.3.0 Preview 3.0 [32621.293.main].

@ghost
Copy link

ghost commented Aug 30, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@legrignotin
Copy link

I am having the same problem too :/

Actually they are rendered, the color is just white on white...
If you force a color on the glyph you'll see it but you'll lose the selected item style, disabled style etc...

@NPadrutt
Copy link

I'm at the same point as @legrignotin.
It's a bit surprising to me that this is open for so long and now moved to the backlog (as is the issue with the TitleView) as those are small details that make an app look very unpolished.

@yurkinh
Copy link
Contributor

yurkinh commented Oct 20, 2022

Checked this issue with Maui in NET 7 RC2 an it is still present(

@NPadrutt
Copy link

Has this issue any relation with the issue that images on iOS are blurry when a page is first rendered?

@phookycom
Copy link

Is there any news on this? Unfortunately, the problem was not solved with NET 7.0 GA. And explicitly specifying the color of the TabIcon is not a solution, because the behavior of the tabs is then no longer dynamic.

<FontImageSource FontFamily="FontAwesomeSolid" Glyph="&#xf0fc;" Size="22" Color="{StaticResource Primary}" />

@KieranMaclagan
Copy link

We're affected by this too. If I'm remembering correctly it was an issue in Xamarin Forms as well. A fix would add some nice polish to MAUI!

@andrei25f
Copy link

andrei25f commented Nov 18, 2022

In the attached project (MauiApp3.zip), сhange this:
<Tab Route="main" Title="Home">
<Tab.Icon>
<FontImageSource FontFamily="MD" Glyph="{x:Static res:IconFont.HomeOutline}" Size="24"/>
</Tab.Icon>
<ShellContent ContentTemplate="{DataTemplate local:MainPage}" />
</Tab>
To:
<Tab Title="Home" Icon="{FontImage Color=Black, FontFamily=MD, Glyph={x:Static res:IconFont.HomeOutline}, Size=24}">
<ShellContent ContentTemplate="{DataTemplate local:MainPage}" Route="main" />
</Tab>
test

@Adelzu
Copy link

Adelzu commented Nov 20, 2022

In the attached project (MauiApp3.zip), сhange this:
<Tab Route="main" Title="Home">
<Tab.Icon>
<FontImageSource FontFamily="MD" Glyph="{x:Static res:IconFont.HomeOutline}" Size="24"/>
</Tab.Icon>
<ShellContent ContentTemplate="{DataTemplate local:MainPage}" />
</Tab>
To:
<Tab Title="Home" Icon="{FontImage Color=Black, FontFamily=MD, Glyph={x:Static res:IconFont.HomeOutline}, Size=24}">
<ShellContent ContentTemplate="{DataTemplate local:MainPage}" Route="main" />
</Tab>
test

By specifying black as the icon color, you just lost dark theme

@am-kh
Copy link

am-kh commented Jan 21, 2023

Any news on this??

@NPadrutt
Copy link

NPadrutt commented Jan 22, 2023

Still waiting on a fix for this too. Given it is still on the backlog, I don't think there was a lot of progress yet.

@rysbilinski
Copy link

rysbilinski commented Jan 25, 2023

@NPadrutt @am-kh

If it helps anyone, I managed to workaround this using styles and triggers

<Tab Title="Inbox" FlyoutItemIsVisible="False" Icon="{FontImage FontFamily=Material, Glyph={x:Static font:MaterialFontIcons.Notifications}}" Route="NotificationsPage" Style="{OnPlatform iOS={StaticResource notificationsTab}}"> <ShellContent ContentTemplate="{DataTemplate views:NotificationsPage}" /> </Tab>

Then the style:

<Style x:Key="notificationsTab" TargetType="Tab"> <Style.Triggers> <Trigger TargetType="Tab" Property="IsChecked" Value="True"> <Setter Property="Icon" Value="{FontImage FontFamily=Material, Glyph={x:Static font:MaterialFontIcons.Notifications}, Color={StaticResource SecondaryDark}}" /> </Trigger> <Trigger TargetType="Tab" Property="IsChecked" Value="False"> <Setter Property="Icon" Value="{FontImage FontFamily=Material, Glyph={x:Static font:MaterialFontIcons.Notifications}, Color={StaticResource Gray200}}" /> </Trigger> </Style.Triggers> </Style>

image

@NPadrutt
Copy link

thanks @rysbilinsk! The only issue I have with this, is that I would have to have different colors for different themes. I tried using an AppThemeBinding for Color:

                <Trigger TargetType="Tab" Property="IsChecked" Value="True">
                    <Setter Property="Icon"
                            Value="{FontImage FontFamily=MaterialIcons, Glyph={x:Static views:IconFont.HomeOutline}, Color={AppThemeBinding Light={StaticResource Gray950}, Dark={StaticResource White}}}" />
                </Trigger>

But that gives me an error, that there is no property for Color. Before I used an FontImageSource, but I haven't found out how to use that in the style yet. In case you know how to solve that I'd greatly appreciate any hint :)

@rysbilinski
Copy link

thanks @rysbilinsk! The only issue I have with this, is that I would have to have different colors for different themes. I tried using an AppThemeBinding for Color:

                <Trigger TargetType="Tab" Property="IsChecked" Value="True">
                    <Setter Property="Icon"
                            Value="{FontImage FontFamily=MaterialIcons, Glyph={x:Static views:IconFont.HomeOutline}, Color={AppThemeBinding Light={StaticResource Gray950}, Dark={StaticResource White}}}" />
                </Trigger>

But that gives me an error, that there is no property for Color. Before I used an FontImageSource, but I haven't found out how to use that in the style yet. In case you know how to solve that I'd greatly appreciate any hint :)

have to be honest I am forcing my app to only have light theme for now.

Could you maybe have the app theme binding on a resource dictionary? And have a resource dictionary containing the different themes for each file? Or just duplicate the themes for dark and light and apply the app theme binding on the style in the tab item?

@arahmancsd
Copy link

Finally, I fixed mine with this approach and it works as expected in iOS

<Tab Title="Discover">
            <Tab.Style>
                <Style TargetType="Tab">
                    <Style.Triggers>
                        <Trigger TargetType="Tab" Property="IsChecked" Value="True">
                            <Setter Property="Icon">
                                <Setter.Value>
                                    <FontImageSource Size="20" Color="{DynamicResource Primary}"
                                                     Glyph="{x:Static util:FontAwesomeIcons.Home}"
                                                     FontFamily="Fas"/>
                                </Setter.Value>
                            </Setter>
                        </Trigger>

                        <Trigger TargetType="Tab" Property="IsChecked" Value="False">
                            <Setter Property="Icon">
                                <Setter.Value>
                                    <FontImageSource Size="20" Color="{AppThemeBinding Light={StaticResource Gray900}, Dark={StaticResource Gray200}}"
                                                     Glyph="{x:Static util:FontAwesomeIcons.Home}" FontFamily="Fas"/>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Tab.Style>
            <ShellContent ContentTemplate="{DataTemplate homeTabViews:HomePage}"/>
        </Tab>

@NPadrutt
Copy link

Finally, I fixed mine with this approach and it works as expected in iOS

<Tab Title="Discover">
            <Tab.Style>
                <Style TargetType="Tab">
                    <Style.Triggers>
                        <Trigger TargetType="Tab" Property="IsChecked" Value="True">
                            <Setter Property="Icon">
                                <Setter.Value>
                                    <FontImageSource Size="20" Color="{DynamicResource Primary}"
                                                     Glyph="{x:Static util:FontAwesomeIcons.Home}"
                                                     FontFamily="Fas"/>
                                </Setter.Value>
                            </Setter>
                        </Trigger>

                        <Trigger TargetType="Tab" Property="IsChecked" Value="False">
                            <Setter Property="Icon">
                                <Setter.Value>
                                    <FontImageSource Size="20" Color="{AppThemeBinding Light={StaticResource Gray900}, Dark={StaticResource Gray200}}"
                                                     Glyph="{x:Static util:FontAwesomeIcons.Home}" FontFamily="Fas"/>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Tab.Style>
            <ShellContent ContentTemplate="{DataTemplate homeTabViews:HomePage}"/>
        </Tab>

This solution works for me on iOS, but has weird side effects on Android.

@samhouts samhouts removed s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Apr 5, 2023
@jinxinjuan jinxinjuan added s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage labels May 17, 2023
@ewerspej
Copy link

ewerspej commented Oct 6, 2023

Is there any update on this issue?

@arnaudaug
Copy link

In addition to the solution proposed above with triggers, in the meantime if it helps you, I use this code in App.xaml.cs :

Current.MainPage = DeviceInfo.Platform == DevicePlatform.iOS || DeviceInfo.Platform == DevicePlatform.MacCatalyst ? new AppShellApple() : new AppShell();

@SliemBeji-FBC
Copy link

Unfortunately still a problem :( WE ARE ALSO AFFECTED

@zippo227
Copy link

Here is a complete solution that works for both. I have configured the Android theme in the Resources folder so didn't add the Android styling.

    <On Platform="Android">
        <TabBar>
            
            <Tab Title="My Day">
                <ShellContent ContentTemplate="{DataTemplate todayTab:MyDayPage}" />
                <Tab.Icon>
                    <FontImageSource Glyph="{x:Static util:FontAwesomeIcons.Check}" FontFamily="Fas"/>
                </Tab.Icon>
            </Tab>
            ....
        </TabBar>
    </On>

    <On Platform="iOS">
            <TabBar>

                <Tab Title="My Day">
                    <ShellContent ContentTemplate="{DataTemplate todayTab:MyDayPage}"/>

                    <Tab.Style>
                        <Style TargetType="Tab">
                            <Style.Triggers>
                                <Trigger TargetType="Tab" Property="IsChecked" Value="True">
                                    <Setter Property="Icon">
                                        <Setter.Value>
                                            <FontImageSource Size="20"
                                                         Color="{DynamicResource Primary}"
                                                 Glyph="{x:Static util:FontAwesomeIcons.Check}"
                                                 FontFamily="Fas"/>
                                        </Setter.Value>
                                    </Setter>
                                </Trigger>

                                <Trigger TargetType="Tab" Property="IsChecked" Value="False">
                                    <Setter Property="Icon">
                                        <Setter.Value>
                                            <FontImageSource Size="20" Color="{AppThemeBinding Light={StaticResource Gray900}, Dark={StaticResource Gray200}}"
                                                 Glyph="{x:Static util:FontAwesomeIcons.Check}"
                                                 FontFamily="Fas"/>
                                        </Setter.Value>
                                    </Setter>
                                </Trigger>
                            </Style.Triggers>
                        </Style>

                    </Tab.Style>
                </Tab>

            </TabBar>
             ....
        </On>
</OnPlatform>

This solution did resolve my issues on iOS, though the OnPlatform parts had compile time issues for me. In my case the settings for android are mostly unaffected by the settings in here, so I do not, as of yet require setting OnPlatform.

I do hope the maui team is able to find a way to remove the requirement for this on iOS.

@samhouts samhouts added the p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint label Dec 19, 2023
@bcaceiro
Copy link

Also the sizes are completely screwed using icon fonts

@matt-goldman
Copy link
Contributor

matt-goldman commented Feb 9, 2024

Seem to be having the same problem with Flyout. And the workaround doesn't work as the IsChecked property doesn't get set. According to the docs we should do this on the Selected state using VisualStateManager, but I couldn't get it working.

@softlion
Copy link
Contributor

softlion commented Mar 14, 2024

Same issue with TabbedPage. No xaml workaround as a page don't have IsChecked property.

@MitchBomcanhao
Copy link

MitchBomcanhao commented Mar 14, 2024

Same issue with TabbedPage. No xaml workaround as a page don't have IsChecked property.

@softlion check #12250 (comment) for a workaround to get icons displayed on tabbedpages.

@softlion
Copy link
Contributor

softlion commented Mar 14, 2024

Same issue with TabbedPage. No xaml workaround as a page don't have IsChecked property.

@softlion check #12250 (comment) for a workaround to get icons displayed on tabbedpages.

It's not for iOS, it's both Android and iOS. I actually experience the issue on Android.

Here is my workaround:

public class TabbedPage2 : TabbedPage
{
 protected override void OnPagesChanged(NotifyCollectionChangedEventArgs e)
    {
        base.OnPagesChanged(e);
        
        
        if (e is { Action: NotifyCollectionChangedAction.Add, NewItems: not null })
        {
            foreach (var page in e.NewItems.OfType<Page>())
                FixIconColor(page);
        }
    }

    /// <summary>
    /// Workaround for  https://github.com/dotnet/maui/issues/8244
    /// </summary>
    private void FixIconColor(Page page)
    {
        if(page.IconImageSource is SvgImageSource imageSource)
        {
            imageSource.ColorMapping = [
                new() { OldColor = Colors.Black, NewColor = UnselectedTabColor},
                new() { OldColor = Colors.White, NewColor = UnselectedTabColor},
            ];
            page.IconImageSource = null;
            page.IconImageSource = imageSource;

            var selectedImageSource = new SvgImageSource
            {
                Source = imageSource.Source,
                Height = imageSource.Height,
                ColorMapping = [new() { OldColor = Colors.Black, NewColor = SelectedTabColor }],
            };
            
            var selectedPageStyle = new Style(typeof(Page)) { ApplyToDerivedTypes = true };
            selectedPageStyle.Triggers.Add(new DataTrigger(typeof(Page))
            {
                Binding = new Binding(nameof(CurrentPage), source: this),
                Value = page,
                Setters = {{ IconImageSourceProperty, selectedImageSource }}
            });
            page.Style = selectedPageStyle;
        }
    }
}

It uses SvgImageSource but you can do the same for any type of source.

Ty @MitchBomcanhao !

@MitchBomcanhao
Copy link

well, this bug is about iOS, so it would seem that your android issue would be a different one.

@zaidmka
Copy link

zaidmka commented Apr 9, 2024

i had this bug as well
`
<Shell
x:Class="TeaStoreApp.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TeaStoreApp"
xmlns:pages="clr-namespace:TeaStoreApp.Pages"
Shell.FlyoutBehavior="Disabled"
Shell.TabBarBackgroundColor="#18565F"
Shell.TabBarTitleColor="Red"
Shell.TabBarUnselectedColor="Green"

>

<TabBar>
    <Tab Title="Home" Icon="home_25">
        <ShellContent ContentTemplate="{DataTemplate pages:HomePage}"/>
    </Tab>

    <Tab Title="Cart" Icon="cart_25">
        <ShellContent ContentTemplate="{DataTemplate pages:CartPage}"/>
    </Tab>

    <Tab Title="Favorites" Icon="heart_25">
        <ShellContent ContentTemplate="{DataTemplate pages:FavoritePage}"/>
    </Tab>

    <Tab Title="Profile" Icon="profile_25">
        <ShellContent ContentTemplate="{DataTemplate pages:ProfilePage}"/>
    </Tab>
</TabBar>
` this is the AppShell its act deferentin iOS and Android ![Screenshot 2024-04-09 223053](https://github.com/dotnet/maui/assets/83184605/4ea64445-ea00-4890-81ae-4aa0723f8670) ![Screenshot 2024-04-09 223044](https://github.com/dotnet/maui/assets/83184605/9c10874d-d71f-462e-96b6-9fb1d299c226) also i cant adjust the bar heigh!

@tscholze
Copy link

I stumbled across this, too. Commenting for update information

@ewerspej
Copy link

I stumbled across this, too. Commenting for update information

@tscholze You can also subscribe to posts without commenting ;) JFYI

@tscholze
Copy link

@ewerspej a thanks I totally forgot it. I really hope that experts like you can fix this issue soon. :)

@ewerspej
Copy link

ewerspej commented Apr 15, 2024

@tscholze I'm actually not a member of the development team, but I'm looking for workarounds while it's not fixed. I'm not that deep into the internals of MAUI yet.

@breyed
Copy link
Contributor

breyed commented May 25, 2024

StackOverflow post on issue (with additional workaround)

@samhouts
Copy link
Member

We agree that this is an important issue. As our roadmap indicates, for the near future, we are focused on:

  • Issues impacting Xamarin.Forms upgrades to .NET MAUI
  • CollectionView
  • Layout

I am marking this as a p/2 issue because it does not meet our focus areas right now, but we are constantly revisiting the backlog for important issues to address as time allows. Thank you for your patience and understanding!

@samhouts samhouts added p/2 Work that is important, but is currently not scheduled for release has-workaround and removed p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint labels Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout has-workaround p/2 Work that is important, but is currently not scheduled for release platform/iOS 🍎 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet