xamarin/Xamarin.Forms

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

Open

#3,901 opened on Sep 26, 2018

 (1 comment) (1 reaction) (0 assignees)C# (1,926 forks)batch import
e/5 :clock5:help wantedinactivet/bug :bug:up-for-grabs

Repository metrics

Stars
 (5,644 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

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.

Contributor guide