-
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
Child Span does not inherit TextColor or FontAttributes from parent Label #21034
Comments
For projects that were created from the net8.0 project template, there is a new There are some behavior differences with |
Fixes: #21034 Span elements are inconsistently inheriting attributes from their parent Label on Android and iOS. Parent TextDecorations would be inherited on Android if unset, but not on iOS. Additionally, neither platform would inherit FontAttributes if unset. Spans on Android and iOS have been updated to use the parent values for TextDecorations and FontAttributes if these values are not set in the Span itself.
Can repro on 17.10 Preview 2.0 with .net8.0 Windows/Android platform, and the solution provided by pjcollins can be solved. |
@pjcollins that looks good - is there a low-key way we can try this solution from your PR e.g. using a handler or would we need to build MAUI ourselves for that? |
I still need to get a test added to the PR, but if you wanted to quickly test the PR build on a machine with a recent .NET 8 MAUI install I think you could do the following:
|
@pjcollins I tried it, but it does not seem to fix the IssueIn this image you see several attempts where the Test cases (corresponding to the labels in the Code section)
Actual behaviorOnly the Expected behavior
CodeTypography.xaml <Style Class="Heading" TargetType="Label">
<Setter Property="FontFamily" Value="PoppinsSemiBold" />
</Style>
<!-- .... -->
<Style Class="Heading04" TargetType="Label">
<Setter Property="FontSize" Value="{x:Static local:Typography.Heading04MobileFontsize}" />
<Setter Property="LineHeight" Value="{x:Static local:Typography.Heading04MobileLineheight}" />
<Setter Property="CharacterSpacing" Value="{x:Static local:Typography.Heading04MobileLetterspacing}" />
<Setter Property="SemanticProperties.HeadingLevel" Value="Level4" />
</Style> Page.xaml <VerticalStackLayout Spacing="{x:Static styles:Spacing.Xsm}">
<Label FormattedText="{Binding Source={x:Static strings:Strings.HeadingPermanentWorkers}, Converter={StaticResource markStringWithColorSpanConverter}, ConverterParameter={x:Static styles:ColorTokens.StaticTextOnBgBrandWeak}}"
StyleClass="Heading, Heading04" />
<Label StyleClass="Heading, Heading04">
<Label.FormattedText>
<FormattedString>
<Span TextColor="{x:Static styles:ColorTokens.StaticTextOnBgBrandWeak}">Permanent</Span>
<Span> workers</Span>
</FormattedString>
</Label.FormattedText>
</Label>
<Label FormattedText="{x:Static strings:Strings.HeadingPermanentWorkers}" StyleClass="Heading, Heading04" />
<Label Text="{x:Static strings:Strings.HeadingPermanentWorkers}"
StyleClass="Heading, Heading04" />
</VerticalStackLayout> |
@hansmbakker I see, this scenario was not outlined in the original issue description. I'll try to take a look at it in the context of this fix, but we may want to file a separate issue to track it eventually. |
Ah, clear. In general I would see
|
@hansmbakker by my understanding the issue you've described above isn't necessary specific to |
@pjcollins I stumbled upon this issue because for our app it was the However, in my opinion it would make sense for a
No, I meant only the (text-related) properties in the documentation section Use formatted text:
Please note that I did not include the properties Other properties from |
With the latest changes in #21191, if |
Description
In Xamarin, child
<Span>
would inherit font properties from the parent<Label>
. In Maui, the child inconsistently inheritsTextDecorations
, but notFontColor
orFontAttributes
(not sure about other attributes).Steps to Reproduce
Expected output:
Text that is blue, bold, and underlined; then text that is green and none of those things
Actual output:
Link to public reproduction project repository
No response
Version with bug
8.0.3 GA
Is this a regression from previous behavior?
Yes, this used to work in Xamarin.Forms
Last version that worked well
Unknown/Other
Affected platforms
Android, I was not able test on other platforms
Affected platform versions
No response
Did you find any workaround?
Copy+paste all label attributes to all of its child spans
Relevant log output
No response
The text was updated successfully, but these errors were encountered: