Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Make Samples app use Fluent styles by default #15041

Closed
wants to merge 17 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
using Uno.UI.Samples.Entities;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Globalization;
using Windows.UI.Core;
using Windows.Storage;
using Microsoft.UI.Xaml;
using System.IO;
using Windows.UI.Popups;
using Uno.Extensions;
using Uno.UI.Samples.Tests;

Expand Down Expand Up @@ -110,9 +108,7 @@ public SampleChooserViewModel(SampleChooserControl owner)
// Disable all pooling so that controls get collected quickly.
Microsoft.UI.Xaml.FrameworkTemplatePool.IsPoolingEnabled = false;
#endif
#if WINAPPSDK
UseFluentStyles = true;
#endif
InitializeCommands();
ObserveChanges();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="Margin" Value="0,0,0,8" />
<Setter Property="IsTextSelectionEnabled" Value="True" />
</Style>
</StackPanel.Resources>
<TextBlock>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<ToolTip x:Name="ctl3" Background="Green" Width="80" CornerRadius="{x:Bind ToRadius(cornerRadius.Value), Mode=OneWay}">
<TextBlock Foreground="Yellow" HorizontalAlignment="Center">ToolTip<LineBreak/>(Control)</TextBlock>
</ToolTip>
<Button x:Name="ctl4" Background="Green" Width="80" Height="100" CornerRadius="{x:Bind ToRadius(cornerRadius.Value), Mode=OneWay}">
<Button x:Name="ctl4" Background="Green" Width="80" Height="100" BorderThickness="0" CornerRadius="{x:Bind ToRadius(cornerRadius.Value), Mode=OneWay}">
<TextBlock Foreground="Yellow" HorizontalAlignment="Center">Button<LineBreak/>(Control)</TextBlock>
</Button>
<ScrollViewer x:Name="ctl5" Background="Green" Width="80" CornerRadius="{x:Bind ToRadius(cornerRadius.Value), Mode=OneWay}">
Expand Down
30 changes: 15 additions & 15 deletions src/Uno.UI.RuntimeTests/Helpers/StyleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,38 +69,38 @@ public static IDisposable UseAppLevelResources(ResourceDictionary resources)
return Disposable.Create(() => appResources.MergedDictionaries.Remove(resources));
}



/// <summary>
/// Ensure Fluent styles are available for the course of a single test.
/// </summary>
public static IDisposable UseFluentStyles()
public static IDisposable UseUwpStyles()
{
#if WINAPPSDK // Disabled on Windows for now because 19041 doesn't support WinUI 2.x; Fluent resources are used by default in SamplesApp.Windows
return null;
#if WINAPPSDK // Disabled on WinUI as removing the resource dictionary causes a crash.
return Disposable.Empty;
#else

NativeDispatcher.CheckThreadAccess();

var resources = Application.Current.Resources;
if (resources is Microsoft/* UWP don't rename */.UI.Xaml.Controls.XamlControlsResources || resources.MergedDictionaries.OfType<Microsoft/* UWP don't rename */.UI.Xaml.Controls.XamlControlsResources>().Any())
var xamlResources = resources.MergedDictionaries.OfType<Microsoft/* UWP don't rename */.UI.Xaml.Controls.XamlControlsResources>().FirstOrDefault();
if (xamlResources is null)
{
return null;
return Disposable.Empty;
}

var xcr = new Microsoft/* UWP don't rename */.UI.Xaml.Controls.XamlControlsResources();
resources.MergedDictionaries.Insert(0, xcr);

// Force default brushes to be reloaded
DefaultBrushes.ResetDefaultThemeBrushes();
ResetIslandRootForeground();
resources.MergedDictionaries.Remove(xamlResources);
ForceReload();

return new DisposableAction(() =>
{
resources.MergedDictionaries.Remove(xcr);
resources.MergedDictionaries.Insert(0, xamlResources);
ForceReload();
});

static void ForceReload()
{
DefaultBrushes.ResetDefaultThemeBrushes();
ResetIslandRootForeground();
});
}
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1638,8 +1638,8 @@ public async Task ValidateFootprint()

double expectedAppBarWidth = 400;

double expectedAppBarCompactClosedHeight = 40;
double expectedAppBarCompactOpenHeight = 40;
double expectedAppBarCompactClosedHeight = 48;
double expectedAppBarCompactOpenHeight = 48;

double expectedAppBarMinimalClosedHeight = 24;
double expectedAppBarMinimalOpenHeight = 24;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2551,8 +2551,8 @@ await RunOnUIThread(() =>
expectedCommandBarWidth = NativeWindowWrapper.Instance.GetWindowSize().Width;
});
#endif
double expectedCommandBarCompactClosedHeight = 40;
double expectedCommandBarCompactOpenHeight = 40;
double expectedCommandBarCompactClosedHeight = 48;
double expectedCommandBarCompactOpenHeight = 48;

double expectedCommandBarMinimalClosedHeight = 24;
double expectedCommandBarMinimalOpenHeight = 24;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ public void ExpanderAutomationPeerTest()
{
RunOnUIThread.Execute(() =>
{
// Uno specific: the control is fluent only
using var _ = StyleHelper.UseFluentStyles();

var root = (StackPanel)XamlReader.Load(
@"<StackPanel xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Private.Infrastructure;
using Uno.UI.RuntimeTests.Helpers;
using Microsoft.UI.Xaml.Controls;
using Uno.Disposables;

namespace Uno.UI.RuntimeTests.MUX.Microsoft_UI_Xaml_Controls.ProgressRingTests;

Expand All @@ -18,7 +19,7 @@ public class ProgressRingTests
#endif
public async Task ProgressRingDefaultHeightShouldBe32(bool useFluent)
{
using (useFluent ? StyleHelper.UseFluentStyles() : null)
using (useFluent ? Disposable.Empty : StyleHelper.UseUwpStyles())
{
var grid = new Grid();
grid.Width = 100;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Common;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Private.Infrastructure;
using Uno.UI.RuntimeTests;
using Uno.UI.RuntimeTests.Helpers;
using SplitButton = Microsoft/* UWP don't rename */.UI.Xaml.Controls.SplitButton;

namespace Windows.UI.Xaml.Tests.MUXControls.ApiTests;
Expand All @@ -20,14 +19,11 @@ public class Given_SplitButton
#endif
public void VerifyFontFamilyForChevron()
{
using (StyleHelper.UseFluentStyles())
{
var splitButton = new SplitButton();
TestServices.WindowHelper.WindowContent = splitButton;
var splitButton = new SplitButton();
TestServices.WindowHelper.WindowContent = splitButton;

var secondayButton = splitButton.GetTemplateChild("SecondaryButton");
var font = ((secondayButton as Button).Content as TextBlock).FontFamily;
Verify.AreEqual((FontFamily)Application.Current.Resources["SymbolThemeFontFamily"], font);
}
var secondayButton = splitButton.GetTemplateChild("SecondaryButton");
var font = ((secondayButton as Button).Content as TextBlock).FontFamily;
Verify.AreEqual((FontFamily)Application.Current.Resources["SymbolThemeFontFamily"], font);
}
}
Loading
Loading