void UnsubscribeCollectionItemsSourceChanged(ItemsViewAdapter <CarouselView, IItemsViewSource> oldItemViewAdapter) { if (oldItemViewAdapter != null && oldItemViewAdapter.ItemsSource is ObservableItemsSource oldObservableItemsSource) { oldObservableItemsSource.CollectionItemsSourceChanged -= CollectionItemsSourceChanged; } }
void SubscribeCollectionItemsSourceChanged(ItemsViewAdapter <CarouselView, IItemsViewSource> oldItemViewAdapter) { if (oldItemViewAdapter?.ItemsSource is ObservableItemsSource oldObservableItemsSource) { oldObservableItemsSource.CollectionItemsSourceChanged += CollectionItemsSourceChanged; } }
int GetIndexFromTemplatedCell(global::Android.Views.View view) { int itemIndex = -1; if (view is ItemContentView templatedCell) { var bContext = (templatedCell?.View as VisualElement)?.BindingContext; itemIndex = ItemsViewAdapter.GetPositionForItem(bContext); } return(itemIndex); }
int GetCarouselViewCurrentIndex(int index) { var centeredView = this.GetCenteredView(); if (centeredView is ItemContentView templatedCell) { var bContext = (templatedCell?.View as VisualElement)?.BindingContext; index = ItemsViewAdapter.GetPositionForItem(bContext); } else { return(-1); } return(index); }
protected override void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { _itemsView = null; ItemsViewAdapter = null; } _disposed = true; base.Dispose(disposing); }
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (Carousel.Loop) { // If the height or width are unbounded and the user is set to // Loop then we can't just do an infinite measure. // Looping works by setting item count to 16384 so if the // CarV has infinite room it'll generate all 16384 items. // This code forces the adapter to just measure the first item // And then that measure is used for the WxH of the CarouselView // I found that "AtMost" also causes this behavior so // that's why I'm turning "AtMost" into "Exactly" if (MeasureSpec.GetMode(widthMeasureSpec) == MeasureSpecMode.AtMost) { widthMeasureSpec = MeasureSpecMode.Exactly.MakeMeasureSpec(widthMeasureSpec.GetSize()); } if (MeasureSpec.GetMode(heightMeasureSpec) == MeasureSpecMode.AtMost) { heightMeasureSpec = MeasureSpecMode.Exactly.MakeMeasureSpec(heightMeasureSpec.GetSize()); } if (MeasureSpec.GetMode(widthMeasureSpec) == MeasureSpecMode.Unspecified || MeasureSpec.GetMode(heightMeasureSpec) == MeasureSpecMode.Unspecified) { if (ItemsViewAdapter.ItemCount > 0) { // Retrieve the first item of the CarouselView and measure it // This is what we'll use for the CarV WxH if the requested measure // is for an infinite amount of space var viewType = ItemsViewAdapter.GetItemViewType(0); var viewHolder = (ViewHolder)ItemsViewAdapter.CreateViewHolder(this, viewType); ItemsViewAdapter.BindViewHolder(viewHolder, 0); viewHolder.ItemView.Measure(widthMeasureSpec, heightMeasureSpec); widthMeasureSpec = MeasureSpecMode.Exactly.MakeMeasureSpec(viewHolder.ItemView.MeasuredWidth); heightMeasureSpec = MeasureSpecMode.Exactly.MakeMeasureSpec(viewHolder.ItemView.MeasuredHeight); } } } base.OnMeasure(widthMeasureSpec, heightMeasureSpec); }
protected override int DetermineTargetPosition(ScrollToRequestEventArgs args) { if (args.Mode == ScrollToMode.Element) { return(ItemsViewAdapter.GetPositionForItem(args.Item)); } if (!Carousel.Loop) { return(args.Index); } if (_carouselViewLoopManager == null) { return(-1); } var carouselPosition = GetCarouselViewCurrentIndex(Carousel.Position); var getGoIndex = _carouselViewLoopManager.GetGoToIndex(this, carouselPosition, args.Index); return(getGoIndex); }
public CarouselViewOnScrollListener(ItemsView itemsView, ItemsViewAdapter <CarouselView, IItemsViewSource> itemsViewAdapter, CarouselViewLoopManager carouselViewLoopManager) : base((CarouselView)itemsView, itemsViewAdapter, true) { _carouselView = itemsView as CarouselView; _carouselViewLoopManager = carouselViewLoopManager; }
public RecyclerViewScrollListener(TItemsView itemsView, ItemsViewAdapter <TItemsView, TItemsViewSource> itemsViewAdapter, bool getCenteredItemOnXAndY) { _itemsView = itemsView; ItemsViewAdapter = itemsViewAdapter; _getCenteredItemOnXAndY = getCenteredItemOnXAndY; }
public RecyclerViewScrollListener(TItemsView itemsView, ItemsViewAdapter <TItemsView, TItemsViewSource> itemsViewAdapter) : this(itemsView, itemsViewAdapter, false) { }
internal void UpdateAdapter(ItemsViewAdapter <TItemsView, TItemsViewSource> itemsViewAdapter) { ItemsViewAdapter = itemsViewAdapter; }