diff --git a/src/Uno.UI/Extensions/DoubleExtensions.cs b/src/Uno.UI/Extensions/DoubleExtensions.cs new file mode 100644 index 000000000000..f06d52342480 --- /dev/null +++ b/src/Uno.UI/Extensions/DoubleExtensions.cs @@ -0,0 +1,30 @@ +using System.Diagnostics.Contracts; +using System.Runtime.CompilerServices; + +namespace Uno.Extensions +{ + internal static class DoubleExtensions + { + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static bool IsFinite(this double value) + { +#if !XAMARIN + return !double.IsInfinity(value) && !double.IsNaN(value); +#else + return double.IsFinite(value); +#endif + } + + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static bool IsFinite(this float value) + { +#if !XAMARIN + return !float.IsInfinity(value) && !float.IsNaN(value); +#else + return float.IsFinite(value); +#endif + } + } +} diff --git a/src/Uno.UI/Microsoft/UI/Xaml/Controls/Repeater/FlowLayout.cs b/src/Uno.UI/Microsoft/UI/Xaml/Controls/Repeater/FlowLayout.cs index b8dc6ba855c0..40711e1f1885 100644 --- a/src/Uno.UI/Microsoft/UI/Xaml/Controls/Repeater/FlowLayout.cs +++ b/src/Uno.UI/Microsoft/UI/Xaml/Controls/Repeater/FlowLayout.cs @@ -6,12 +6,8 @@ using Windows.Foundation; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; +using Uno.Extensions; using static Microsoft.UI.Xaml.Controls._Tracing; -#if !XAMARIN -using _Float = Uno.UI.LayoutHelper; -#else -using _Float = System.Single; -#endif namespace Microsoft.UI.Xaml.Controls { @@ -227,7 +223,7 @@ protected virtual Rect GetExtent( // If the available size is infinite, we will have realized all the items in one line. // In that case, the extent in the non virtualizing direction should be based on the // right/bottom of the last realized element. - SetMinorSize(ref extent, _Float.IsFinite(availableSizeMinor) ? availableSizeMinor : Math.Max(0.0f, MinorEnd(lastRealizedLayoutBounds))); + SetMinorSize(ref extent, availableSizeMinor.IsFinite() ? availableSizeMinor : Math.Max(0.0f, MinorEnd(lastRealizedLayoutBounds))); } else { @@ -236,7 +232,7 @@ protected virtual Rect GetExtent( // We dont have anything realized. make an educated guess. int numLines = (int)Math.Ceiling(itemsCount / averageItemsPerLine); extent = - _Float.IsFinite(availableSizeMinor) + availableSizeMinor.IsFinite() ? MinorMajorRect(0, 0, availableSizeMinor, Math.Max(0.0f, (float)(numLines * averageLineSize - lineSpacing))) : MinorMajorRect( 0, diff --git a/src/Uno.UI/Microsoft/UI/Xaml/Controls/Repeater/FlowLayoutAlgorithm.cs b/src/Uno.UI/Microsoft/UI/Xaml/Controls/Repeater/FlowLayoutAlgorithm.cs index 74e964932321..e1268ba76475 100644 --- a/src/Uno.UI/Microsoft/UI/Xaml/Controls/Repeater/FlowLayoutAlgorithm.cs +++ b/src/Uno.UI/Microsoft/UI/Xaml/Controls/Repeater/FlowLayoutAlgorithm.cs @@ -5,12 +5,8 @@ using System.Collections.Specialized; using Windows.Foundation; using Windows.UI.Xaml; +using Uno.Extensions; using static Microsoft.UI.Xaml.Controls._Tracing; -#if !XAMARIN -using _Double = Uno.UI.LayoutHelper; -#else -using _Double = System.Double; -#endif namespace Microsoft.UI.Xaml.Controls { @@ -391,7 +387,7 @@ void Generate( { // Does not fit, wrap to the previous row var availableSizeMinor = Minor(availableSize); - SetMinorStart(ref currentBounds, _Double.IsFinite(availableSizeMinor) ? availableSizeMinor - Minor(desiredSize) : 0.0f); + SetMinorStart(ref currentBounds, availableSizeMinor.IsFinite() ? availableSizeMinor - Minor(desiredSize) : 0.0f); SetMajorStart(ref currentBounds, lineOffset - Major(desiredSize) - (float)(lineSpacing)); if (lineNeedsReposition) diff --git a/src/Uno.UI/Microsoft/UI/Xaml/Controls/Repeater/StackLayout.cs b/src/Uno.UI/Microsoft/UI/Xaml/Controls/Repeater/StackLayout.cs index 60a5164d8bb4..1ee01b2a16cc 100644 --- a/src/Uno.UI/Microsoft/UI/Xaml/Controls/Repeater/StackLayout.cs +++ b/src/Uno.UI/Microsoft/UI/Xaml/Controls/Repeater/StackLayout.cs @@ -6,12 +6,8 @@ using Windows.Foundation; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; +using Uno.Extensions; using static Microsoft.UI.Xaml.Controls._Tracing; -#if !XAMARIN -using _Double = Uno.UI.LayoutHelper; -#else -using _Double = System.Double; -#endif namespace Microsoft.UI.Xaml.Controls { @@ -227,7 +223,7 @@ Size IFlowLayoutAlgorithmDelegates.Algorithm_GetProvisionalArrangeSize(int index { var measureSizeMinor = Minor(measureSize); return MinorMajorSize( - (float) (_Double.IsFinite(measureSizeMinor) ? Math.Max(measureSizeMinor, Minor(desiredSize)) : Minor(desiredSize)), + (float) (measureSizeMinor.IsFinite() ? Math.Max(measureSizeMinor, Minor(desiredSize)) : Minor(desiredSize)), (float) Major(desiredSize)); } diff --git a/src/Uno.UI/UI/LayoutHelper.cs b/src/Uno.UI/UI/LayoutHelper.cs index 13271045c9c0..76470ebe6de9 100644 --- a/src/Uno.UI/UI/LayoutHelper.cs +++ b/src/Uno.UI/UI/LayoutHelper.cs @@ -4,7 +4,6 @@ using Windows.Foundation; using Windows.UI.Xaml; using static System.Double; -using static System.Math; namespace Uno.UI { @@ -261,16 +260,6 @@ internal static Size NumberOrDefault(this Size value, Size defaultValue) ); } -#if !XAMARIN - [Pure] - internal static bool IsFinite(this double value) - => !IsInfinity(value) && !IsNaN(value); - - [Pure] - internal static bool IsFinite(this float value) - => !float.IsInfinity(value) && !float.IsNaN(value); -#endif - [Pure] internal static double FiniteOrDefault(this double value, double defaultValue) { diff --git a/src/Uno.UI/UI/Xaml/Controls/Primitives/LoopingSelector/LoopingSelector_Partial.cs b/src/Uno.UI/UI/Xaml/Controls/Primitives/LoopingSelector/LoopingSelector_Partial.cs index 08c21a7a76e9..4627f06161ef 100644 --- a/src/Uno.UI/UI/Xaml/Controls/Primitives/LoopingSelector/LoopingSelector_Partial.cs +++ b/src/Uno.UI/UI/Xaml/Controls/Primitives/LoopingSelector/LoopingSelector_Partial.cs @@ -10,6 +10,7 @@ using Windows.UI.Xaml.Automation.Peers; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; +using Uno.Extensions; using Uno.UI; namespace Windows.UI.Xaml.Controls.Primitives