-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[android] support more system font names #15759
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Context: dotnet#10713 Context: https://github.com/supershopping/ShellFlyoutLagging In reviewing the above customer sample, I noticed time spent in: 79.52ms microsoft.maui!Microsoft.Maui.Handlers.LabelHandler.MapFont(Microsoft.Maui.Handlers.ILabelHandler,Microsoft.Maui.ILabel) 20.71ms microsoft.extensions.logging.abstractions!Microsoft.Extensions.Logging.LoggerExtensions.LogWarning(Microsoft.Extensions What warning are we trying to log? It seems like it is impacting the time it takes for the first Shell flyout to open. Adding more logging, I found: 06-19 15:31:19.834 5706 5706 I DOTNET : Unable to load font 'sans-serif-medium' from assets. 06-19 15:31:19.840 5706 5706 I DOTNET : Unable to load font 'sans-serif-medium.ttf' from assets. 06-19 15:31:19.840 5706 5706 I DOTNET : Unable to load font 'Fonts/sans-serif-medium.ttf' from assets. 06-19 15:31:19.841 5706 5706 I DOTNET : Unable to load font 'fonts/sans-serif-medium.ttf' from assets. 06-19 15:31:19.841 5706 5706 I DOTNET : Unable to load font 'sans-serif-medium.otf' from assets. 06-19 15:31:19.842 5706 5706 I DOTNET : Unable to load font 'Fonts/sans-serif-medium.otf' from assets. 06-19 15:31:19.842 5706 5706 I DOTNET : Unable to load font 'fonts/sans-serif-medium.otf' from assets. Which is likely just trying to load one of: * https://github.com/dotnet/maui/blob/0543e03cbe7331ae2c106c67a9eaefc575f75945/src/Controls/src/Core/Shell/BaseShellItem.cs#L517 * https://github.com/dotnet/maui/blob/0543e03cbe7331ae2c106c67a9eaefc575f75945/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellItemRenderer.cs#L248 In 2d354d1, we added support for certain Android system fonts. I think we should just expand this further to support various Android fonts like: sans-serif-black sans-serif-condensed sans-serif-condensed-light sans-serif-light sans-serif-medium You can use these in Android such as: android:fontFamily="sans-serif-medium" We can load this `Typeface` from C# such as: Typeface.Create("sans-serif-medium", TypefaceStyle.Normal) See: https://stackoverflow.com/a/14344132 In MAUI apps, customers are likely using a `Fonts/` folder, so if they use these names, they are likely trying to load a system font. After these changes, I see this result on a Pixel 5: Before: 79.52ms microsoft.maui!Microsoft.Maui.Handlers.LabelHandler.MapFont(Microsoft.Maui.Handlers.ILabelHandler,Microsoft.Maui.ILabel) After: 26.91ms microsoft.maui!Microsoft.Maui.Handlers.LabelHandler.MapFont(Microsoft.Maui.Handlers.ILabelHandler,Microsoft.Maui.ILabel) So, I think this saves ~52ms of time for the first Shell flyout opening in this sample.
mattleibow
approved these changes
Jun 20, 2023
PureWeen
reviewed
Jun 20, 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
fixed-in-8.0.0-preview.6.8686
Look for this fix in 8.0.0-preview.6.8686!
platform/android 🤖
t/perf
The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf)
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context: #10713
Context: https://github.com/supershopping/ShellFlyoutLagging
Fixes #13239
In reviewing the above customer sample, I noticed time spent in:
What warning are we trying to log? It seems like it is impacting the time it takes for the first Shell flyout to open.
Adding more logging, I found:
Which is likely just trying to load one of:
maui/src/Controls/src/Core/Shell/BaseShellItem.cs
Line 517 in 0543e03
maui/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellItemRenderer.cs
Line 248 in 0543e03
In 2d354d1, we added support for certain Android system fonts. I think we should just expand this further to support various Android fonts like:
You can use these in Android such as:
We can load this
Typeface
from C# such as:See: https://stackoverflow.com/a/14344132
In MAUI apps, customers are likely using a
Fonts/
folder, so if they use these names, they are likely trying to load a system font.After these changes, I see this result on a Pixel 5:
So, I think this saves ~52ms of time for the first Shell flyout opening in this sample.