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

Replace Shell sans-serif-medium magic string on Android #13544

Closed
wants to merge 1 commit into from

Conversation

jfversluis
Copy link
Member

Description of Change

In 3 places which had to do with Shell and/or TabbedPage we had a reference to sans-serif-medium as a string. This was causing exceptions, from what I can tell, on all Android devices and throwing underwater exceptions that the font could not be loaded.

I've changed these references to the TypeFace.SansSerif which is built-in and assume that it resolves to the same. From a visual test I don't see any differences.

Thinking about it, there will probably be no differences, since the font couldn't be loaded earlier, it would not have shown as it was intended in the first place.

Unfortunately, I couldn't really find any definitive source on if this was removed on Android at some point or what the cause is that we are seeing this now.

Preferably I'd like @PureWeen to have a look being the one most likely to have implemented this

Issues Fixed

Fixes #13239

@jfversluis jfversluis added t/bug Something isn't working platform/android 🤖 area-fonts Custom fonts and Font related API's labels Feb 24, 2023
@jfversluis jfversluis requested a review from PureWeen February 24, 2023 13:01
@mandel-macaque
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. What device were you running this on? I know I've seen this exception before, but I just tested on a few emulators and I'm not seeing the issue happen.

  2. I noticed that on simulators (API 23 and API 30) that the font looked different with your change vs before your change. So, I'm still just trying to understand and track why that is.

Here's a pic.
Left is this PR and right is without this PR

image

@jfversluis
Copy link
Member Author

I'd have to check in the actual device/emulators I've seen this on.

I think I have an answer to the "why" though.

I replaced it with SansSerif and not medium (because it's not in there) and the magic string had medium. So somehow we need to replicate that better then? Or maybe try to pin down on which devices this is happening exactly and maybe make it so that it applies the current way to devices where it works and the "new" way to devices where it gives the exception?

@@ -511,7 +511,6 @@ internal static DataTemplate CreateDefaultFlyoutItemCell(string textBinding, str

defaultLabelClass.Setters.Add(new Setter { Property = Label.FontSizeProperty, Value = 14 });
defaultLabelClass.Setters.Add(new Setter { Property = Label.TextColorProperty, Value = textColor });
defaultLabelClass.Setters.Add(new Setter { Property = Label.FontFamilyProperty, Value = "sans-serif-medium" });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the only one that throws from the magic string because the way we load magic strings on Label is by consulting the assets first and then it falls back to the Typeface call :-/

I wonder if there's a way we can change it to not throw so many times or know we need to not consult the assets.

@PureWeen
Copy link
Member

PureWeen commented Mar 3, 2023

I'd have to check in the actual device/emulators I've seen this on.

I think I have an answer to the "why" though.

I replaced it with SansSerif and not medium (because it's not in there) and the magic string had medium. So somehow we need to replicate that better then? Or maybe try to pin down on which devices this is happening exactly and maybe make it so that it applies the current way to devices where it works and the "new" way to devices where it gives the exception?

I think the main place this exception comes from is the label. The code inside the BottomNavigationUtils works fine and doesn't throw with the magic string. When Label first attempts to load the font it consults the Assets. If that fails, then it uses Typeface.Create which succeeds for the magic string.

image

This is really a problem for any font that a user uses that's not part of our assets but will load as part of the OS fonts.

Ideally, we could fix this for all magic strings. Maybe there's a way we can just fix this for the default Shell path though. Maybe we can add a controls level mapper just for this font type? Not too sure.... Maybe there's some set of magic strings we can create a magic string list for that don't consult the assets?

text.Typeface = services.GetRequiredService<IFontManager>()
.GetTypeface(Font.OfSize("sans-serif-medium", 0.0));

text.SetTypeface(Typeface.SansSerif, TypefaceStyle.Normal);
Copy link
Member

@PureWeen PureWeen Mar 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just delete this entire method? It's marked obsolete.

And from my tests it's never called.

@jfversluis jfversluis marked this pull request as draft March 6, 2023 15:11
@jfversluis
Copy link
Member Author

Converting to draft while we talk more about this one

@Rabosa616
Copy link

Hi @jfversluis @PureWeen Any news here?

@jfversluis
Copy link
Member Author

@Rabosa616 not really unfortunately. We found that, despite the exception, this code actually does do something. So this PR isn't the right fix and I still need to get back to this to determine what is the right approach here.

@Rabosa616
Copy link

Hi @jfversluis
I can see that this error only happend to me when I added the builder.Logging.AddDebug(); in MaiuProgram, removing it I do not get the error.

@janseris
Copy link

janseris commented Apr 8, 2023

Hi @jfversluis I can see that this error only happend to me when I added the builder.Logging.AddDebug(); in MaiuProgram, removing it I do not get the error.

Same here. Confirming.

@jfversluis
Copy link
Member Author

From what I can tell this is fixed by #15759, this isn't needed anymore

@jfversluis jfversluis closed this Jul 3, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-fonts Custom fonts and Font related API's platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Microsoft.Maui.FontManager: Warning: Unable to load font 'sans-serif-medium' from assets.
6 participants