diff --git a/src/Avalonia.Base/Input/PullGestureRecognizer.cs b/src/Avalonia.Base/Input/GestureRecognizers/PullGestureRecognizer.cs similarity index 93% rename from src/Avalonia.Base/Input/PullGestureRecognizer.cs rename to src/Avalonia.Base/Input/GestureRecognizers/PullGestureRecognizer.cs index bbbded44fa..fedd07ec32 100644 --- a/src/Avalonia.Base/Input/PullGestureRecognizer.cs +++ b/src/Avalonia.Base/Input/GestureRecognizers/PullGestureRecognizer.cs @@ -60,9 +60,9 @@ namespace Avalonia.Input public void PointerMoved(PointerEventArgs e) { - if (_tracking == e.Pointer) + if (_tracking == e.Pointer && _target is Visual visual) { - var currentPosition = e.GetPosition(_target); + var currentPosition = e.GetPosition(visual); _actions!.Capture(e.Pointer, this); Vector delta = default; @@ -100,13 +100,13 @@ namespace Avalonia.Input public void PointerPressed(PointerPressedEventArgs e) { - if (_target != null && (e.Pointer.Type == PointerType.Touch || e.Pointer.Type == PointerType.Pen)) + if (_target != null && _target is Visual visual && (e.Pointer.Type == PointerType.Touch || e.Pointer.Type == PointerType.Pen)) { - var position = e.GetPosition(_target); + var position = e.GetPosition(visual); var canPull = false; - var bounds = _target.Bounds; + var bounds = visual.Bounds; switch (PullDirection) { diff --git a/src/Avalonia.Controls/PullToRefresh/RefreshCompletionDeferral.cs b/src/Avalonia.Controls/PullToRefresh/RefreshCompletionDeferral.cs new file mode 100644 index 0000000000..a18b3c2934 --- /dev/null +++ b/src/Avalonia.Controls/PullToRefresh/RefreshCompletionDeferral.cs @@ -0,0 +1,36 @@ +using System; +using System.Threading; + +namespace Avalonia.Controls +{ + /// + /// Deferral class for notify that a work done in RefreshRequested event is done. + /// + public class RefreshCompletionDeferral + { + private Action _deferredAction; + private int _deferCount; + + public RefreshCompletionDeferral(Action deferredAction) + { + _deferredAction = deferredAction; + } + + public void Complete() + { + Interlocked.Decrement(ref _deferCount); + + if (_deferCount == 0) + { + _deferredAction?.Invoke(); + } + } + + public RefreshCompletionDeferral Get() + { + Interlocked.Increment(ref _deferCount); + + return this; + } + } +} diff --git a/src/Avalonia.Controls/PullToRefresh/RefreshRequestedEventArgs.cs b/src/Avalonia.Controls/PullToRefresh/RefreshRequestedEventArgs.cs new file mode 100644 index 0000000000..4bb25d3b2c --- /dev/null +++ b/src/Avalonia.Controls/PullToRefresh/RefreshRequestedEventArgs.cs @@ -0,0 +1,42 @@ +using System; +using Avalonia.Interactivity; + +namespace Avalonia.Controls +{ + /// + /// Provides event data for RefreshRequested events. + /// + public class RefreshRequestedEventArgs : RoutedEventArgs + { + private RefreshCompletionDeferral _refreshCompletionDeferral; + + /// + /// Gets a deferral object for managing the work done in the RefreshRequested event handler. + /// + /// A object + public RefreshCompletionDeferral GetDeferral() + { + return _refreshCompletionDeferral.Get(); + } + + public RefreshRequestedEventArgs(Action deferredAction, RoutedEvent? routedEvent) : base(routedEvent) + { + _refreshCompletionDeferral = new RefreshCompletionDeferral(deferredAction); + } + + public RefreshRequestedEventArgs(RefreshCompletionDeferral completionDeferral, RoutedEvent? routedEvent) : base(routedEvent) + { + _refreshCompletionDeferral = completionDeferral; + } + + internal void IncrementCount() + { + _refreshCompletionDeferral?.Get(); + } + + internal void DecrementCount() + { + _refreshCompletionDeferral?.Complete(); + } + } +} diff --git a/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs b/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs index 2647ac1ac1..f2f735aaa9 100644 --- a/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs +++ b/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs @@ -1,8 +1,6 @@ using System; using System.Numerics; using System.Reactive.Linq; -using System.Threading; -using Avalonia.Animation; using Avalonia.Animation.Easings; using Avalonia.Controls.Primitives; using Avalonia.Controls.PullToRefresh; @@ -104,14 +102,7 @@ namespace Avalonia.Controls internal PullDirection PullDirection { get => GetValue(PullDirectionProperty); - set - { - SetValue(PullDirectionProperty, value); - - OnOrientationChanged(); - - UpdateContent(); - } + set => SetValue(PullDirectionProperty, value); } internal RefreshInfoProvider? RefreshInfoProvider @@ -201,7 +192,7 @@ namespace Avalonia.Controls } else { - RaisePropertyChanged(ContentProperty, null, Content); + RaisePropertyChanged(ContentProperty, null, Content, Data.BindingPriority.Style, false); } } @@ -400,6 +391,12 @@ namespace Avalonia.Controls break; } + UpdateContent(); + } + else if(change.Property == PullDirectionProperty) + { + OnOrientationChanged(); + UpdateContent(); } } @@ -553,95 +550,4 @@ namespace Avalonia.Controls } } } - - /// - /// Defines constants that specify the state of a RefreshVisualizer - /// - public enum RefreshVisualizerState - { - Idle, - Peeking, - Interacting, - Pending, - Refreshing - } - - /// - /// Defines constants that specify the orientation of a RefreshVisualizer. - /// - public enum RefreshVisualizerOrientation - { - Auto, - Normal, - Rotate90DegreesCounterclockwise, - Rotate270DegreesCounterclockwise - } - - /// - /// Provides event data for RefreshRequested events. - /// - public class RefreshRequestedEventArgs : RoutedEventArgs - { - private RefreshCompletionDeferral _refreshCompletionDeferral; - - /// - /// Gets a deferral object for managing the work done in the RefreshRequested event handler. - /// - /// A object - public RefreshCompletionDeferral GetDeferral() - { - return _refreshCompletionDeferral.Get(); - } - - public RefreshRequestedEventArgs(Action deferredAction, RoutedEvent? routedEvent) : base(routedEvent) - { - _refreshCompletionDeferral = new RefreshCompletionDeferral(deferredAction); - } - - public RefreshRequestedEventArgs(RefreshCompletionDeferral completionDeferral, RoutedEvent? routedEvent) : base(routedEvent) - { - _refreshCompletionDeferral = completionDeferral; - } - - internal void IncrementCount() - { - _refreshCompletionDeferral?.Get(); - } - - internal void DecrementCount() - { - _refreshCompletionDeferral?.Complete(); - } - } - - /// - /// Deferral class for notify that a work done in RefreshRequested event is done. - /// - public class RefreshCompletionDeferral - { - private Action _deferredAction; - private int _deferCount; - - public RefreshCompletionDeferral(Action deferredAction) - { - _deferredAction = deferredAction; - } - - public void Complete() - { - Interlocked.Decrement(ref _deferCount); - - if (_deferCount == 0) - { - _deferredAction?.Invoke(); - } - } - - public RefreshCompletionDeferral Get() - { - Interlocked.Increment(ref _deferCount); - - return this; - } - } } diff --git a/src/Avalonia.Controls/PullToRefresh/RefreshVisualizerOrientation.cs b/src/Avalonia.Controls/PullToRefresh/RefreshVisualizerOrientation.cs new file mode 100644 index 0000000000..1ea37f67b9 --- /dev/null +++ b/src/Avalonia.Controls/PullToRefresh/RefreshVisualizerOrientation.cs @@ -0,0 +1,13 @@ +namespace Avalonia.Controls +{ + /// + /// Defines constants that specify the orientation of a RefreshVisualizer. + /// + public enum RefreshVisualizerOrientation + { + Auto, + Normal, + Rotate90DegreesCounterclockwise, + Rotate270DegreesCounterclockwise + } +} diff --git a/src/Avalonia.Controls/PullToRefresh/RefreshVisualizerState.cs b/src/Avalonia.Controls/PullToRefresh/RefreshVisualizerState.cs new file mode 100644 index 0000000000..5ab52f4de6 --- /dev/null +++ b/src/Avalonia.Controls/PullToRefresh/RefreshVisualizerState.cs @@ -0,0 +1,14 @@ +namespace Avalonia.Controls +{ + /// + /// Defines constants that specify the state of a RefreshVisualizer + /// + public enum RefreshVisualizerState + { + Idle, + Peeking, + Interacting, + Pending, + Refreshing + } +} diff --git a/src/Avalonia.Controls/PullToRefresh/ScrollViewerIRefreshInfoProviderAdapter.cs b/src/Avalonia.Controls/PullToRefresh/ScrollViewerIRefreshInfoProviderAdapter.cs index db06de69ad..c3aebc82c5 100644 --- a/src/Avalonia.Controls/PullToRefresh/ScrollViewerIRefreshInfoProviderAdapter.cs +++ b/src/Avalonia.Controls/PullToRefresh/ScrollViewerIRefreshInfoProviderAdapter.cs @@ -23,7 +23,7 @@ namespace Avalonia.Controls.PullToRefresh _refreshPullDirection = pullDirection; } - public RefreshInfoProvider? AdaptFromTree(IVisual root, Size? refreshVIsualizerSize) + public RefreshInfoProvider? AdaptFromTree(Visual root, Size? refreshVIsualizerSize) { if (root is ScrollViewer scrollViewer) { @@ -45,7 +45,7 @@ namespace Avalonia.Controls.PullToRefresh } } - ScrollViewer? AdaptFromTreeRecursiveHelper(IVisual root, int depth) + ScrollViewer? AdaptFromTreeRecursiveHelper(Visual root, int depth) { if (depth == 0) { diff --git a/src/Avalonia.Themes.Fluent/Controls/RefreshContainer.xaml b/src/Avalonia.Themes.Fluent/Controls/RefreshContainer.xaml index 97002c25bd..8e29e6208f 100644 --- a/src/Avalonia.Themes.Fluent/Controls/RefreshContainer.xaml +++ b/src/Avalonia.Themes.Fluent/Controls/RefreshContainer.xaml @@ -4,7 +4,7 @@ TargetType="RefreshContainer"> - + - +