public int GetVisibleItemsCount() { var layoutManager = (LinearLayoutManager)_recyclerView.GetLayoutManager(); var firstVisiblePosition = layoutManager.FindFirstCompletelyVisibleItemPosition(); var lastVisiblePosition = layoutManager.FindLastCompletelyVisibleItemPosition(); return(lastVisiblePosition - firstVisiblePosition); }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); if (e.PropertyName == FastCollectionView.FastCollection.FastCollectionView.ItemsSourceProperty.PropertyName) { CalculateLayoutRects(); if (_adapter != null && Element != null) { _adapter.Items = Element.ItemsSource; } _recyclerView?.GetLayoutManager()?.ScrollToPosition(0); } else if (e.PropertyName == VisualElement.WidthProperty.PropertyName || e.PropertyName == FastCollectionView.FastCollection.FastCollectionView.ItemTemplateSelectorProperty.PropertyName) { _recyclerView?.GetRecycledViewPool()?.Clear(); _recyclerView?.SetAdapter(null); _recyclerView?.SetAdapter(_adapter); CalculateLayoutRects(); _adapter?.NotifyDataSetChanged(); } else if (e.PropertyName == FastCollectionView.FastCollection.FastCollectionView.IsScrollEnabledProperty .PropertyName) { Device.BeginInvokeOnMainThread(() => { if (_recyclerView != null && Element != null) { _recyclerView.Enabled = Element.IsScrollEnabled; } }); } else if (e.PropertyName == FastCollectionView.FastCollection.FastCollectionView.IsRefreshingProperty.PropertyName) { if (_refresh != null && Element != null) { _refresh.Refreshing = Element.IsRefreshing; } } else if (e.PropertyName == FastCollectionView.FastCollection.FastCollectionView .IsPullToRefreshEnabledProperty.PropertyName) { if (_refresh != null && Element != null) { _refresh.IsPullToRefreshEnabled = Element.IsPullToRefreshEnabled; } } else if (e.PropertyName == FastCollectionView.FastCollection.FastCollectionView.RefreshTopOffsetProperty .PropertyName) { if (_refresh != null && Element != null) { if (Element.RefreshTopOffset != -1) { _refresh.Refreshing = false; var size = (int)(Element.RefreshTopOffset * _density); _refresh.SetProgressViewOffset(true, 0, size); _refresh.Refreshing = Element.IsRefreshing; } } } else if (e.PropertyName == FastCollectionView.FastCollection.FastCollectionView.LoadMoreCommandProperty .PropertyName) { Device.BeginInvokeOnMainThread(() => { if (_scrollListener != null) { _scrollListener.EnableLoadMore = Element?.LoadMoreCommand != null; } }); } }