xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] Custom font not displaying correctly when loading the page again #6666

Open NickeManarin opened 5 years ago

NickeManarin commented 5 years ago

Description

I'm trying to use a custom glyph font. It works the first time that the View appears, but the second time a rectangle with a X inside will be rendered instead.

Steps to Reproduce

  1. I simply created a font online using the IconMoon web app.
  2. I added the font to the Android project normally, adding as AndroidAsset.
  3. I created a simple IconLabel extending Label.
  4. After that I added two resources in the App.xaml file:
<OnPlatform x:Key="Font.Glyph" x:TypeArguments="x:String">
     <On Platform="Android" Value="Fonts/project_icons.ttf#ProjectIcons"/>
     <On Platform="iOS" Value="ProjectIcons"/>
 </OnPlatform>
<Style TargetType="{x:Type n:IconLabel}">
    <Setter Property="FontFamily" Value="{StaticResource Font.Glyph}"/>
    <Setter Property="FontSize" Value="40"/>
    <Setter Property="TextColor" Value="{DynamicResource Color.Foreground}"/>
</Style>
  1. I have a ContentPage that displays multiple ContentViews. When changing the content view being displayed (back and forth), after the displaying the glyphs correctly one time, all subsequent displays will have the incorrect glyph.

Basic Information

Screenshots

This is the result: Screenshot_20190626-135623

Reproduction Link

Not yet...

NickeManarin commented 5 years ago

It has something to do with the previous view being displayed. I have to do more tests.

toomasz commented 5 years ago

Duplicate of https://github.com/xamarin/Xamarin.Forms/issues/6317 See my comment for workaround

NickeManarin commented 5 years ago

@toomasz Is it? Because mine is a simple Label, not a FontImageSource. Btw, I noticed that it only happens when going back and forth displaying the previous View in which it contains a dragabble list view by the Sharpnado nuget and images from FFImageLoading nuget.

For example, if I go to the next view and go back to the view that displays the label from the picture, it will work normally.

andreinitescu commented 5 years ago

@NickeManarin I strongly suggest you attach a sample which reproduces the issue in order to increase the chance of getting it fixed. I know, I know, it's boring but it's worth it 👌.

NickeManarin commented 5 years ago

@andreinitescu Yes, that was my original idea. But since the project is closed source, I need to create a sample project that simulates the issue. I'm going to do that in the following days.

James3UK commented 5 years ago

@NickeManarin Try the fix here https://github.com/xamarin/Xamarin.Forms/issues/6317#issuecomment-498358580 if it fixes the issue then it's a duplicate as mentioned above.

NickeManarin commented 5 years ago

It happened something worse, now the icons inside a FontImageSource (inside a button) are gone. But... I'm not experiencing the issue with the faulty icon anymore with the IconLabel (that extends a Label).

NickeManarin commented 5 years ago

At first I thought it could be something related to the fact that my button was invisible at first (but later was being displayed), but I tested on a button that is always visible... Same issue.

jsuarezruiz commented 5 years ago

Duplicate of #6317. @NickeManarin if you think it's different, add a comment. And if you can a repro sample ;)

NickeManarin commented 5 years ago

So, here's the test project: https://github.com/NickeManarin/Xamarin.Demos2

There's two files in which I want you people to see:

Both have commented lines, right above the namespace declaration.

  1. Now, run the Android project and click on the blue Options button.
  2. It should open a sliding dialog with two kinds of icons: One "close" icon using the FontIconLabel class and other two buttons using the FontImageSource.
  3. Click on the background to dismiss the dialog, and open again. It should see that the red "close" icon is faulty (a rectangle with an X inside).
  4. Now, uncomment the code inside the FontImageSourceHandler class.
  5. Run again, open the same dialog as before.
  6. Notice that the icons are missing in the buttons (FontImageSource), but the FontIconLabel now no longer fails to render the icon.
  7. Now, comment again the code from the FontImageSourceHandler class and uncomment the one inside the FontIconLabelRenderer.
  8. Test again.

So, the only way to solve this issue for me was to create a label renderer that sets its Font manually.

jsuarezruiz commented 5 years ago

Thanks for the sample!. Yes, I see the problem.

James3UK commented 5 years ago

@NickeManarin I built a custom nuget based on https://github.com/xamarin/Xamarin.Forms/issues/6317 / https://github.com/xamarin/Xamarin.Forms/pull/6470 and it does seem to fix your issue. Give it a try and confirm if that is the case? Xamarin.Forms.9.9.16.zip

jfversluis commented 5 years ago

@NickeManarin would you be able to have another look with the latest Xamarin.Forms version?

According to issue #6317 this is likely to be fixed now. Would be great if you could verify that this fixes it for you as well and close the issue accordingly, thanks!

ArgusMagnus commented 5 years ago

The bug is fixed for most controls in the latest Xamarin version, but this is still an issue, when a FontImageSource is used as Shell.FlyoutIcon or SearchHandler.QueryIcon.