Skip to content

Fixed the span text disappeared in label when setting the font attribute on span and setting an implicit style for Label on content page #28851

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

NanthiniMahalingam
Copy link
Contributor

@NanthiniMahalingam NanthiniMahalingam commented Apr 8, 2025

Issue details

When setting the FontAttributes in a Span within a Label, and applying an implicit style to the Label (without specifying the FontSize in the style) from the ContentPage resources, while a global default style for label font size is defined in App.xaml, the default font is not applied correctly. Therefore span text disappeared.

Root cause

When setting FontAttributes in a Span within a Label, and applying an implicit style to the Label (without specifying the FontSize) from the ContentPage resources, while a global default style for label font size is defined in App.xaml, the default font is not applied because the implicit style does not explicitly define default FontSize.

Description changes

I retrieved the font size using FontManager.GetFontSize() instead of relying on the default font size from the Label, since font.IsDefault is false when setting FontAttributes in a Span within a Label.

Validated the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Reference

var platformFont = font.IsDefault ? null : font.ToUIFont(fontManager);

Test Case

The issue raises when adding the font size style globally in the application's resource file. As a result, I was unable to apply the global style in the host app, and I couldn't find any reference for applying the style globally.

Issues Fixed

Fixes #19190

Output images:

Before After

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Apr 8, 2025
Copy link
Contributor

Hey there @@NanthiniMahalingam! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Apr 8, 2025
@@ -116,7 +116,7 @@ internal static SpannableString ToSpannableStringNewWay(
if (font.IsDefault && defaultFont.HasValue)
font = defaultFont.Value;
if (!font.IsDefault)
spannable.SetSpan(new PlatformFontSpan(context ?? AAplication.Context, font.ToTypeface(fontManager), font.AutoScalingEnabled, (float)font.Size), start, end, SpanTypes.InclusiveInclusive);
spannable.SetSpan(new PlatformFontSpan(context ?? AAplication.Context, font.ToTypeface(fontManager), font.AutoScalingEnabled, (float)fontManager.GetFontSize(font).Value), start, end, SpanTypes.InclusiveInclusive);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you include a related test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @jsuarezruiz

The issue raises when adding the font size style globally in the application's resource file. As a result, I was unable to apply the global style in the host app, and I couldn't find any reference for applying the style globally.

@NanthiniMahalingam NanthiniMahalingam marked this pull request as ready for review April 10, 2025 13:05
@NanthiniMahalingam NanthiniMahalingam requested a review from a team as a code owner April 10, 2025 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-label Label, Span community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android 🤖
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[regression/8.0.3] Setting a style on a label causes spans with FontAttributes to be ignored on Android
3 participants