Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 96 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue35513.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 35513, "Button TextColor does not restore to platform default when reset to null after dynamic update", PlatformAffected.Android | PlatformAffected.iOS | PlatformAffected.macOS)]
public class Issue35513 : ContentPage
{
Button _sampleButton;
Label _sampleLabel;
Entry _sampleEntry;
Editor _sampleEditor;
RadioButton _sampleRadioButton;
Picker _samplePicker;

public Issue35513()
{
_sampleButton = new Button
{
Text = "Button Control"
};

_sampleLabel = new Label
{
Text = "Label Control"
};

_sampleEntry = new Entry
{
Text = "Entry Control"
};

_sampleEditor = new Editor
{
Text = "Editor Control",
AutoSize = EditorAutoSizeOption.TextChanges
};

_sampleRadioButton = new RadioButton
{
Content = "RadioButton Control"
};

_samplePicker = new Picker
{
Title = "Picker Control"
};
_samplePicker.Items.Add("First Option");
_samplePicker.Items.Add("Second Option");
_samplePicker.SelectedIndex = 0;


Content = new ScrollView
{
Content = new VerticalStackLayout
{
Padding = new Thickness(24),
Spacing = 14,
Children =
{
_sampleButton,
_sampleLabel,
_sampleEntry,
_sampleEditor,
_sampleRadioButton,
_samplePicker,
new Button
{
Text = "Set Text Color",
AutomationId = "SetTextColorButton",
Command = new Command(() =>
{
_sampleButton.TextColor = Colors.Orange;
_sampleLabel.TextColor = Colors.Orange;
_sampleEntry.TextColor = Colors.Orange;
_sampleEditor.TextColor = Colors.Orange;
_sampleRadioButton.TextColor = Colors.Orange;
_samplePicker.TextColor = Colors.Orange;
})
},
new Button
{
Text = "Reset Text Color",
AutomationId = "ResetTextColorButton",
Command = new Command(() =>
{
_sampleButton.TextColor = null;
_sampleLabel.TextColor = null;
_sampleEntry.TextColor = null;
_sampleEditor.TextColor = null;
_sampleRadioButton.TextColor = null;
_samplePicker.TextColor = null;
})
}
}
}
};
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue35513 : _IssuesUITest
{
public Issue35513(TestDevice device) : base(device) { }

public override string Issue => "Button TextColor does not restore to platform default when reset to null after dynamic update";

[Test, Order(1)]
[Category(UITestCategories.Button)]
public void TextViewBasedControlsTextColorUpdates()
{
App.WaitForElement("SetTextColorButton");
App.Tap("SetTextColorButton");
VerifyScreenshot("AfterSetTextColorOnTextViewBasedControls");
}

[Test, Order(2)]
[Category(UITestCategories.Button)]
public void TextViewBasedControlsRestoreDefaultAfterResetToNull()
{
App.WaitForElement("SetTextColorButton");
App.Tap("SetTextColorButton");
App.Tap("ResetTextColorButton");
VerifyScreenshot("AfterResetTextColorToNullOnTextViewBasedControls");
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 16 additions & 2 deletions src/Core/src/Platform/Android/TextViewExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Net;
using System.Runtime.CompilerServices;
using Android.Content.Res;
using Android.Graphics;
using Android.Text;
using Android.Views;
Expand All @@ -14,6 +15,7 @@ namespace Microsoft.Maui.Platform
public static class TextViewExtensions
{
static readonly ConditionalWeakTable<TextView, StrongBox<int>> s_htmlGenerations = new();
static readonly ConditionalWeakTable<TextView, ColorStateList> defaultTextColors = new();

public static void UpdateTextPlainText(this TextView textView, IText label)
{
Expand Down Expand Up @@ -58,8 +60,20 @@ public static void UpdateTextColor(this TextView textView, ITextStyle textStyle)
{
var textColor = textStyle.TextColor;

if (textColor != null)
textView.SetTextColor(textColor.ToPlatform());
// Cache the original themed TextColors the first time this control is updated.
if (textView.TextColors is ColorStateList currentColors)
{
defaultTextColors.GetValue(textView, _ => currentColors);
}

if (textColor is null)
{
var defaultColors = defaultTextColors.TryGetValue(textView, out var cached) ? cached : null;
textView.SetTextColor(defaultColors);
return;
}

textView.SetTextColor(textColor.ToPlatform());
}

public static void UpdateFont(this TextView textView, ITextStyle textStyle, IFontManager fontManager)
Expand Down
1 change: 0 additions & 1 deletion src/Core/src/Platform/iOS/ButtonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public static void UpdateTextColor(this UIButton platformButton, ITextStyle butt
platformButton.SetTitleColor(null, UIControlState.Disabled);
platformButton.TintColor = window.TintColor;
}

return;
}

Expand Down
Loading