Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[iOS] TextDecoration Strikethrough not working on iOS together with LineHeight #11928

Merged
merged 6 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using Xamarin.Forms.Internals;
using Xamarin.Forms.CustomAttributes;

#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be automated with a platform test on iOS - we can verify that the Control's AttributedText has the strikethrough attribute after the Label has LineHeight and TextDecoration set.

[Category(UITestCategories.Label)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 11829,
"[Bug] TextDecoration Strikethrough not working on iOS together with LineHeight",
PlatformAffected.All)]
public class Issue11829 : TestContentPage
{
public Issue11829()
{

}

protected override void Init()
{
Title = "Issue 11829";

var layout = new StackLayout();

var instructions = new Label
{
Padding = 12,
BackgroundColor = Color.Black,
TextColor = Color.White,
Text = "If the text below is underline & strike through, the test has passed."
};

var label = new Label
{
TextDecorations = TextDecorations.Underline | TextDecorations.Strikethrough,
LineHeight = 2,
Text = "Underline using LineHeight",
Margin = new Thickness(0, 12)
};

var textDecorationsLayout = new StackLayout
{
Orientation = StackOrientation.Horizontal
};

var textDecorationsCheckBox = new CheckBox
{
IsChecked = true,
VerticalOptions = LayoutOptions.Center
};

var textDecorationsText = new Label
{
Text = "Underline",
WidthRequest = 100,
VerticalOptions = LayoutOptions.Center
};

textDecorationsLayout.Children.Add(textDecorationsText);
textDecorationsLayout.Children.Add(textDecorationsCheckBox);

var lineHeightLayout = new StackLayout
{
Orientation = StackOrientation.Horizontal
};

var lineHeightSlider = new Slider
{
Maximum = 4,
Minimum = 2,
Value = 2,
WidthRequest = 150,
VerticalOptions = LayoutOptions.Center
};

var lineHeightText = new Label
{
Text = "LineHeight",
WidthRequest = 100,
VerticalOptions = LayoutOptions.Center
};

lineHeightLayout.Children.Add(lineHeightText);
lineHeightLayout.Children.Add(lineHeightSlider);

layout.Children.Add(instructions);
layout.Children.Add(label);
layout.Children.Add(textDecorationsLayout);
layout.Children.Add(lineHeightLayout);

Content = layout;

textDecorationsCheckBox.CheckedChanged += (sender, args) =>
{
if (args.Value)
label.TextDecorations = TextDecorations.Strikethrough | TextDecorations.Underline;
else
label.TextDecorations = TextDecorations.None;
};

lineHeightSlider.ValueChanged += (sender, args) =>
{
label.LineHeight = args.NewValue;
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,8 @@
<DependentUpon>Issue11938.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue10623.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11496.xaml.cs">
<Compile Include="$(MSBuildThisFileDirectory)Issue11829.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11496.xaml.cs" >
<DependentUpon>Issue11496.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue11209.xaml.cs">
Expand Down
5 changes: 4 additions & 1 deletion Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ protected override void OnElementChanged(ElementChangedEventArgs<Label> e)

UpdateLineBreakMode();
UpdateText();
UpdateTextDecorations();
UpdateTextColor();
UpdateFont();
UpdateTextDecorations();
UpdateMaxLines();
UpdateCharacterSpacing();
UpdatePadding();
Expand Down Expand Up @@ -219,7 +219,10 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
else if (e.PropertyName == VisualElement.FlowDirectionProperty.PropertyName)
UpdateHorizontalTextAlignment();
else if (e.PropertyName == Label.LineHeightProperty.PropertyName)
{
UpdateText();
UpdateTextDecorations();
}
else if (e.PropertyName == Label.MaxLinesProperty.PropertyName)
UpdateMaxLines();
else if (e.PropertyName == Label.PaddingProperty.PropertyName)
Expand Down