diff --git a/Sharpnado.CollectionView.Droid/Renderers/CollectionViewRenderer.OnControlScrollChangedListener.cs b/Sharpnado.CollectionView.Droid/Renderers/CollectionViewRenderer.OnControlScrollChangedListener.cs index 3469816..d76d896 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.ForceUpdateCurrentIndexDuringScroll && _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..f18d8c5 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 ForceUpdateCurrentIndexDuringScrollProperty = BindableProperty.Create( + nameof(ForceUpdateCurrentIndexDuringScroll), + typeof(bool), + typeof(CollectionView), + false); + public CollectionView() { // default layout is VerticalList @@ -365,6 +371,12 @@ public int ColumnCount set => SetValue(ColumnCountProperty, value); } + public bool ForceUpdateCurrentIndexDuringScroll + { + get => (bool)GetValue(ForceUpdateCurrentIndexDuringScrollProperty); + set => SetValue(ForceUpdateCurrentIndexDuringScrollProperty, value); + } + public Func PreRevealAnimationAsync { get; set; } public Func RevealAnimationAsync { get; set; }