diff --git a/Sharpnado.CollectionView.Droid/Renderers/CollectionViewRenderer.OnControlScrollChangedListener.cs b/Sharpnado.CollectionView.Droid/Renderers/CollectionViewRenderer.OnControlScrollChangedListener.cs index 3469816..f19a05f 100644 --- a/Sharpnado.CollectionView.Droid/Renderers/CollectionViewRenderer.OnControlScrollChangedListener.cs +++ b/Sharpnado.CollectionView.Droid/Renderers/CollectionViewRenderer.OnControlScrollChangedListener.cs @@ -19,8 +19,6 @@ private class OnControlScrollChangedListener : RecyclerView.OnScrollListener private CancellationTokenSource _cts; private int _lastVisibleItemIndex = -1; - private int _currentOffset = 0; - public OnControlScrollChangedListener(IntPtr handle, JniHandleOwnership transfer) : base(handle, transfer) { @@ -38,7 +36,23 @@ public override void OnScrolled(RecyclerView recyclerView, int dx, int dy) { base.OnScrolled(recyclerView, dx, dy); - _currentOffset += dx; + if (dx > 0) + { + _element.ScrollingRightCommand?.Execute(null); + } + else if (dx < 0) + { + _element.ScrollingLeftCommand?.Execute(null); + } + + if (dy > 0) + { + _element.ScrollingDownCommand?.Execute(null); + } + else if (dy < 0) + { + _element.ScrollingUpCommand?.Execute(null); + } var infiniteListLoader = _element?.InfiniteListLoader; if (infiniteListLoader == null) diff --git a/Sharpnado.CollectionView/RenderedViews/CollectionView.cs b/Sharpnado.CollectionView/RenderedViews/CollectionView.cs index 6e28cd6..fc22ebb 100644 --- a/Sharpnado.CollectionView/RenderedViews/CollectionView.cs +++ b/Sharpnado.CollectionView/RenderedViews/CollectionView.cs @@ -159,6 +159,26 @@ public class CollectionView : View typeof(ICommand), typeof(CollectionView)); + public static readonly BindableProperty ScrollingLeftCommandProperty = BindableProperty.Create( + nameof(ScrollingLeftCommand), + typeof(ICommand), + typeof(CollectionView)); + + public static readonly BindableProperty ScrollingUpCommandProperty = BindableProperty.Create( + nameof(ScrollingUpCommand), + typeof(ICommand), + typeof(CollectionView)); + + public static readonly BindableProperty ScrollingRightCommandProperty = BindableProperty.Create( + nameof(ScrollingRightCommand), + typeof(ICommand), + typeof(CollectionView)); + + public static readonly BindableProperty ScrollingDownCommandProperty = BindableProperty.Create( + nameof(ScrollingDownCommand), + typeof(ICommand), + typeof(CollectionView)); + public static readonly BindableProperty EnableDragAndDropProperty = BindableProperty.Create( nameof(EnableDragAndDrop), typeof(bool), @@ -317,6 +337,30 @@ public ICommand ScrollEndedCommand set => SetValue(ScrollEndedCommandProperty, value); } + public ICommand ScrollingLeftCommand + { + get => (ICommand)GetValue(ScrollingLeftCommandProperty); + set => SetValue(ScrollingLeftCommandProperty, value); + } + + public ICommand ScrollingUpCommand + { + get => (ICommand)GetValue(ScrollingUpCommandProperty); + set => SetValue(ScrollingUpCommandProperty, value); + } + + public ICommand ScrollingDownCommand + { + get => (ICommand)GetValue(ScrollingDownCommandProperty); + set => SetValue(ScrollingDownCommandProperty, value); + } + + public ICommand ScrollingRightCommand + { + get => (ICommand)GetValue(ScrollingRightCommandProperty); + set => SetValue(ScrollingRightCommandProperty, value); + } + public bool EnableDragAndDrop { get => (bool)GetValue(EnableDragAndDropProperty);