-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Re-evaluate visual state setters on theme change
- Loading branch information
1 parent
b8b580b
commit 190c390
Showing
7 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_PersonPicture.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,50 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Private.Infrastructure; | ||
using SamplesApp.UITests; | ||
using Uno.UI.RuntimeTests.Helpers; | ||
using PersonPicture = Microsoft/* UWP don't rename */.UI.Xaml.Controls.PersonPicture; | ||
|
||
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls; | ||
|
||
[TestClass] | ||
[RunsOnUIThread] | ||
public partial class Given_PersonPicture | ||
{ | ||
private partial class MyPersonPicture : PersonPicture | ||
{ | ||
public TextBlock InitialsTextBlock { get; private set; } | ||
|
||
protected override void OnApplyTemplate() | ||
{ | ||
base.OnApplyTemplate(); | ||
InitialsTextBlock = (TextBlock)GetTemplateChild("InitialsTextBlock"); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
[UnoWorkItem("https://github.com/unoplatform/uno/issues/16006")] | ||
public async Task TestInitialsTextBlockFontFamily() | ||
{ | ||
var personPicture = new MyPersonPicture(); | ||
await UITestHelper.Load(personPicture); | ||
|
||
#if WINAPPSDK | ||
string symbolsFontName = "Segoe MDL2 Assets"; | ||
#else | ||
string symbolsFontName = "ms-appx:///Uno.Fonts.Fluent/Fonts/uno-fluentui-assets.ttf"; | ||
#endif | ||
|
||
var fontFamilyLight = personPicture.InitialsTextBlock.FontFamily.Source; | ||
Assert.AreEqual(symbolsFontName, fontFamilyLight); | ||
|
||
using (ThemeHelper.UseDarkTheme()) | ||
{ | ||
Assert.AreEqual(fontFamilyLight, personPicture.InitialsTextBlock.FontFamily.Source); | ||
await TestServices.WindowHelper.WaitForIdle(); | ||
Assert.AreEqual(fontFamilyLight, personPicture.InitialsTextBlock.FontFamily.Source); | ||
} | ||
|
||
Assert.AreEqual(fontFamilyLight, personPicture.InitialsTextBlock.FontFamily.Source); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...RuntimeTests/Tests/Windows_UI_Xaml_Media_Animation/Given_TemplateBindingAfterAnimation.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,73 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.UI.Xaml.Media; | ||
using Private.Infrastructure; | ||
using Uno.UI.RuntimeTests.Helpers; | ||
using Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Media_Animation.TestPages; | ||
|
||
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Media_Animation; | ||
|
||
[TestClass] | ||
[RunsOnUIThread] | ||
internal class Given_TemplateBindingAfterAnimation | ||
{ | ||
[TestMethod] | ||
public async Task When_TemplateBinding_And_Animation_Set_Local_On_TemplatedParent() | ||
{ | ||
// Scenario being tested: | ||
// - CustomButton style sets Foreground to Blue | ||
// - A visual state sets tb1.Foreground to Red (we call GoToState in OnApplyTemplate) | ||
// - tb1 Foreground has TemplateBinding to CustomButton's Foreground | ||
var page = new TemplateBindingAfterAnimationPage(); | ||
|
||
await UITestHelper.Load(page); | ||
|
||
var btn = page.customButton; | ||
var tb1 = btn.TextBlockTemplateChildBoundToForeground; | ||
|
||
Assert.AreEqual((btn.Foreground as SolidColorBrush).Color, Microsoft.UI.Colors.Blue); | ||
Assert.AreEqual((tb1.Foreground as SolidColorBrush).Color, Microsoft.UI.Colors.Red); | ||
|
||
btn.Foreground = new SolidColorBrush(Microsoft.UI.Colors.Green); | ||
|
||
Assert.AreEqual((btn.Foreground as SolidColorBrush).Color, Microsoft.UI.Colors.Green); | ||
Assert.AreEqual((tb1.Foreground as SolidColorBrush).Color, Microsoft.UI.Colors.Green); | ||
|
||
await TestServices.WindowHelper.WaitForIdle(); | ||
|
||
Assert.AreEqual((btn.Foreground as SolidColorBrush).Color, Microsoft.UI.Colors.Green); | ||
Assert.AreEqual((tb1.Foreground as SolidColorBrush).Color, Microsoft.UI.Colors.Green); | ||
} | ||
|
||
[TestMethod] | ||
public async Task When_TemplateBinding_And_Animation_Change_Theme() | ||
{ | ||
// Scenario being tested: | ||
// - CustomButton style sets Background to {ThemeResource TemplateBindingAfterAnimationThemeColor1} (Light=White, Dark=LightGray) | ||
// - A visual state sets tb2.Foreground to {ThemeResource TemplateBindingAfterAnimationThemeColor2} (Light=Brown, Dark=RosyBrown) (we call GoToState in OnApplyTemplate) | ||
// - tb2 Foreground has TemplateBinding to CustomButton's Background | ||
var page = new TemplateBindingAfterAnimationPage(); | ||
|
||
await UITestHelper.Load(page); | ||
|
||
var btn = page.customButton; | ||
var tb2 = btn.TextBlockTemplateChildBoundToBackground; | ||
|
||
Assert.AreEqual((btn.Background as SolidColorBrush).Color, Microsoft.UI.Colors.White); | ||
Assert.AreEqual((tb2.Foreground as SolidColorBrush).Color, Microsoft.UI.Colors.Brown); | ||
|
||
using (ThemeHelper.UseDarkTheme()) | ||
{ | ||
Assert.AreEqual((btn.Background as SolidColorBrush).Color, Microsoft.UI.Colors.LightGray); | ||
|
||
#if HAS_UNO | ||
Assert.AreEqual((tb2.Foreground as SolidColorBrush).Color, Microsoft.UI.Colors.RosyBrown); | ||
#else | ||
Assert.AreEqual((tb2.Foreground as SolidColorBrush).Color, Microsoft.UI.Colors.LightGray); | ||
#endif | ||
|
||
await TestServices.WindowHelper.WaitForIdle(); | ||
|
||
Assert.AreEqual((tb2.Foreground as SolidColorBrush).Color, Microsoft.UI.Colors.RosyBrown); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...ts/Tests/Windows_UI_Xaml_Media_Animation/TestPages/TemplateBindingAfterAnimationPage.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,53 @@ | ||
<Page | ||
x:Class="Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Media_Animation.TestPages.TemplateBindingAfterAnimationPage" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Media_Animation.TestPages" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<Grid> | ||
<Grid.Resources> | ||
<ResourceDictionary> | ||
<ResourceDictionary.ThemeDictionaries> | ||
<ResourceDictionary x:Key="Light"> | ||
<SolidColorBrush x:Key="TemplateBindingAfterAnimationThemeColor1" Color="White" /> | ||
<SolidColorBrush x:Key="TemplateBindingAfterAnimationThemeColor2" Color="Brown" /> | ||
</ResourceDictionary> | ||
<ResourceDictionary x:Key="Dark"> | ||
<SolidColorBrush x:Key="TemplateBindingAfterAnimationThemeColor1" Color="LightGray" /> | ||
<SolidColorBrush x:Key="TemplateBindingAfterAnimationThemeColor2" Color="RosyBrown" /> | ||
</ResourceDictionary> | ||
</ResourceDictionary.ThemeDictionaries> | ||
|
||
<Style x:Key="TemplateBindingAfterAnimationStyle" TargetType="local:CustomButton"> | ||
<Setter Property="Foreground" Value="Blue" /> | ||
<Setter Property="Background" Value="{ThemeResource TemplateBindingAfterAnimationThemeColor1}" /> | ||
<Setter Property="Template"> | ||
<Setter.Value> | ||
<ControlTemplate TargetType="local:CustomButton"> | ||
<StackPanel> | ||
<TextBlock x:Name="tb1" Foreground="{TemplateBinding Foreground}" Text="Foreground bound to Foreground" /> | ||
<TextBlock x:Name="tb2" Foreground="{TemplateBinding Background}" Text="Foreground bound to Background" /> | ||
<VisualStateManager.VisualStateGroups> | ||
<VisualStateGroup x:Name="MyVSGroup"> | ||
<VisualState x:Name="MyState"> | ||
<VisualState.Setters> | ||
<Setter Target="tb1.Foreground" Value="Red" /> | ||
<Setter Target="tb2.Foreground" Value="{ThemeResource TemplateBindingAfterAnimationThemeColor2}" /> | ||
</VisualState.Setters> | ||
</VisualState> | ||
</VisualStateGroup> | ||
</VisualStateManager.VisualStateGroups> | ||
</StackPanel> | ||
</ControlTemplate> | ||
</Setter.Value> | ||
</Setter> | ||
</Style> | ||
</ResourceDictionary> | ||
</Grid.Resources> | ||
<local:CustomButton Style="{StaticResource TemplateBindingAfterAnimationStyle}" x:FieldModifier="public" x:Name="customButton" /> | ||
</Grid> | ||
</Page> |
26 changes: 26 additions & 0 deletions
26
...Tests/Windows_UI_Xaml_Media_Animation/TestPages/TemplateBindingAfterAnimationPage.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,26 @@ | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
|
||
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Media_Animation.TestPages; | ||
|
||
public sealed partial class TemplateBindingAfterAnimationPage : Page | ||
{ | ||
public TemplateBindingAfterAnimationPage() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
} | ||
|
||
public partial class CustomButton : Button | ||
{ | ||
public TextBlock TextBlockTemplateChildBoundToForeground { get; private set; } | ||
public TextBlock TextBlockTemplateChildBoundToBackground { get; private set; } | ||
|
||
protected override void OnApplyTemplate() | ||
{ | ||
base.OnApplyTemplate(); | ||
TextBlockTemplateChildBoundToForeground = (TextBlock)this.GetTemplateChild("tb1"); | ||
TextBlockTemplateChildBoundToBackground = (TextBlock)this.GetTemplateChild("tb2"); | ||
VisualStateManager.GoToState(this, "MyState", false); | ||
} | ||
} |
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