From cac7f126298772baa3d0521f044fafc7631c769a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Mart=C3=ADnez=20Serrano?= Date: Sat, 8 Oct 2022 19:35:35 +0200 Subject: [PATCH 1/2] Force to update CurrentIndex before scroll ended (during scroll) --- ...ionViewRenderer.OnControlScrollChangedListener.cs | 7 +++++++ .../RenderedViews/CollectionView.cs | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Sharpnado.CollectionView.Droid/Renderers/CollectionViewRenderer.OnControlScrollChangedListener.cs b/Sharpnado.CollectionView.Droid/Renderers/CollectionViewRenderer.OnControlScrollChangedListener.cs index 3469816..ccb0eb9 100644 --- a/Sharpnado.CollectionView.Droid/Renderers/CollectionViewRenderer.OnControlScrollChangedListener.cs +++ b/Sharpnado.CollectionView.Droid/Renderers/CollectionViewRenderer.OnControlScrollChangedListener.cs @@ -40,6 +40,13 @@ public override void OnScrolled(RecyclerView recyclerView, int dx, int dy) _currentOffset += dx; + if (_element.ForceToUpdateCurrentIndexDuringScroll && _weakNativeView.TryGetTarget(out CollectionViewRenderer nativeView)) + { + _cts?.Cancel(); + _cts = new CancellationTokenSource(); + UpdateCurrentIndex(nativeView, _cts.Token); + } + var infiniteListLoader = _element?.InfiniteListLoader; if (infiniteListLoader == null) { diff --git a/Sharpnado.CollectionView/RenderedViews/CollectionView.cs b/Sharpnado.CollectionView/RenderedViews/CollectionView.cs index 6e28cd6..a88b915 100644 --- a/Sharpnado.CollectionView/RenderedViews/CollectionView.cs +++ b/Sharpnado.CollectionView/RenderedViews/CollectionView.cs @@ -217,6 +217,12 @@ public class CollectionView : View typeof(CollectionView), 1); + public static readonly BindableProperty ForceToUpdateCurrentIndexDuringScrollProperty = BindableProperty.Create( + nameof(ForceToUpdateCurrentIndexDuringScroll), + typeof(bool), + typeof(CollectionView), + false); + public CollectionView() { // default layout is VerticalList @@ -365,6 +371,12 @@ public int ColumnCount set => SetValue(ColumnCountProperty, value); } + public bool ForceToUpdateCurrentIndexDuringScroll + { + get => (bool)GetValue(ForceToUpdateCurrentIndexDuringScrollProperty); + set => SetValue(ForceToUpdateCurrentIndexDuringScrollProperty, value); + } + public Func PreRevealAnimationAsync { get; set; } public Func RevealAnimationAsync { get; set; } From 252e097cdf0f10c2f824826ee545e6bd846aaecf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Mart=C3=ADnez=20Serrano?= Date: Mon, 10 Oct 2022 13:35:35 +0200 Subject: [PATCH 2/2] pr changes --- ...ctionViewRenderer.OnControlScrollChangedListener.cs | 2 +- .../RenderedViews/CollectionView.cs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sharpnado.CollectionView.Droid/Renderers/CollectionViewRenderer.OnControlScrollChangedListener.cs b/Sharpnado.CollectionView.Droid/Renderers/CollectionViewRenderer.OnControlScrollChangedListener.cs index ccb0eb9..d76d896 100644 --- a/Sharpnado.CollectionView.Droid/Renderers/CollectionViewRenderer.OnControlScrollChangedListener.cs +++ b/Sharpnado.CollectionView.Droid/Renderers/CollectionViewRenderer.OnControlScrollChangedListener.cs @@ -40,7 +40,7 @@ public override void OnScrolled(RecyclerView recyclerView, int dx, int dy) _currentOffset += dx; - if (_element.ForceToUpdateCurrentIndexDuringScroll && _weakNativeView.TryGetTarget(out CollectionViewRenderer nativeView)) + if (_element.ForceUpdateCurrentIndexDuringScroll && _weakNativeView.TryGetTarget(out CollectionViewRenderer nativeView)) { _cts?.Cancel(); _cts = new CancellationTokenSource(); diff --git a/Sharpnado.CollectionView/RenderedViews/CollectionView.cs b/Sharpnado.CollectionView/RenderedViews/CollectionView.cs index a88b915..f18d8c5 100644 --- a/Sharpnado.CollectionView/RenderedViews/CollectionView.cs +++ b/Sharpnado.CollectionView/RenderedViews/CollectionView.cs @@ -217,8 +217,8 @@ public class CollectionView : View typeof(CollectionView), 1); - public static readonly BindableProperty ForceToUpdateCurrentIndexDuringScrollProperty = BindableProperty.Create( - nameof(ForceToUpdateCurrentIndexDuringScroll), + public static readonly BindableProperty ForceUpdateCurrentIndexDuringScrollProperty = BindableProperty.Create( + nameof(ForceUpdateCurrentIndexDuringScroll), typeof(bool), typeof(CollectionView), false); @@ -371,10 +371,10 @@ public int ColumnCount set => SetValue(ColumnCountProperty, value); } - public bool ForceToUpdateCurrentIndexDuringScroll + public bool ForceUpdateCurrentIndexDuringScroll { - get => (bool)GetValue(ForceToUpdateCurrentIndexDuringScrollProperty); - set => SetValue(ForceToUpdateCurrentIndexDuringScrollProperty, value); + get => (bool)GetValue(ForceUpdateCurrentIndexDuringScrollProperty); + set => SetValue(ForceUpdateCurrentIndexDuringScrollProperty, value); } public Func PreRevealAnimationAsync { get; set; }