diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..2bd6cc1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "dotnet.defaultSolution": "AuroraControlsMaui.sln" +} \ No newline at end of file diff --git a/AuroraControls.TestApp/AuroraControls.TestApp.csproj b/AuroraControls.TestApp/AuroraControls.TestApp.csproj index 7d25608..1fa9c06 100644 --- a/AuroraControls.TestApp/AuroraControls.TestApp.csproj +++ b/AuroraControls.TestApp/AuroraControls.TestApp.csproj @@ -18,9 +18,7 @@ 14.2 21.0 13.1 - - - --weak-framework=NewsstandKit.framework/NewsstandKit + --weak-framework=NewsstandKit.framework/NewsstandKit false diff --git a/AuroraControlsMaui/AuroraControlBuilder.cs b/AuroraControlsMaui/AuroraControlBuilder.cs index 74f6dce..7631be9 100644 --- a/AuroraControlsMaui/AuroraControlBuilder.cs +++ b/AuroraControlsMaui/AuroraControlBuilder.cs @@ -40,4 +40,4 @@ public static MauiAppBuilder UseAuroraControls(this MauiAppBuilder mauiAppBuilde return mauiAppBuilder; } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/AuroraControls.csproj b/AuroraControlsMaui/AuroraControls.csproj index 918a58a..946d184 100644 --- a/AuroraControlsMaui/AuroraControls.csproj +++ b/AuroraControlsMaui/AuroraControls.csproj @@ -1,25 +1,25 @@ - - - net7.0-android;net7.0-ios;net7.0-maccatalyst - true - true - enable - - 14.2 - 21.0 - 13.1 - AuroraControls - - - - false - - - - - - - - - + + net7.0-android;net7.0-ios;net7.0-maccatalyst + true + true + enable + 14.2 + 21.0 + 13.1 + AuroraControls + + + false + + + + + + + + \ No newline at end of file diff --git a/AuroraControlsMaui/AuroraViewBase.cs b/AuroraControlsMaui/AuroraViewBase.cs index 15bf2ca..5523484 100644 --- a/AuroraControlsMaui/AuroraViewBase.cs +++ b/AuroraControlsMaui/AuroraViewBase.cs @@ -125,4 +125,4 @@ private void PaintSurfaceInternal(SKSurface surface, SKImageInfo info) } } } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/AuroraViewHandler.cs b/AuroraControlsMaui/AuroraViewHandler.cs index b68aa55..aa72707 100644 --- a/AuroraControlsMaui/AuroraViewHandler.cs +++ b/AuroraControlsMaui/AuroraViewHandler.cs @@ -9,4 +9,4 @@ public AuroraViewHandler() : base(SKCanvasViewHandler.SKCanvasViewMapper, SKCanvasViewHandler.SKCanvasViewCommandMapper) { } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/CupertinoToggleSwitch.cs b/AuroraControlsMaui/CupertinoToggleSwitch.cs index 9ab55f8..874d7b7 100644 --- a/AuroraControlsMaui/CupertinoToggleSwitch.cs +++ b/AuroraControlsMaui/CupertinoToggleSwitch.cs @@ -336,4 +336,4 @@ private void AnimateToggle(bool toggled) easing: Easing.CubicInOut, length: ToggleAnimationDuration); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Easings.cs b/AuroraControlsMaui/Easings.cs index a7858bf..60fb2c1 100644 --- a/AuroraControlsMaui/Easings.cs +++ b/AuroraControlsMaui/Easings.cs @@ -420,4 +420,4 @@ public static double BounceEaseInOut(double p) return (0.5d * BounceEaseOut((p * 2) - 1)) + 0.5d; } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/EmbeddedResourceLoader.cs b/AuroraControlsMaui/EmbeddedResourceLoader.cs index 87fcfc1..54da2eb 100644 --- a/AuroraControlsMaui/EmbeddedResourceLoader.cs +++ b/AuroraControlsMaui/EmbeddedResourceLoader.cs @@ -54,4 +54,4 @@ public static Stream Load(string name) return stream ?? Stream.Null; } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/EndCapType.cs b/AuroraControlsMaui/EndCapType.cs index 079090e..5156546 100644 --- a/AuroraControlsMaui/EndCapType.cs +++ b/AuroraControlsMaui/EndCapType.cs @@ -6,4 +6,4 @@ public enum EndCapType { Square = 1, Rounded = 2, -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Extensions/ColorExtensions.cs b/AuroraControlsMaui/Extensions/ColorExtensions.cs index ff45142..c4f37f7 100644 --- a/AuroraControlsMaui/Extensions/ColorExtensions.cs +++ b/AuroraControlsMaui/Extensions/ColorExtensions.cs @@ -38,4 +38,4 @@ public static SKColor WithAlpha(this SKColor color, float alpha) return color.WithAlpha((byte)alphaByte); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Extensions/DrawingExtensions.cs b/AuroraControlsMaui/Extensions/DrawingExtensions.cs index 7263c61..a652dfd 100644 --- a/AuroraControlsMaui/Extensions/DrawingExtensions.cs +++ b/AuroraControlsMaui/Extensions/DrawingExtensions.cs @@ -19,4 +19,4 @@ public static System.Drawing.PointF Center(this RectangleF rectangle) rectangle.Left + (rectangle.Width / 2f), rectangle.Top + (rectangle.Height / 2f)); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Extensions/ImageSourceExtensions.cs b/AuroraControlsMaui/Extensions/ImageSourceExtensions.cs index 59c9fc9..bfc3468 100644 --- a/AuroraControlsMaui/Extensions/ImageSourceExtensions.cs +++ b/AuroraControlsMaui/Extensions/ImageSourceExtensions.cs @@ -294,4 +294,4 @@ public static UriImageSource AsAsyncUriImageSource(this Task ima .FileImageSourceFromSvg(svgName, squareSize, colorOverride: colorOverride) .AsAsyncSourceFor(image); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Extensions/MathExtensions.cs b/AuroraControlsMaui/Extensions/MathExtensions.cs index f378c54..1eb2c0d 100644 --- a/AuroraControlsMaui/Extensions/MathExtensions.cs +++ b/AuroraControlsMaui/Extensions/MathExtensions.cs @@ -40,4 +40,4 @@ public static byte Lerp(this byte start, byte end, double amount) return (byte)(start + adjusted); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Extensions/ObjectExtensions.cs b/AuroraControlsMaui/Extensions/ObjectExtensions.cs index 9b02bef..bce045c 100644 --- a/AuroraControlsMaui/Extensions/ObjectExtensions.cs +++ b/AuroraControlsMaui/Extensions/ObjectExtensions.cs @@ -40,4 +40,4 @@ public static T Clamp(this T val, T min, T max) return val; } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Extensions/SKCanvasExtensions.cs b/AuroraControlsMaui/Extensions/SKCanvasExtensions.cs index 6f5103c..14c6ac2 100644 --- a/AuroraControlsMaui/Extensions/SKCanvasExtensions.cs +++ b/AuroraControlsMaui/Extensions/SKCanvasExtensions.cs @@ -449,4 +449,4 @@ public static Size IconifiedTextSize(this SKCanvas canvas, string text, SKPaint return new Size(width, height); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Extensions/SKTextRun.cs b/AuroraControlsMaui/Extensions/SKTextRun.cs index 39a92f6..aa004cc 100644 --- a/AuroraControlsMaui/Extensions/SKTextRun.cs +++ b/AuroraControlsMaui/Extensions/SKTextRun.cs @@ -112,4 +112,4 @@ public static IEnumerable Create(string text, SKTextRunLookup lookup, return runs; } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Extensions/SKTextRunLookup.cs b/AuroraControlsMaui/Extensions/SKTextRunLookup.cs index 4c58bfd..9f9e8fd 100644 --- a/AuroraControlsMaui/Extensions/SKTextRunLookup.cs +++ b/AuroraControlsMaui/Extensions/SKTextRunLookup.cs @@ -97,4 +97,4 @@ public void Dispose() { Dispose(true); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Extensions/SKTextRunLookupEntry.cs b/AuroraControlsMaui/Extensions/SKTextRunLookupEntry.cs index f0bead3..2b69b9a 100644 --- a/AuroraControlsMaui/Extensions/SKTextRunLookupEntry.cs +++ b/AuroraControlsMaui/Extensions/SKTextRunLookupEntry.cs @@ -76,4 +76,4 @@ public void Dispose() { Dispose(true); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Extensions/SkiaShapeExtensions.cs b/AuroraControlsMaui/Extensions/SkiaShapeExtensions.cs index 50273df..a48fab1 100644 --- a/AuroraControlsMaui/Extensions/SkiaShapeExtensions.cs +++ b/AuroraControlsMaui/Extensions/SkiaShapeExtensions.cs @@ -59,4 +59,4 @@ public static SKRectI Subtract(this SKRectI rect, Thickness thickness) return rect; } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Extensions/SkiaSharpTextExtensions.cs b/AuroraControlsMaui/Extensions/SkiaSharpTextExtensions.cs index bcdddec..7127b77 100644 --- a/AuroraControlsMaui/Extensions/SkiaSharpTextExtensions.cs +++ b/AuroraControlsMaui/Extensions/SkiaSharpTextExtensions.cs @@ -108,10 +108,7 @@ public static void DrawTextAtBaseline( public static void EnsureHasValidFont(this SKPaint fontPaint, string text) { - if (fontPaint.Typeface is null) - { - fontPaint.Typeface = PlatformInfo.DefaultTypeface; - } + fontPaint.Typeface ??= PlatformInfo.DefaultTypeface; // TODO: There is likely a better/faster way to do all of this if (!string.IsNullOrEmpty(text) && !fontPaint.Typeface.ContainsGlyphs(text)) @@ -136,4 +133,4 @@ public static void EnsureHasValidFont(this SKPaint fontPaint, string text) } } } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Extensions/VisualElementExtensions.cs b/AuroraControlsMaui/Extensions/VisualElementExtensions.cs index c09f58e..fb207f6 100644 --- a/AuroraControlsMaui/Extensions/VisualElementExtensions.cs +++ b/AuroraControlsMaui/Extensions/VisualElementExtensions.cs @@ -21,7 +21,7 @@ public static class VisualElementExtensions /// end color. /// The time, in milliseconds, between frames. /// The number of milliseconds over which to interpolate the animation. - /// The easing function to use to transision in, out, or in and out of the animation. + /// The easing function to use to transition in, out, or in and out of the animation. /// The 1st type parameter. public static Task ColorTo(this TElement element, Expression> start, Color end, uint rate = 16, uint length = 250, Easing easing = null) where TElement : IAnimatable @@ -31,10 +31,7 @@ public static Task ColorTo(this TElement element, Expression ColorTo(this TElement element, ExpressionThe animation ending point. /// The time, in milliseconds, between frames. /// The number of milliseconds over which to interpolate the animation. - /// The easing function to use to transision in, out, or in and out of the animation. + /// The easing function to use to transition in, out, or in and out of the animation. /// The 1st type parameter. public static Task TransitionTo(this TElement element, Expression> start, double end, uint rate = 16, uint length = 250, Easing easing = null) where TElement : IAnimatable @@ -79,10 +76,7 @@ public static Task TransitionTo(this TElement element, Expressio return Task.FromResult(false); } - if (easing is null) - { - easing = Easing.Linear; - } + easing ??= Easing.Linear; var member = (MemberExpression)start.Body; var property = member.Member as PropertyInfo; @@ -117,9 +111,9 @@ public static Task TransitionTo(this TElement element, Expressio /// The animation ending point. /// The time, in milliseconds, between frames. /// The number of milliseconds over which to interpolate the animation. - /// The easing function to use to transision in, out, or in and out of the animation. + /// The easing function to use to transition in, out, or in and out of the animation. /// The 1st type parameter. - public static Task TransitionTo(this TElement element, Expression> start, int end, uint rate = 16, uint length = 250, Easing easing = null) + public static Task TransitionTo(this TElement element, Expression> start, float end, uint rate = 16, uint length = 250, Easing easing = null) where TElement : IAnimatable { if (element is null) @@ -127,11 +121,53 @@ public static Task TransitionTo(this TElement element, Expressio return Task.FromResult(false); } - if (easing is null) + easing ??= Easing.Linear; + + var member = (MemberExpression)start.Body; + var property = member.Member as PropertyInfo; + + var animationName = $"transition_to_{property.Name}_{element.GetHashCode()}"; + + var tcs = new TaskCompletionSource(); + + var elementStartingPosition = (float)property.GetValue(element); + + var transitionAnimation = new Animation(d => property.SetValue(element, d), elementStartingPosition, end, easing); + + try + { + element.AbortAnimation(animationName); + + transitionAnimation.Commit(element, animationName, rate, length, finished: (f, a) => tcs.SetResult(a)); + } + catch (InvalidOperationException) { - easing = Easing.Linear; } + return tcs.Task; + } + + /// + /// Extends VisualElement with a new SizeTo method which provides a higher level approach for animating transitions. + /// + /// A task containing the animation result boolean. + /// The VisualElement to perform animation on. + /// The animation starting point. + /// The animation ending point. + /// The time, in milliseconds, between frames. + /// The number of milliseconds over which to interpolate the animation. + /// The easing function to use to transition in, out, or in and out of the animation. + /// The 1st type parameter. + public static Task TransitionTo(this TElement element, Expression> start, int end, uint rate = 16, uint length = 250, Easing easing = null) + where TElement : IAnimatable + { + if (element is null) + { + return Task.FromResult(false); + } + + easing ??= Easing.Linear; + var member = (MemberExpression)start.Body; var property = member.Member as PropertyInfo; @@ -164,10 +200,7 @@ public static Task TransitionTo(this TElement element, Expressio return Task.FromResult(false); } - if (easing is null) - { - easing = Easing.Linear; - } + easing ??= Easing.Linear; var member = (MemberExpression)start.Body; var property = member.Member as PropertyInfo; @@ -201,14 +234,38 @@ public static Task TransitionTo(this TElement element, string an return Task.FromResult(false); } - if (easing is null) + easing ??= Easing.Linear; + + var tcs = new TaskCompletionSource(); + + var transitionAnimation = new Animation(callback, start?.Invoke() ?? default(double), end, easing); + + try + { + element.AbortAnimation(animationName); + + transitionAnimation.Commit(element, animationName, rate, length, finished: (f, a) => tcs.SetResult(a)); + } + catch (InvalidOperationException) { - easing = Easing.Linear; } + return tcs.Task; + } + + public static Task TransitionTo(this TElement element, string animationName, Action callback, Func start, float end, uint rate = 16, uint length = 250, Easing easing = null) + where TElement : IAnimatable + { + if (element is null) + { + return Task.FromResult(false); + } + + easing ??= Easing.Linear; + var tcs = new TaskCompletionSource(); - var transitionAnimation = new Animation(callback, start?.Invoke() ?? default(double), end, easing); + var transitionAnimation = new Animation(x => callback((float)x), start?.Invoke() ?? default(float), end, easing); try { @@ -231,10 +288,7 @@ public static Task TransitionTo(this TElement element, string an return Task.FromResult(false); } - if (easing is null) - { - easing = Easing.Linear; - } + easing ??= Easing.Linear; var tcs = new TaskCompletionSource(); @@ -261,10 +315,7 @@ public static Task TransitionTo(this TElement element, string an return Task.FromResult(false); } - if (easing is null) - { - easing = Easing.Linear; - } + easing ??= Easing.Linear; var tcs = new TaskCompletionSource(); @@ -302,10 +353,7 @@ public static Task PointTo(this TElement element, Expression ThicknessTo(this TElement element, Expression return Task.FromResult(false); } - if (easing is null) - { - easing = Easing.Linear; - } + easing ??= Easing.Linear; var member = (MemberExpression)start.Body; var property = member.Member as PropertyInfo; @@ -414,10 +459,7 @@ public static Task SizeTo(this TElement element, Expression listFonts; - if (RegisteredFonts.TryGetValue(qualifiedName, out listFonts)) + + if (qualifiedName is not null && RegisteredFonts.TryGetValue(qualifiedName, out listFonts)) { // Find closest weight return listFonts.MinBy(x => Math.Abs(x.FontWeight - style.FontWeight)); @@ -105,4 +106,4 @@ public static async void AddToAuroraFontCache(this IFontCollection fontDescripto } } } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Gauges/CircularFillGauge.cs b/AuroraControlsMaui/Gauges/CircularFillGauge.cs index 5d08766..623db39 100644 --- a/AuroraControlsMaui/Gauges/CircularFillGauge.cs +++ b/AuroraControlsMaui/Gauges/CircularFillGauge.cs @@ -141,4 +141,4 @@ public Task TransitionTo(double progressPercentage, uint rate = 16, uint l { return this.TransitionTo(x => x.ProgressPercentage, progressPercentage, rate, length, easing); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Gauges/CircularGauge.cs b/AuroraControlsMaui/Gauges/CircularGauge.cs index 5c0d274..df1614f 100644 --- a/AuroraControlsMaui/Gauges/CircularGauge.cs +++ b/AuroraControlsMaui/Gauges/CircularGauge.cs @@ -205,4 +205,4 @@ public async Task TransitionTo(double? startingDegree = null, double? endi return transitions.TrueForAll(x => !x.IsCanceled && !x.IsFaulted && x.IsCompleted && x.Result); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Gauges/LinearGauge.cs b/AuroraControlsMaui/Gauges/LinearGauge.cs index 6eea615..42d82ff 100644 --- a/AuroraControlsMaui/Gauges/LinearGauge.cs +++ b/AuroraControlsMaui/Gauges/LinearGauge.cs @@ -278,4 +278,4 @@ public async Task TransitionTo(double? startingPercentage = null, double? return transitions.TrueForAll(x => !x.IsCanceled && !x.IsFaulted && x.IsCompleted && x.Result); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/GradientColorView.cs b/AuroraControlsMaui/GradientColorView.cs index 5129d08..b9e26cb 100644 --- a/AuroraControlsMaui/GradientColorView.cs +++ b/AuroraControlsMaui/GradientColorView.cs @@ -338,4 +338,4 @@ private void AnimateTap(bool tapped, bool reset = false) this.InvalidateSurface(); }); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/GradientDirection.cs b/AuroraControlsMaui/GradientDirection.cs index c652625..5a77629 100644 --- a/AuroraControlsMaui/GradientDirection.cs +++ b/AuroraControlsMaui/GradientDirection.cs @@ -7,4 +7,4 @@ public enum GradientDirection { Horizontal = 1, Vertical = 2, -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/GradientPillButton.cs b/AuroraControlsMaui/GradientPillButton.cs index 759b35d..a6c2c58 100644 --- a/AuroraControlsMaui/GradientPillButton.cs +++ b/AuroraControlsMaui/GradientPillButton.cs @@ -537,4 +537,4 @@ private void AnimateRipple(bool reset = false) this.InvalidateSurface(); }); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/IAuroraView.cs b/AuroraControlsMaui/IAuroraView.cs index 2bed80c..8252160 100644 --- a/AuroraControlsMaui/IAuroraView.cs +++ b/AuroraControlsMaui/IAuroraView.cs @@ -8,4 +8,4 @@ public interface IAuroraView (bindable, _, _) => (bindable as IAuroraView)?.InvalidateSurface(); void InvalidateSurface(); -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/IIconCache.cs b/AuroraControlsMaui/IIconCache.cs index 5beec05..935e17f 100644 --- a/AuroraControlsMaui/IIconCache.cs +++ b/AuroraControlsMaui/IIconCache.cs @@ -110,4 +110,4 @@ public interface IIconCache /// Clears the cache. /// Task ClearCache(); -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/IconCacheBase.cs b/AuroraControlsMaui/IconCacheBase.cs index db0064d..05f7c36 100644 --- a/AuroraControlsMaui/IconCacheBase.cs +++ b/AuroraControlsMaui/IconCacheBase.cs @@ -386,4 +386,4 @@ public void Dispose() Dispose(disposing: true); GC.SuppressFinalize(this); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Loading/CupertinoActivityIndicator.cs b/AuroraControlsMaui/Loading/CupertinoActivityIndicator.cs index 697095b..948c730 100644 --- a/AuroraControlsMaui/Loading/CupertinoActivityIndicator.cs +++ b/AuroraControlsMaui/Loading/CupertinoActivityIndicator.cs @@ -9,10 +9,6 @@ namespace AuroraControls.Loading; public class CupertinoActivityIndicator : SceneViewBase #pragma warning restore CA1001 // Types that own disposable fields should be disposable { - private SKPicture _loadingIndicator; - - private bool _needsRefresh; - private SKPaint _foregroundPaint; private SKColor _foregroundColor = ((Color)IndicatorColorProperty.DefaultValue).ToSKColor(); @@ -22,8 +18,7 @@ public class CupertinoActivityIndicator : SceneViewBase /// public static BindableProperty SegmentsProperty = BindableProperty.Create(nameof(Segments), typeof(uint), typeof(CupertinoActivityIndicator), 16u, - propertyChanged: static (bindable, _, _) => - (bindable as CupertinoActivityIndicator)._needsRefresh = true); + propertyChanged: IAuroraView.PropertyChangedInvalidateSurface); /// /// Gets or sets the number of segments in the indicator. @@ -41,8 +36,7 @@ public uint Segments /// public static BindableProperty LengthPercentProperty = BindableProperty.Create(nameof(LengthPercent), typeof(double), typeof(CupertinoActivityIndicator), .2d, - propertyChanged: static (bindable, _, _) => - (bindable as CupertinoActivityIndicator)._needsRefresh = true); + propertyChanged: IAuroraView.PropertyChangedInvalidateSurface); /// /// Gets or sets the length percentage. @@ -59,8 +53,7 @@ public double LengthPercent /// public static BindableProperty WidthPercentProperty = BindableProperty.Create(nameof(WidthPercent), typeof(double), typeof(CupertinoActivityIndicator), .25d, - propertyChanged: static (bindable, _, _) => - (bindable as CupertinoActivityIndicator)._needsRefresh = true); + propertyChanged: IAuroraView.PropertyChangedInvalidateSurface); /// /// Gets or sets the width percentage. @@ -81,7 +74,7 @@ public double WidthPercent { var cai = bindable as CupertinoActivityIndicator; cai._foregroundColor = ((Color)newValue).ToSKColor(); - cai._needsRefresh = true; + cai.InvalidateSurface(); }); /// @@ -99,8 +92,7 @@ public Color IndicatorColor /// public static BindableProperty CornerRadiusProperty = BindableProperty.Create(nameof(CornerRadius), typeof(double), typeof(CupertinoActivityIndicator), 4d, - propertyChanged: static (bindable, _, _) => - (bindable as CupertinoActivityIndicator)._needsRefresh = true); + propertyChanged: IAuroraView.PropertyChangedInvalidateSurface); /// /// Gets or sets the corner radius. @@ -134,9 +126,6 @@ protected override void Detached() _foregroundPaint?.Dispose(); _foregroundPaint = null; - - _loadingIndicator?.Dispose(); - _loadingIndicator = null; } protected override SKImage PaintScene(SKSurface surface, SKImageInfo info, double percentage) @@ -148,51 +137,37 @@ protected override SKImage PaintScene(SKSurface surface, SKImageInfo info, doubl var midX = info.Rect.MidX; var midY = info.Rect.MidY; - if (_needsRefresh || _loadingIndicator == null) - { - using (var recorder = new SKPictureRecorder()) - using (var recordingCanvas = recorder.BeginRecording(info.Rect)) - { - var minLength = Math.Min(info.Width, info.Height) * .5f; - var yStart = info.Rect.MidY - minLength; - var length = minLength * (float)LengthPercent; - - var width = length * (float)WidthPercent; + var minLength = Math.Min(info.Width, info.Height) * .5f; + var yStart = info.Rect.MidY - minLength; + var length = minLength * (float)LengthPercent; - var halfCanvasWidth = info.Width * .5f; + var width = length * (float)WidthPercent; - var drawRect = new SKRect(halfCanvasWidth - (width * .5f), yStart, halfCanvasWidth + (width * .5f), yStart + length); + var halfCanvasWidth = info.Width * .5f; - var segments = (float)Segments; + var drawRect = new SKRect(halfCanvasWidth - (width * .5f), yStart, halfCanvasWidth + (width * .5f), yStart + length); - var cornerRadius = (float)CornerRadius * _scale; + var segments = (float)Segments; - var rotationAmount = 360f / segments; - var alphaAmount = 1f / segments; + var cornerRadius = (float)CornerRadius * _scale; - recordingCanvas.Clear(); + var rotationAmount = 360f / segments; + var alphaAmount = 1f / segments; - for (int i = 0; i < segments; i++) - { - _foregroundPaint.Color = _foregroundColor.WithAlpha(alphaAmount * (i + .1f)); - recordingCanvas.RotateDegrees(rotationAmount, midX, midY); - recordingCanvas.DrawRoundRect(drawRect, cornerRadius, cornerRadius, _foregroundPaint); - } - - _loadingIndicator = recorder.EndRecording(); - } - - _needsRefresh = false; - } + canvas.Clear(); using (new SKAutoCanvasRestore(canvas)) { - canvas.Clear(); canvas.RotateDegrees(startingRotation, midX, midY); - canvas.DrawPicture(_loadingIndicator); + + for (int i = 0; i < segments; i++) + { + _foregroundPaint.Color = _foregroundColor.WithAlpha(alphaAmount * (i + .1f)); + canvas.RotateDegrees(rotationAmount, midX, midY); + canvas.DrawRoundRect(drawRect, cornerRadius, cornerRadius, _foregroundPaint); + } } - canvas.Flush(); return surface.Snapshot(); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Loading/LoadingViewBase.cs b/AuroraControlsMaui/Loading/LoadingViewBase.cs index d5e5151..1789ef5 100644 --- a/AuroraControlsMaui/Loading/LoadingViewBase.cs +++ b/AuroraControlsMaui/Loading/LoadingViewBase.cs @@ -115,4 +115,4 @@ public void Stop() Animating = false; this.AbortAnimation(_animationName); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Loading/MaterialCircular.cs b/AuroraControlsMaui/Loading/MaterialCircular.cs index 3aa5448..03a149f 100644 --- a/AuroraControlsMaui/Loading/MaterialCircular.cs +++ b/AuroraControlsMaui/Loading/MaterialCircular.cs @@ -221,4 +221,4 @@ protected override SKImage PaintScene(SKSurface surface, SKImageInfo info, doubl return surface.Snapshot(); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Loading/Nofriendo.cs b/AuroraControlsMaui/Loading/Nofriendo.cs index 08621a4..5a7bd34 100644 --- a/AuroraControlsMaui/Loading/Nofriendo.cs +++ b/AuroraControlsMaui/Loading/Nofriendo.cs @@ -179,4 +179,4 @@ protected override void UpdateAnimationValues() CurrentAnimationStep = 0; } } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Loading/RainbowRing.cs b/AuroraControlsMaui/Loading/RainbowRing.cs index e95934b..8d87cc7 100644 --- a/AuroraControlsMaui/Loading/RainbowRing.cs +++ b/AuroraControlsMaui/Loading/RainbowRing.cs @@ -11,19 +11,19 @@ public class RainbowRing : SceneViewBase private readonly SKColor[] _colors = new[] { - SKColor.Parse("#99f44336"), - SKColor.Parse("#99ff5722"), - SKColor.Parse("#99ffeb3b"), - SKColor.Parse("#9900bcd4"), - SKColor.Parse("#993f51b5"), - SKColor.Parse("#99673ab7"), - SKColor.Parse("#999c27b0"), - SKColor.Parse("#bffafafa"), + SKColor.Parse("#99f44336"), + SKColor.Parse("#99ff5722"), + SKColor.Parse("#99ffeb3b"), + SKColor.Parse("#9900bcd4"), + SKColor.Parse("#993f51b5"), + SKColor.Parse("#99673ab7"), + SKColor.Parse("#999c27b0"), + SKColor.Parse("#bffafafa"), }; private readonly Random _rng = new Random(Guid.NewGuid().GetHashCode()); - private Point[] _movementAmount = new Point[RingCount]; + private readonly Point[] _movementAmount = new Point[RingCount]; private bool _firstRun = true; @@ -41,8 +41,7 @@ public class RainbowRing : SceneViewBase propertyChanged: static (bindable, _, newValue) => { - var current = bindable as RainbowRing; - if (current != null && current._ringPaint != null) + if (bindable is RainbowRing current && current._ringPaint != null) { var value = (float)(double)newValue; current._ringPaint.StrokeWidth = value; @@ -171,4 +170,4 @@ private void UpdateAnimationValues() _movementAmount[i] = new Point(_rng.Next(-maxMovement, maxMovement), _rng.Next(-maxMovement, maxMovement)); } } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Loading/Waves.cs b/AuroraControlsMaui/Loading/Waves.cs index 95e0af2..33ef778 100644 --- a/AuroraControlsMaui/Loading/Waves.cs +++ b/AuroraControlsMaui/Loading/Waves.cs @@ -5,9 +5,9 @@ /// public class Waves : LoadingViewBase { - private Random _rng; + private readonly Random _rng; - private double _randomSeed; + private readonly double _randomSeed; /// /// Specifies the number of waves. @@ -173,4 +173,4 @@ protected override void PaintControl(SKSurface surface, SKImageInfo info) } } } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/NotificationBadge.cs b/AuroraControlsMaui/NotificationBadge.cs index ef4dd2a..53a161e 100644 --- a/AuroraControlsMaui/NotificationBadge.cs +++ b/AuroraControlsMaui/NotificationBadge.cs @@ -302,4 +302,4 @@ public void DrawNotificationBadge(SKSurface surface, SKRect rect, bool clear = t } } } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/NumericEntry.cs b/AuroraControlsMaui/NumericEntry.cs index d4cd455..e72c4dc 100644 --- a/AuroraControlsMaui/NumericEntry.cs +++ b/AuroraControlsMaui/NumericEntry.cs @@ -30,4 +30,4 @@ public NumericEntryValueType ValueType get => (NumericEntryValueType)GetValue(ValueTypeProperty); set => SetValue(ValueTypeProperty, value); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/NumericEntryHandler.cs b/AuroraControlsMaui/NumericEntryHandler.cs index b52a543..7a68e8e 100644 --- a/AuroraControlsMaui/NumericEntryHandler.cs +++ b/AuroraControlsMaui/NumericEntryHandler.cs @@ -65,4 +65,4 @@ protected static bool IsValid(string value, CultureInfo cultureInfo, NumericEntr return false; } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/PlatformInfo.cs b/AuroraControlsMaui/PlatformInfo.cs index 3328727..c83189f 100644 --- a/AuroraControlsMaui/PlatformInfo.cs +++ b/AuroraControlsMaui/PlatformInfo.cs @@ -163,4 +163,4 @@ public static Rect GetLocationOfView(IElement view, IElement parent) return _unknownLocation; #endif } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/PlatformUnderlayDrawable.cs b/AuroraControlsMaui/PlatformUnderlayDrawable.cs index 2cc7c53..0bf7e32 100644 --- a/AuroraControlsMaui/PlatformUnderlayDrawable.cs +++ b/AuroraControlsMaui/PlatformUnderlayDrawable.cs @@ -1,4 +1,4 @@ -using Microsoft.Maui.Animations; +using Microsoft.Maui.Animations; using Microsoft.Maui.Platform; #if IOS || MACCATALYST @@ -639,7 +639,7 @@ private void DrawUnderlay(IUnderlayDrawable underlayDrawable, View element, Rect if (borderSize > 0d) { _placeholderPaint.TextSize = placeholderFontSize; - var placeholderRectSize = canvas.GetTextContainerRectAt(isError ? underlayDrawable.ErrorText : placeholder, new SKPoint((float)controlXLeft, 0.0f), _placeholderPaint); + var placeholderRectSize = canvas.GetTextContainerRectAt(isError ? underlayDrawable.ErrorText : placeholder, new SKPoint((float)controlXLeft, 0.0f), _placeholderPaint); canvas.DrawRoundRect(roundedRectBackgroundPlaceholderThrough, cornerRadiusSize, _borderPaint); @@ -675,7 +675,7 @@ private void DrawUnderlay(IUnderlayDrawable underlayDrawable, View element, Rect _placeholderPaint.Color = underlayDrawable.ErrorColor.ToSKColor(); _placeholderPaint.EnsureHasValidFont(underlayDrawable.ErrorText ?? placeholder); - canvas.DrawTextCenteredVertically(underlayDrawable.ErrorText ?? placeholder, new SKPoint((float)controlXLeft, focusedPlaceholderCenterY), _placeholderPaint); + canvas.DrawTextCenteredVertically(underlayDrawable.ErrorText ?? placeholder, new SKPoint((float)controlXLeft, focusedPlaceholderCenterY), _placeholderPaint); } else if (!string.IsNullOrEmpty(placeholder)) { @@ -697,13 +697,13 @@ private void DrawUnderlay(IUnderlayDrawable underlayDrawable, View element, Rect _placeholderPaint.EnsureHasValidFont(placeholder); - canvas.DrawTextCenteredVertically(placeholder, new SKPoint((float)controlXLeft, (float)placeholderY), _placeholderPaint); + canvas.DrawTextCenteredVertically(placeholder, new SKPoint((float)controlXLeft, (float)placeholderY), _placeholderPaint); } _placeholderPaint.Color = placeholderColor.ToSKColor().WithAlpha(1f - (float)hasValueAnimationPercentage); _placeholderPaint.TextSize = fontSize; - canvas.DrawTextCenteredVertically(placeholder, new SKPoint((float)controlXLeft, (float)controlYCenter), _placeholderPaint); + canvas.DrawTextCenteredVertically(placeholder, new SKPoint((float)controlXLeft, (float)controlYCenter), _placeholderPaint); } } finally @@ -754,4 +754,4 @@ public void Dispose() public interface IHavePlatformUnderlayDrawable { PlatformUnderlayDrawable PlatformUnderlayDrawable { get; } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Platforms/Android/IconCache.cs b/AuroraControlsMaui/Platforms/Android/IconCache.cs index 3b43389..0d3de62 100644 --- a/AuroraControlsMaui/Platforms/Android/IconCache.cs +++ b/AuroraControlsMaui/Platforms/Android/IconCache.cs @@ -48,4 +48,4 @@ public override async Task StreamFromSource(ImageSource imageSource) return stream; } } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Platforms/Android/ImageSourceExtensions.cs b/AuroraControlsMaui/Platforms/Android/ImageSourceExtensions.cs index 84721d6..f4c788a 100644 --- a/AuroraControlsMaui/Platforms/Android/ImageSourceExtensions.cs +++ b/AuroraControlsMaui/Platforms/Android/ImageSourceExtensions.cs @@ -25,4 +25,4 @@ public static IImageSourceHandler GetHandler(this ImageSource source) return returnValue; } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Platforms/Android/NumericEntryHandler.cs b/AuroraControlsMaui/Platforms/Android/NumericEntryHandler.cs index 6d62b8b..eec5a6d 100644 --- a/AuroraControlsMaui/Platforms/Android/NumericEntryHandler.cs +++ b/AuroraControlsMaui/Platforms/Android/NumericEntryHandler.cs @@ -83,4 +83,4 @@ protected override void Dispose(bool disposing) base.Dispose(disposing); } } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Platforms/MacCatalyst/IconCache.cs b/AuroraControlsMaui/Platforms/MacCatalyst/IconCache.cs index 068ea5d..f95e579 100644 --- a/AuroraControlsMaui/Platforms/MacCatalyst/IconCache.cs +++ b/AuroraControlsMaui/Platforms/MacCatalyst/IconCache.cs @@ -46,4 +46,4 @@ public override async Task StreamFromSource(ImageSource imageSource) return image.AsPNG().AsStream(); } } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Platforms/MacCatalyst/ImageSourceExtensions.cs b/AuroraControlsMaui/Platforms/MacCatalyst/ImageSourceExtensions.cs index ff66865..e22142d 100644 --- a/AuroraControlsMaui/Platforms/MacCatalyst/ImageSourceExtensions.cs +++ b/AuroraControlsMaui/Platforms/MacCatalyst/ImageSourceExtensions.cs @@ -25,4 +25,4 @@ public static IImageSourceHandler GetHandler(this ImageSource source) return returnValue; } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Platforms/MacCatalyst/NumericEntryHandler.cs b/AuroraControlsMaui/Platforms/MacCatalyst/NumericEntryHandler.cs index b11e104..ee7ca54 100644 --- a/AuroraControlsMaui/Platforms/MacCatalyst/NumericEntryHandler.cs +++ b/AuroraControlsMaui/Platforms/MacCatalyst/NumericEntryHandler.cs @@ -36,4 +36,4 @@ private bool OnShouldChangeCharacters(UITextField textField, NSRange range, stri return IsValid(final, NumericEntryVirtualView.CultureInfo, NumericEntryVirtualView.ValueType); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Platforms/MacCatalyst/UIViewExtensions.cs b/AuroraControlsMaui/Platforms/MacCatalyst/UIViewExtensions.cs index db9a16c..588c83e 100644 --- a/AuroraControlsMaui/Platforms/MacCatalyst/UIViewExtensions.cs +++ b/AuroraControlsMaui/Platforms/MacCatalyst/UIViewExtensions.cs @@ -9,4 +9,4 @@ public static UIEdgeInsets ToNative(this InsetsF inset) { return new UIEdgeInsets(inset.Top, inset.Left, inset.Bottom, inset.Right); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Platforms/iOS/IconCache.cs b/AuroraControlsMaui/Platforms/iOS/IconCache.cs index 4c0dc23..9b08257 100644 --- a/AuroraControlsMaui/Platforms/iOS/IconCache.cs +++ b/AuroraControlsMaui/Platforms/iOS/IconCache.cs @@ -46,4 +46,4 @@ public override async Task StreamFromSource(ImageSource imageSource) return image.AsPNG().AsStream(); } } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Platforms/iOS/ImageSourceExtensions.cs b/AuroraControlsMaui/Platforms/iOS/ImageSourceExtensions.cs index bca7c94..13992b2 100644 --- a/AuroraControlsMaui/Platforms/iOS/ImageSourceExtensions.cs +++ b/AuroraControlsMaui/Platforms/iOS/ImageSourceExtensions.cs @@ -25,4 +25,4 @@ public static IImageSourceHandler GetHandler(this ImageSource source) return returnValue; } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Platforms/iOS/NumericEntryHandler.cs b/AuroraControlsMaui/Platforms/iOS/NumericEntryHandler.cs index b11e104..ee7ca54 100644 --- a/AuroraControlsMaui/Platforms/iOS/NumericEntryHandler.cs +++ b/AuroraControlsMaui/Platforms/iOS/NumericEntryHandler.cs @@ -36,4 +36,4 @@ private bool OnShouldChangeCharacters(UITextField textField, NSRange range, stri return IsValid(final, NumericEntryVirtualView.CultureInfo, NumericEntryVirtualView.ValueType); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Platforms/iOS/UIViewExtensions.cs b/AuroraControlsMaui/Platforms/iOS/UIViewExtensions.cs index db9a16c..588c83e 100644 --- a/AuroraControlsMaui/Platforms/iOS/UIViewExtensions.cs +++ b/AuroraControlsMaui/Platforms/iOS/UIViewExtensions.cs @@ -9,4 +9,4 @@ public static UIEdgeInsets ToNative(this InsetsF inset) { return new UIEdgeInsets(inset.Top, inset.Left, inset.Bottom, inset.Right); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/SegmentedControl.cs b/AuroraControlsMaui/SegmentedControl.cs index 45004f3..df46b89 100644 --- a/AuroraControlsMaui/SegmentedControl.cs +++ b/AuroraControlsMaui/SegmentedControl.cs @@ -555,4 +555,4 @@ public void Dispose() Dispose(disposing: true); GC.SuppressFinalize(this); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/ServiceProvider.cs b/AuroraControlsMaui/ServiceProvider.cs index de89d6a..5616aa9 100644 --- a/AuroraControlsMaui/ServiceProvider.cs +++ b/AuroraControlsMaui/ServiceProvider.cs @@ -16,4 +16,4 @@ private static IServiceProvider Current #else null; #endif -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/StyledInputLayout.cs b/AuroraControlsMaui/StyledInputLayout.cs index 44bd935..4ac7832 100644 --- a/AuroraControlsMaui/StyledInputLayout.cs +++ b/AuroraControlsMaui/StyledInputLayout.cs @@ -240,4 +240,4 @@ public struct StyledContentTypeRegistration HasValue = _ => true, AlignPlaceholderToTop = false, }; -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/StyledInputLayoutHandler.cs b/AuroraControlsMaui/StyledInputLayoutHandler.cs index 578ed51..af9f4e0 100644 --- a/AuroraControlsMaui/StyledInputLayoutHandler.cs +++ b/AuroraControlsMaui/StyledInputLayoutHandler.cs @@ -155,4 +155,4 @@ private static void MapStyledInputContent(IContentViewHandler elementHandler, IC hpud.PlatformUnderlayDrawable?.PrepareForDisplay(); } } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/SvgImageView.cs b/AuroraControlsMaui/SvgImageView.cs index 796777a..010d9f3 100644 --- a/AuroraControlsMaui/SvgImageView.cs +++ b/AuroraControlsMaui/SvgImageView.cs @@ -201,4 +201,4 @@ private void SetSvgResource() _pictureName = embeddedImageName; } } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/Tile.cs b/AuroraControlsMaui/Tile.cs index a01e273..2193d71 100644 --- a/AuroraControlsMaui/Tile.cs +++ b/AuroraControlsMaui/Tile.cs @@ -766,4 +766,4 @@ private void SetSvgResource() _pictureName = embeddedImageName; } } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/UIntTypeConverter.cs b/AuroraControlsMaui/UIntTypeConverter.cs index 70e0341..d82c315 100644 --- a/AuroraControlsMaui/UIntTypeConverter.cs +++ b/AuroraControlsMaui/UIntTypeConverter.cs @@ -32,4 +32,4 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul return ui.ToString(CultureInfo.InvariantCulture); } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/UnderlayDrawableElement.cs b/AuroraControlsMaui/UnderlayDrawableElement.cs index 64525bf..cdd3973 100644 --- a/AuroraControlsMaui/UnderlayDrawableElement.cs +++ b/AuroraControlsMaui/UnderlayDrawableElement.cs @@ -174,4 +174,4 @@ public interface IUnderlayDrawable : IElement, IHavePlaceholder ICommand Command { get; } object CommandParameter { get; } -} \ No newline at end of file +} diff --git a/AuroraControlsMaui/VisualEffects/VisualEffect.cs b/AuroraControlsMaui/VisualEffects/VisualEffect.cs index 5c11ef5..76431c0 100644 --- a/AuroraControlsMaui/VisualEffects/VisualEffect.cs +++ b/AuroraControlsMaui/VisualEffects/VisualEffect.cs @@ -24,4 +24,4 @@ public bool Enabled public abstract SKImage ApplyEffect(SKImage image, SKSurface surface, SKImageInfo info, SKRect overrideRect); public abstract SKImage ApplyEffect(SKImage image, SKSurface surface, GRBackendRenderTarget info, SKRect overrideRect); -} \ No newline at end of file +} diff --git a/Directory.build.props b/Directory.build.props index f9f01e7..385baaa 100644 --- a/Directory.build.props +++ b/Directory.build.props @@ -1,32 +1,37 @@ - - true - latest - $(NoWarn);CS1591 - - - https://eight.bot - https://github.com/TheEightBot/AuroraControls.Maui - git - .NET MAUI;Custom Controls;SkiaSharp;Eight-Bot - + true + latest + $(NoWarn);CS1591 + + + https://eight.bot + https://github.com/TheEightBot/AuroraControls.Maui + git + .NET MAUI;Custom Controls;SkiaSharp;Eight-Bot + Provides custom user controls for the .NET MAUI platform - logo.png - - - - - - - - - - - - - - - - + logo.png + + + + + + + + + + + + + \ No newline at end of file