xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.63k stars 1.88k forks source link

Setting FontAttribute on a Span makes it ignore FontSize from the parent Label #3901

Open GalaxiaGuy opened 5 years ago

GalaxiaGuy commented 5 years ago

I originally posted this as comments here: https://github.com/xamarin/Xamarin.Forms/issues/2168 , based on one of the other comments. I now think this is separate to the original issue there.

Description

Setting FontAttribute on a Span makes the span ignore FontSize on the parent Label.

Steps to Reproduce

Create a label like the following:

<Label FontSize="30">
    <Label.FormattedText>
        <FormattedString>
            <Span FontAttributes="Bold">Bold</Span>
        </FormattedString>        
    </Label.FormattedText>
</Label>

Expected Behavior

The bold text has font size 30.

Actual Behavior

The bold text has default font size.

Basic Information

Tested explicitly on 3.1.0.697729, 3.2.0.839982 and 3.3.0.840541-pre1 on Android and iOS, but I think it has always been this way.

Screenshots

Reproduction Link

https://github.com/GalaxiaGuy/XF-FormattedText-Bug https://github.com/GalaxiaGuy/XF-FormattedText-Bug/archive/master.zip

Copied from my comments on #2168

I assume the problem is to do with font properties sometimes being separate things and sometimes not. Here for instance: https://github.com/xamarin/Xamarin.Forms/blob/bd31e1e9fc8b2f9ad94cc99e0c7ab058174821f3/Xamarin.Forms.Platform.Android/Renderers/FormattedStringExtensions.cs#L63) The Android spannable gets the Font of the Span, which obviously doesn't consider any properties of the Label.

It looks kind of messy to fix. Copying the properties from the label to the span is easy in theory, but it looks like there is no easy way to see if the span has had it's font size explicitly set.

And it has existed long enough it might be a compatibility issue.

davidortinau commented 5 years ago

yup, just discovered this myself.