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

[iOS] Fix setting text decorations and text at the same time and respect changes #14907

Merged
merged 1 commit into from
Nov 23, 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,94 @@
using System;
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
[Category(UITestCategories.Label)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 11954,
"[Bug] iOS label can't un-set text decorations when updating text at the same time",
PlatformAffected.iOS)]
public class Issue11954 : TestContentPage
{
public Issue11954()
{
UpdateLabel();
}

private Label NiceLabel;

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

var layout = new StackLayout();

var instructions = new Label
{
Padding = 12,
BackgroundColor = Color.Black,
TextColor = Color.White,
Text = "If press the toggle button and the label enables and disables strikethrough correctly, the test has passed"
};

NiceLabel = new Label
{
FontSize = 16,
Padding = new Thickness(30,24,30,0),
Text = "Default text"
};

var button = new Button
{
Text = "Toggle"
};

button.Clicked += Button_Clicked;

layout.Children.Add(NiceLabel);
layout.Children.Add(button);

Content = layout;
}

private bool _isStrikethrough;

private void Button_Clicked(object sender, EventArgs e)
{
// Toggle strike-through and update label
_isStrikethrough = !_isStrikethrough;
UpdateLabel();
}

private void UpdateLabel()
{
NiceLabel.TextDecorations = _isStrikethrough ? TextDecorations.Strikethrough : TextDecorations.None;

// Comment out the next line and it starts working again
NiceLabel.Text = "Is it strikethrough? " + _isStrikethrough.ToString();
}

#if UITEST
[Test]
[Category(UITestCategories.ManualReview)]
public void Issue11954Test()
{
RunningApp.Tap("Toggle");
RunningApp.Screenshot("Label should have strikethrough");
RunningApp.Tap("Toggle");
RunningApp.Screenshot("Label should NOT have strikethrough");

Assert.Inconclusive("For visual review only");
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue10623.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11829.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11496.xaml.cs" >
<Compile Include="$(MSBuildThisFileDirectory)Issue11496.xaml.cs">
<DependentUpon>Issue11496.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue11209.xaml.cs">
Expand Down Expand Up @@ -1828,6 +1828,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue14757.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue14897.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue14805.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11954.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
Expand Down Expand Up @@ -2731,7 +2732,7 @@
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue7671.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -2946,7 +2947,7 @@
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue14765.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue13573.xaml">
<SubType>Designer</SubType>
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ void UpdateTextPlainText()
{
var text = Element.UpdateFormsText(Element.Text, Element.TextTransform);
#if __MOBILE__
Control.Text = text;
Control.AttributedText = new NSAttributedString(text);
#else
Control.StringValue = text ?? "";
#endif
Expand Down