From d330404b5531579737bd5fa0d72fa5b9ad535ff1 Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Fri, 29 May 2020 08:42:24 -0400 Subject: [PATCH] fix: Adjust UWP sample head In UWP (non-WinUI) GridLengthHelper.Auto fails with MethodAccessException, this is a UWP-only workaround. --- .../UITests/Views/Controls/StarStackPanel.cs | 29 ++++++------ .../UITests/Views/Helper/GridLengthHelper2.cs | 45 +++++++++++++++++++ .../SamplesApp.UnitTests.Shared.projitems | 1 + 3 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Helper/GridLengthHelper2.cs diff --git a/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Controls/StarStackPanel.cs b/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Controls/StarStackPanel.cs index 155d8800374a..09bfd41fefb4 100644 --- a/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Controls/StarStackPanel.cs +++ b/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Controls/StarStackPanel.cs @@ -4,6 +4,7 @@ using System.Globalization; using System.Linq; using System.Text.RegularExpressions; +using Uno.UI.Samples.Helper; #if !NETFX_CORE && !__ANDROID__ && !__IOS__ && !__WASM__ && !__MACOS__ using System.Windows; @@ -106,15 +107,15 @@ private void MeasureChild(UIElement child, Size availableSize, Orientation orien { var sizeHint = GetChildSizeHint(child); - if (GridLengthHelper.GetIsStar(sizeHint)) + if (GridLengthHelper2.GetIsStar(sizeHint)) { starTotal += sizeHint.Value; } - else if (GridLengthHelper.GetIsAuto(sizeHint)) + else if (GridLengthHelper2.GetIsAuto(sizeHint)) { MesureChildAuto(child, orientation, availableSize, ref totalSize); } - else if (GridLengthHelper.GetIsAbsolute(sizeHint)) + else if (GridLengthHelper2.GetIsAbsolute(sizeHint)) { MesureChildAbsolute(child, orientation, availableSize, sizeHint, ref totalSize); } @@ -178,7 +179,7 @@ private void MeasureStarChildren(Size availableSize, Orientation orientation, re foreach (UIElement child in children) { var sizeHint = GetChildSizeHint(child); - if (GridLengthHelper.GetIsStar(sizeHint)) + if (GridLengthHelper2.GetIsStar(sizeHint)) { MesureChildStar(child, orientation, availableSize, sizeHint, starTotal, ref totalSize); } @@ -298,15 +299,15 @@ private Record ComputeChildSize(UIElement child, Orientation orientation, ref Si var sizeHint = GetChildSizeHint(child); var size = new Size(); - if (GridLengthHelper.GetIsStar(sizeHint)) + if (GridLengthHelper2.GetIsStar(sizeHint)) { starTotal += sizeHint.Value; } - else if (GridLengthHelper.GetIsAuto(sizeHint)) + else if (GridLengthHelper2.GetIsAuto(sizeHint)) { ComputeChildAutoSize(child, orientation, ref finalSize, ref totalLength, ref size); } - else if (GridLengthHelper.GetIsAbsolute(sizeHint)) + else if (GridLengthHelper2.GetIsAbsolute(sizeHint)) { ComputeChildAbsoluteSize(orientation, ref finalSize, ref totalLength, ref sizeHint, ref size); } @@ -409,7 +410,7 @@ private static Size ComputeFinalChildSize(Record record, Orientation orientation { var size = record.Size; - if (GridLengthHelper.GetIsStar(record.SizeHint)) + if (GridLengthHelper2.GetIsStar(record.SizeHint)) { var portion = record.SizeHint.Value * starRatio; @@ -550,7 +551,7 @@ private static GridLength[] ParseGridLength(string s) { if (string.IsNullOrEmpty(part)) { - result.Add(GridLengthHelper.FromValueAndType(0, GridUnitType.Auto)); + result.Add(GridLengthHelper2.FromValueAndType(0, GridUnitType.Auto)); continue; } @@ -563,7 +564,7 @@ private static GridLength[] ParseGridLength(string s) var autoGroup = match.Groups["auto"]; if (autoGroup.Success) { - result.Add(GridLengthHelper.FromValueAndType(0, GridUnitType.Auto)); + result.Add(GridLengthHelper2.FromValueAndType(0, GridUnitType.Auto)); continue; } @@ -574,14 +575,14 @@ private static GridLength[] ParseGridLength(string s) !string.IsNullOrWhiteSpace(starsGroup.Value) ? double.Parse(starsGroup.Value, CultureInfo.InvariantCulture) : 1; - result.Add(GridLengthHelper.FromValueAndType(value, GridUnitType.Star)); + result.Add(GridLengthHelper2.FromValueAndType(value, GridUnitType.Star)); continue; } var starGroup = match.Groups["star"]; if (starGroup.Success) { - result.Add(GridLengthHelper.FromValueAndType(1, GridUnitType.Star)); + result.Add(GridLengthHelper2.FromValueAndType(1, GridUnitType.Star)); continue; } @@ -589,7 +590,7 @@ private static GridLength[] ParseGridLength(string s) if (absGroup.Success) { var value = double.Parse(absGroup.Value, CultureInfo.InvariantCulture); - result.Add(GridLengthHelper.FromValueAndType(value, GridUnitType.Pixel)); + result.Add(GridLengthHelper2.FromValueAndType(value, GridUnitType.Pixel)); continue; } @@ -631,7 +632,7 @@ public static void SetSize(DependencyObject obj, GridLength value) "Size", typeof(GridLength), typeof(StarStackPanel), - new PropertyMetadata(GridLengthHelper.Auto, HandleSizePropertyChanged) + new PropertyMetadata(GridLengthHelper2.Auto, HandleSizePropertyChanged) ); private static void HandleSizePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) diff --git a/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Helper/GridLengthHelper2.cs b/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Helper/GridLengthHelper2.cs new file mode 100644 index 000000000000..53229fd30a91 --- /dev/null +++ b/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Helper/GridLengthHelper2.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Windows.UI.Xaml; + +namespace Uno.UI.Samples.Helper +{ + class GridLengthHelper2 + { + public static GridLength Auto => +#if NETFX_CORE && !HAS_UNO_WINUI + GridLength.Auto; +#else + GridLengthHelper.Auto; +#endif + + internal static GridLength FromValueAndType(double value, GridUnitType pixel) => +#if NETFX_CORE && !HAS_UNO_WINUI + new GridLength(value, pixel); +#else + GridLengthHelper.FromValueAndType(value, pixel); +#endif + + internal static bool GetIsStar(GridLength sizeHint) => +#if NETFX_CORE && !HAS_UNO_WINUI + sizeHint.IsStar; +#else + GridLengthHelper.GetIsStar(sizeHint); +#endif + + internal static bool GetIsAbsolute(GridLength sizeHint) => +#if NETFX_CORE && !HAS_UNO_WINUI + sizeHint.IsAbsolute; +#else + GridLengthHelper.GetIsAbsolute(sizeHint); +#endif + + internal static bool GetIsAuto(GridLength sizeHint) => +#if NETFX_CORE && !HAS_UNO_WINUI + sizeHint.IsAuto; +#else + GridLengthHelper.GetIsAuto(sizeHint); +#endif + } +} diff --git a/src/SamplesApp/SamplesApp.UnitTests.Shared/SamplesApp.UnitTests.Shared.projitems b/src/SamplesApp/SamplesApp.UnitTests.Shared/SamplesApp.UnitTests.Shared.projitems index a92cd4838b3f..f4d674542c82 100644 --- a/src/SamplesApp/SamplesApp.UnitTests.Shared/SamplesApp.UnitTests.Shared.projitems +++ b/src/SamplesApp/SamplesApp.UnitTests.Shared/SamplesApp.UnitTests.Shared.projitems @@ -42,6 +42,7 @@ +