fix: fix scroll button memory leakage.
This commit is contained in:
@@ -2,6 +2,7 @@ using Avalonia;
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.VisualTree;
|
using Avalonia.VisualTree;
|
||||||
|
using Irihi.Avalonia.Shared.Helpers;
|
||||||
using Ursa.Common;
|
using Ursa.Common;
|
||||||
|
|
||||||
namespace Ursa.Controls;
|
namespace Ursa.Controls;
|
||||||
@@ -54,11 +55,17 @@ public class ScrollToButton: Button
|
|||||||
}
|
}
|
||||||
_scroll = scroll;
|
_scroll = scroll;
|
||||||
|
|
||||||
_disposable = ScrollViewer.OffsetProperty.Changed.AddClassHandler<ScrollViewer, Vector>(OnScrollChanged);
|
_disposable = _scroll?.GetObservable(ScrollViewer.OffsetProperty).Subscribe(OnScrollChanged);
|
||||||
SetVisibility(Direction, _scroll?.Offset);
|
SetVisibility(Direction, _scroll?.Offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnUnloaded(RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnUnloaded(e);
|
||||||
|
_disposable?.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnClick()
|
protected override void OnClick()
|
||||||
{
|
{
|
||||||
if (_scroll is null) return;
|
if (_scroll is null) return;
|
||||||
@@ -83,14 +90,13 @@ public class ScrollToButton: Button
|
|||||||
_scroll = null;
|
_scroll = null;
|
||||||
}
|
}
|
||||||
_scroll = scroll;
|
_scroll = scroll;
|
||||||
_disposable = ScrollViewer.OffsetProperty.Changed.AddClassHandler<ScrollViewer, Vector>(OnScrollChanged);
|
_disposable = _scroll?.GetObservable(ScrollViewer.OffsetProperty).Subscribe(OnScrollChanged);
|
||||||
SetVisibility(Direction, _scroll?.Offset);
|
SetVisibility(Direction, _scroll?.Offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnScrollChanged(ScrollViewer arg1, AvaloniaPropertyChangedEventArgs<Vector> arg2)
|
private void OnScrollChanged(Vector arg2)
|
||||||
{
|
{
|
||||||
if (arg1 != _scroll) return;
|
SetVisibility(Direction, arg2);
|
||||||
SetVisibility(Direction, arg2.NewValue.Value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetVisibility(Position direction, Vector? vector)
|
private void SetVisibility(Position direction, Vector? vector)
|
||||||
|
|||||||
Reference in New Issue
Block a user