Ejemplo n.º 1
0
        public int GetVisibleItemsCount()
        {
            var layoutManager        = (LinearLayoutManager)_recyclerView.GetLayoutManager();
            var firstVisiblePosition = layoutManager.FindFirstCompletelyVisibleItemPosition();
            var lastVisiblePosition  = layoutManager.FindLastCompletelyVisibleItemPosition();

            return(lastVisiblePosition - firstVisiblePosition);
        }
Ejemplo n.º 2
0
 protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     base.OnElementPropertyChanged(sender, e);
     if (e.PropertyName == FastGridView.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 ==
              FastGridView.ItemTemplateSelectorProperty.PropertyName)
     {
         _recyclerView?.GetRecycledViewPool()?.Clear();
         _recyclerView?.SetAdapter(null);
         _recyclerView?.SetAdapter(_adapter);
         CalculateLayoutRects();
         _adapter?.NotifyDataSetChanged();
     }
     else if (e.PropertyName == FastGridView.IsScrollEnabledProperty
              .PropertyName)
     {
         Device.BeginInvokeOnMainThread(() => {
             if (_recyclerView != null && Element != null)
             {
                 _recyclerView.Enabled = Element.IsScrollEnabled;
             }
         });
     }
     else if (e.PropertyName ==
              FastGridView.IsRefreshingProperty.PropertyName)
     {
         if (_refresh != null && Element != null)
         {
             _refresh.Refreshing = Element.IsRefreshing;
         }
     }
     else if (e.PropertyName == FastGridView
              .IsPullToRefreshEnabledProperty.PropertyName)
     {
         if (_refresh != null && Element != null)
         {
             _refresh.IsPullToRefreshEnabled = Element.IsPullToRefreshEnabled;
         }
     }
     else if (e.PropertyName == FastGridView.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 == FastGridView.LoadMoreCommandProperty
              .PropertyName)
     {
         Device.BeginInvokeOnMainThread(() => {
             if (_scrollListener != null)
             {
                 _scrollListener.EnableLoadMore = Element?.LoadMoreCommand != null;
             }
         });
     }
 }