This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[macOS] Fix TextColor Label issue (#14604)
* Fix TextColor Label issue on macOS * Fix build error * Really fix build Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com> Co-authored-by: Gerald Versluis <gerald@verslu.is>
- Loading branch information
1 parent
b5ce2cc
commit 6d751f7
Showing
5 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue10101.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<local:TestContentPage | ||
xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:d="http://xamarin.com/schemas/2014/forms/design" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
Title="Test 10101" xmlns:local="using:Xamarin.Forms.Controls" | ||
x:Class="Xamarin.Forms.Controls.Issues.Issue10101"> | ||
<local:TestContentPage.Resources> | ||
<ResourceDictionary> | ||
<!-- FONTS --> | ||
<OnPlatform x:TypeArguments="Font" x:Key="FontNormal"> | ||
<On Platform="macOS" Value="Roboto Bold, 15" /> | ||
</OnPlatform> | ||
<!-- LABELS --> | ||
<Style TargetType="Label" ApplyToDerivedTypes="True"> | ||
<Setter Property="Font" Value="{StaticResource FontNormal}" /> | ||
<Setter Property="TextColor" Value="Red" /> | ||
</Style> | ||
</ResourceDictionary> | ||
</local:TestContentPage.Resources> | ||
|
||
<StackLayout> | ||
<Label | ||
x:Name="label1" | ||
Text="I should keep my color" /> | ||
<Label | ||
x:Name="label2" | ||
LineBreakMode="WordWrap"> | ||
<Label.FormattedText> | ||
<FormattedString> | ||
<Span Text="I should" TextColor="Red" FontAttributes="Bold" /> | ||
<Span Text=" keep my color" TextColor="Red" /> | ||
</FormattedString> | ||
</Label.FormattedText> | ||
</Label> | ||
<Button x:Name="button" Text="Change text on label" Clicked="button_Clicked" /> | ||
|
||
<Label x:Name="labelColor" Text="Welcome to Xamarin.Forms!" HorizontalOptions="Center" | ||
VerticalOptions="CenterAndExpand"> | ||
<Label.GestureRecognizers> | ||
<TapGestureRecognizer Tapped="OnTapped" /> | ||
</Label.GestureRecognizers> | ||
</Label> | ||
<Label x:Name="labelText" Text="" HorizontalOptions="Center" | ||
VerticalOptions="CenterAndExpand" /> | ||
</StackLayout> | ||
</local:TestContentPage> |
79 changes: 79 additions & 0 deletions
79
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue10101.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Xamarin.Forms; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 10101, "Changing text on a Label on macOS resets font color to Black", PlatformAffected.macOS)] | ||
public partial class Issue10101 : TestContentPage | ||
{ | ||
class ColorItem | ||
{ | ||
public Color Color { get; set; } = Color.Red; | ||
public string Name { get; set; } | ||
} | ||
|
||
readonly Random _random = new Random(); | ||
|
||
static List<ColorItem> GetSystemColorList() => | ||
new List<ColorItem> | ||
{ | ||
new ColorItem() {Color = Color.Accent, Name = "Accent"}, | ||
new ColorItem() {Color = Color.AliceBlue, Name = "AliceBlue"}, | ||
new ColorItem() {Color = Color.MintCream, Name = "MintCream"}, | ||
new ColorItem() {Color = Color.MistyRose, Name = "MistyRose"}, | ||
new ColorItem() {Color = Color.Moccasin, Name = "Moccasin"}, | ||
new ColorItem() {Color = Color.NavajoWhite, Name = "NavajoWhite"}, | ||
new ColorItem() {Color = Color.Navy, Name = "Navy"}, | ||
new ColorItem() {Color = Color.OldLace, Name = "OldLace"}, | ||
new ColorItem() {Color = Color.MidnightBlue, Name = "MidnightBlue"}, | ||
new ColorItem() {Color = Color.Olive, Name = "Olive"}, | ||
new ColorItem() {Color = Color.Orange, Name = "Orange"}, | ||
new ColorItem() {Color = Color.OrangeRed, Name = "OrangeRed"}, | ||
new ColorItem() {Color = Color.Orchid, Name = "Orchid"}, | ||
new ColorItem() {Color = Color.PaleGoldenrod, Name = "PaleGoldenrod"}, | ||
new ColorItem() {Color = Color.PaleGreen, Name = "PaleGreen"}, | ||
new ColorItem() {Color = Color.PaleTurquoise, Name = "PaleTurquoise"}, | ||
new ColorItem() {Color = Color.OliveDrab, Name = "OliveDrab"} | ||
}; | ||
|
||
protected override void Init() | ||
{ | ||
|
||
} | ||
|
||
#if APP | ||
public Issue10101() | ||
{ | ||
InitializeComponent(); | ||
OnTapped(null, null); | ||
} | ||
|
||
ColorItem RandomColor() | ||
{ | ||
var colors = GetSystemColorList(); | ||
return colors[_random.Next(0, colors.Count - 1)]; | ||
} | ||
|
||
void OnTapped(object sender, EventArgs e) | ||
{ | ||
var color = RandomColor(); | ||
|
||
labelText.TextColor = color.Color; | ||
labelColor.TextColor = color.Color; | ||
|
||
labelText.Text = $"TextColor should be {color.Name}"; | ||
labelColor.Text = $"TextColor should be {color.Name}"; | ||
} | ||
|
||
void button_Clicked(System.Object sender, System.EventArgs e) | ||
{ | ||
label1.Text = "This text should still be red"; | ||
} | ||
#endif | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters