From 8b71fe8536fc7accf5d7d6e1dd47ea03daed9ec1 Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 31 Oct 2024 10:41:47 +0100 Subject: [PATCH] Use PropertyChanged-override instead of Observables - no Recative UI or System.Reactive dependency needed - imo cleaner code - no risk of memory leaks due to not unsubscribed observables --- .../IconPacks.Avalonia.Core.csproj | 1 - .../PackIconControlBase.cs | 33 +++++++++---------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/IconPacks.Avalonia.Core/IconPacks.Avalonia.Core.csproj b/src/IconPacks.Avalonia.Core/IconPacks.Avalonia.Core.csproj index 8e8825a..214e64a 100644 --- a/src/IconPacks.Avalonia.Core/IconPacks.Avalonia.Core.csproj +++ b/src/IconPacks.Avalonia.Core/IconPacks.Avalonia.Core.csproj @@ -20,7 +20,6 @@ - diff --git a/src/IconPacks.Avalonia.Core/PackIconControlBase.cs b/src/IconPacks.Avalonia.Core/PackIconControlBase.cs index 80fa4b9..2285034 100644 --- a/src/IconPacks.Avalonia.Core/PackIconControlBase.cs +++ b/src/IconPacks.Avalonia.Core/PackIconControlBase.cs @@ -1,6 +1,4 @@ using System; -using System.Reactive; -using System.Reactive.Linq; using System.Threading.Tasks; using Avalonia; using Avalonia.Animation; @@ -43,22 +41,6 @@ public abstract class PackIconControlBase : PackIconBase protected PackIconControlBase() { AffectsRender(SpinProperty, SpinDurationProperty, OpacityProperty, SpinEasingFunctionProperty, FlipProperty, RotationAngleProperty); - - Observable.CombineLatest( - this.GetObservable(SpinProperty).Select(_ => Unit.Default), - this.GetObservable(IsVisibleProperty).Select(_ => Unit.Default), - this.GetObservable(SpinDurationProperty).Select(_ => Unit.Default), - this.GetObservable(OpacityProperty).Select(_ => Unit.Default), - this.GetObservable(SpinEasingFunctionProperty).Select(_ => Unit.Default)) - .Select(_ => this.CanSpin()) - .Subscribe(spin => - { - this.StopSpinAnimation(); - if (spin) - { - this.BeginSpinAnimation(); - } - }); } private bool CanSpin() @@ -121,6 +103,21 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang this.UpdateRotateTransformation(change.GetNewValue()); } } + + // Update Spin-Animation as needed + if (change.Property == SpinProperty + || change.Property == IsVisibleProperty + || change.Property == SpinDurationProperty + || change.Property == OpacityProperty + || change.Property == SpinEasingFunctionProperty) + { + this.StopSpinAnimation(); + + if (this.CanSpin()) + { + this.BeginSpinAnimation(); + } + } } private void UpdateScaleTransformation(PackIconFlipOrientation flipOrientation)