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

[Span] Improve formatting inheritance #21191

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

pjcollins
Copy link
Member

@pjcollins pjcollins commented Mar 13, 2024

Fixes: #21034

Label has been updated to set corresponding formatting properties on
its Span children if they are set.

One behavior to mention with respect to iOS is that font attributes can
not be forced on font families that do not support them. The .NET 8
templates use OpenSansRegular as a font family for Labels by default,
and with these changes child spans will now inherit this font family as
well. More context for this behavior is described in issue #1018.

There is some discussion related to Style inheritance in issue #21034,
however this appears to be a more complex issue. Span does not inherit
from Label directly, and as such a style with a target type of Label
can not currently be applied to a Span. This will potentially require
follow up investigation in a separate issue/PR.

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.
@jsuarezruiz jsuarezruiz added platform/android 🤖 platform/iOS 🍎 legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor area-controls-label Label, Span labels Mar 14, 2024
@pjcollins pjcollins changed the title [Span] Improve attribute inheritance [Span] Improve formatting inheritance Mar 19, 2024
@StephaneDelcroix
Copy link
Contributor

StephaneDelcroix commented Mar 29, 2024

If I recall correctly, if a format property isn't set on the Span, it will use the format property of the label

I believe this isn't the right fix for the reported issue

@pjcollins
Copy link
Member Author

If I recall correctly, if a format property isn't set on the Span, it will use the format property of the label

I believe this isn't the right fix for the reported issue

This does appear to be the case for some formatting properties, but there is inconsistency between platforms.

If we compare Android FormattedStringExtensions with iOS FormattedStringExtensions, iOS is missing TextDecorations info from its label, while Android is missing LineHeight when compared to iOS. BackgroundColor is missing from both. The Windows and Tizen cases appear to have similar issues.

In my first look at this I was attempting to address issues at the platform level, and can revisit that if that seems like the more appropriate fix? Assigning values when setting up the Spans felt like a more comprehensive and more easily tested fix though (assuming full inheritance when unset is the behavior we want).

I may also be missing somewhere else where Span gets formatting information from its associated Label?

@PureWeen
Copy link
Member

PureWeen commented Mar 29, 2024

If I recall correctly, if a format property isn't set on the Span, it will use the format property of the label
I believe this isn't the right fix for the reported issue

This does appear to be the case for some formatting properties, but there is inconsistency between platforms.

If we compare Android FormattedStringExtensions with iOS FormattedStringExtensions, iOS is missing TextDecorations info from its label, while Android is missing LineHeight when compared to iOS. BackgroundColor is missing from both. The Windows and Tizen cases appear to have similar issues.

In my first look at this I was attempting to address issues at the platform level, and can revisit that if that seems like the more appropriate fix? Assigning values when setting up the Spans felt like a more comprehensive and more easily tested fix though (assuming full inheritance when unset is the behavior we want).

I may also be missing somewhere else where Span gets formatting information from its associated Label?

Maybe we could add some explicit interfaces to span itself for ITextElement?
https://github.com/dotnet/maui/blob/d7dac41200a932ea748569a28b6f26e7e3df69db/src/Controls/src/Core/Span.cs#L10C2-L10C122

And then if "textcolor" isn't set it returns the "textcolor" from the label. We usually use the interfaces to simplify interaction from the platform level and then use the implementation of it to calculate what the platform needs to know.

@rmarinho
Copy link
Member

Hey just saw this .. seems ifs set a TextColor on my Label, my spans don t respect.

@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
@jsuarezruiz
Copy link
Contributor

Hey just saw this .. seems ifs set a TextColor on my Label, my spans don t respect.

@pjcollins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Child Span does not inherit TextColor or FontAttributes from parent Label
6 participants