-
Notifications
You must be signed in to change notification settings - Fork 742
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(shape): Stroke update not triggering re-render
- Loading branch information
Showing
5 changed files
with
141 additions
and
5 deletions.
There are no files selected for viewing
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
17 changes: 17 additions & 0 deletions
17
src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Shapes/Shape_StrokeTest.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,17 @@ | ||
<Page x:Class="UITests.Windows_UI_Xaml_Shapes.Shape_StrokeTest" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> | ||
|
||
<StackPanel Spacing="16"> | ||
<!-- note: for unknown reason, this Grid is needed for the test to fail before the fix --> | ||
<Grid Height="50" Width="50"> | ||
<Rectangle x:Name="TestTarget" | ||
Height="40" Width="40" | ||
StrokeThickness="20" /> | ||
</Grid> | ||
|
||
<Button x:Name="ChangeThemeButton" Content="ChangeTheme" Click="{x:Bind ChangeTheme}" /> | ||
<Button x:Name="UpdateBrushButton" Content="UpdateBrush" Click="{x:Bind UpdateBrush}" /> | ||
<Button x:Name="UpdateBrushColorButton" Content="UpdateBrushColor" Click="{x:Bind UpdateBrushColor}" /> | ||
</StackPanel> | ||
</Page> |
88 changes: 88 additions & 0 deletions
88
src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Shapes/Shape_StrokeTest.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,88 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Uno.UI.Samples.Controls; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
using Windows.UI; | ||
using Windows.UI.ViewManagement; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Controls.Primitives; | ||
using Windows.UI.Xaml.Data; | ||
using Windows.UI.Xaml.Input; | ||
using Windows.UI.Xaml.Media; | ||
using Windows.UI.Xaml.Navigation; | ||
using XamlWindow = Windows.UI.Xaml.Window; | ||
|
||
namespace UITests.Windows_UI_Xaml_Shapes | ||
{ | ||
[Sample("Shapes")] | ||
public sealed partial class Shape_StrokeTest : Page | ||
{ | ||
private readonly List<SolidColorBrush> _brushes = | ||
new[] { Colors.Red, Colors.Green, Colors.Blue } | ||
.Select(x => new SolidColorBrush(x)) | ||
.ToList(); | ||
|
||
public Shape_StrokeTest() | ||
{ | ||
this.InitializeComponent(); | ||
TestTarget.Stroke = _brushes[0]; | ||
|
||
// Apperently, these scenarios already work without the fix..?: | ||
// - 1 OK: assign Shape.Stroke directly | ||
// - 2 OK: assign Shape.Stroke.Color directly | ||
// - 3 OK: updating Shape.Stroke.Color(ThemeResource) with (dark/light) theme change | ||
// - 4 FAIL: assign Shape.Stroke.Color directly within a Grid? | ||
// This test is aimed at the #4 scenario, and tests for its fix. | ||
} | ||
|
||
private void ChangeTheme() | ||
{ | ||
if (XamlWindow.Current?.Content is FrameworkElement root) | ||
{ | ||
var theme = root.ActualTheme switch | ||
{ | ||
ElementTheme.Light => ApplicationTheme.Light, | ||
ElementTheme.Dark => ApplicationTheme.Dark, | ||
|
||
_ => GetCurrentOsTheme(), | ||
}; | ||
root.RequestedTheme = theme == ApplicationTheme.Light ? ElementTheme.Dark : ElementTheme.Light; | ||
} | ||
|
||
ApplicationTheme GetCurrentOsTheme() | ||
{ | ||
var settings = new UISettings(); | ||
var systemBackground = settings.GetColorValue(UIColorType.Background); | ||
var black = Color.FromArgb(255, 0, 0, 0); | ||
|
||
return systemBackground == black ? ApplicationTheme.Dark : ApplicationTheme.Light; | ||
} | ||
} | ||
|
||
private void UpdateBrush() | ||
{ | ||
var index = (_brushes.IndexOf(TestTarget.Stroke as SolidColorBrush) + 1) % _brushes.Count; | ||
var brush = _brushes[index]; | ||
|
||
TestTarget.Stroke = brush; | ||
} | ||
|
||
private void UpdateBrushColor() | ||
{ | ||
if (TestTarget.Stroke is SolidColorBrush stroke) | ||
{ | ||
stroke.Color = Color.FromArgb( | ||
byte.MaxValue, | ||
(byte)(stroke.Color.R ^ 255), | ||
(byte)(stroke.Color.G ^ 255), | ||
(byte)(stroke.Color.B ^ 255) | ||
); | ||
} | ||
} | ||
} | ||
} |
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