protected virtual void UpdateTemplatedCell(TemplatedCell cell, NSIndexPath indexPath) { cell.ContentSizeChanged -= CellContentSizeChanged; cell.LayoutAttributesChanged -= CellLayoutAttributesChanged; var bindingContext = ItemsSource[indexPath]; // If we've already created a cell for this index path (for measurement), re-use the content if (_measurementCells.TryGetValue(bindingContext, out TemplatedCell measurementCell)) { _measurementCells.Remove(bindingContext); measurementCell.ContentSizeChanged -= CellContentSizeChanged; measurementCell.LayoutAttributesChanged -= CellLayoutAttributesChanged; cell.UseContent(measurementCell); } else { cell.Bind(ItemsView.ItemTemplate, ItemsSource[indexPath], ItemsView); } cell.ContentSizeChanged += CellContentSizeChanged; cell.LayoutAttributesChanged += CellLayoutAttributesChanged; ItemsViewLayout.PrepareCellForLayout(cell); }
internal UIEdgeInsets GetInsetForSection(ItemsViewLayout itemsViewLayout, UICollectionView collectionView, nint section) { var uIEdgeInsets = ItemsViewLayout.GetInsetForSection(collectionView, itemsViewLayout, section); if (!ItemsView.IsGrouped) { return(uIEdgeInsets); } // If we're grouping, we'll need to inset the sections to maintain the spacing between the // groups and their group headers/footers nfloat spacing = itemsViewLayout.GetMinimumLineSpacingForSection(collectionView, itemsViewLayout, section); var top = uIEdgeInsets.Top; var left = uIEdgeInsets.Left; if (itemsViewLayout.ScrollDirection == UICollectionViewScrollDirection.Horizontal) { left += spacing; } else { top += spacing; } return(new UIEdgeInsets(top, left, uIEdgeInsets.Bottom, uIEdgeInsets.Right)); }
protected override void Dispose(bool disposing) { if (_disposed) { return; } _disposed = true; if (disposing) { ItemsSource?.Dispose(); CollectionView.Delegate = null; Delegator?.Dispose(); _emptyUIView?.Dispose(); _emptyUIView = null; _emptyViewFormsElement = null; ItemsViewLayout?.Dispose(); CollectionView?.Dispose(); } base.Dispose(disposing); }
void CheckForEmptySource() { var wasEmpty = _isEmpty; _isEmpty = ItemsSource.ItemCount == 0; if (_isEmpty) { _measurementCells.Clear(); ItemsViewLayout?.ClearCellSizeCache(); } if (wasEmpty != _isEmpty) { UpdateEmptyViewVisibility(_isEmpty); } if (wasEmpty && !_isEmpty) { // If we're going from empty to having stuff, it's possible that we've never actually measured // a prototype cell and our itemSize or estimatedItemSize are wrong/unset // So trigger a constraint update; if we need a measurement, that will make it happen ItemsViewLayout.ConstrainTo(CollectionView.Bounds.Size); } }
public CarouselViewController(CarouselView itemsView, ItemsViewLayout layout) : base(itemsView, layout) { Carousel = itemsView; CollectionView.AllowsSelection = false; CollectionView.AllowsMultipleSelection = false; Carousel.Scrolled += CarouselViewScrolled; _oldViews = new List <View>(); }
public ReorderableItemsViewController(TItemsView reorderableItemsView, ItemsViewLayout layout) : base(reorderableItemsView, layout) { // The UICollectionViewController has built-in recognizer for reorder that can be installed by setting "InstallsStandardGestureForInteractiveMovement". // For some reason it only seemed to work when the CollectionView was inside the Flyout section of a FlyoutPage. // The UILongPressGestureRecognizer is simple enough to set up so let's just add our own. InstallsStandardGestureForInteractiveMovement = false; }
public virtual void UpdateItemsSource() { _measurementCells.Clear(); ItemsViewLayout?.ClearCellSizeCache(); ItemsSource = CreateItemsViewSource(); CollectionView.ReloadData(); CollectionView.CollectionViewLayout.InvalidateLayout(); }
protected virtual void UpdateDefaultCell(DefaultCell cell, NSIndexPath indexPath) { cell.Label.Text = ItemsSource[indexPath].ToString(); if (cell is ItemsViewCell constrainedCell) { ItemsViewLayout.PrepareCellForLayout(constrainedCell); } }
void ConstrainToItemsView() { var itemsViewWidth = ItemsView.Width; var itemsViewHeight = ItemsView.Height; if (itemsViewHeight < 0 || itemsViewWidth < 0) { ItemsViewLayout.UpdateConstraints(CollectionView.Bounds.Size); return; } ItemsViewLayout.UpdateConstraints(new CGSize(itemsViewWidth, itemsViewHeight)); }
protected virtual void CacheCellAttributes(NSIndexPath indexPath, CGSize size) { if (!ItemsSource.IsIndexPathValid(indexPath)) { // The upate might be coming from a cell that's being removed; don't cache it. return; } var item = ItemsSource[indexPath]; if (item != null) { ItemsViewLayout.CacheCellSize(item, size); } }
internal CGSize GetSizeForItem(NSIndexPath indexPath) { if (ItemsViewLayout.EstimatedItemSize.IsEmpty) { return(ItemsViewLayout.ItemSize); } if (ItemsSource.IsIndexPathValid(indexPath)) { var item = ItemsSource[indexPath]; if (item != null && ItemsViewLayout.TryGetCachedCellSize(item, out CGSize size)) { return(size); } } return(ItemsViewLayout.EstimatedItemSize); }
public void UpdateLayout(ItemsViewLayout newLayout) { // Ignore calls to this method if the new layout is the same as the old one if (CollectionView.CollectionViewLayout == newLayout) { return; } ItemsViewLayout = newLayout; _initialized = false; EnsureLayoutInitialized(); if (_initialized) { // Reload the data so the currently visible cells get laid out according to the new layout CollectionView.ReloadData(); } }
void EnsureLayoutInitialized() { if (_initialized) { return; } _initialized = true; ItemsViewLayout.GetPrototype = GetPrototype; Delegator = CreateDelegator(); CollectionView.Delegate = Delegator; ItemsViewLayout.SetInitialConstraints(CollectionView.Bounds.Size); CollectionView.SetCollectionViewLayout(ItemsViewLayout, false); UpdateEmptyView(); }
protected ItemsViewController(TItemsView itemsView, ItemsViewLayout layout) : base(layout) { ItemsView = itemsView; ItemsViewLayout = layout; }
protected override ItemsViewController <TItemsView> CreateController(TItemsView itemsView, ItemsViewLayout layout) => new ReorderableItemsViewController <TItemsView>(itemsView, layout);
public StructuredItemsViewController(TItemsView structuredItemsView, ItemsViewLayout layout) : base(structuredItemsView, layout) { }
protected override ItemsViewController <TItemsView> CreateController(TItemsView itemsView, ItemsViewLayout layout) => new StructuredItemsViewController <TItemsView>(itemsView, layout);
protected virtual void UpdateLayout() { _layout = SelectLayout(); Controller?.UpdateLayout(_layout); }
public CarouselViewDelegator(ItemsViewLayout itemsViewLayout, CarouselViewController itemsViewController) : base(itemsViewLayout, itemsViewController) { }
public SelectableItemsViewController(TItemsView selectableItemsView, ItemsViewLayout layout) : base(selectableItemsView, layout) { }
protected override CarouselViewController CreateController(CarouselView newElement, ItemsViewLayout layout) => new CarouselViewController(newElement, layout);
protected abstract ItemsViewController <TItemsView> CreateController(TItemsView newElement, ItemsViewLayout layout);
public GroupableItemsViewController(TItemsView groupableItemsView, ItemsViewLayout layout) : base(groupableItemsView, layout) { _isGrouped = ItemsView.IsGrouped; }
public GroupableItemsViewDelegator(ItemsViewLayout itemsViewLayout, TViewController itemsViewController) : base(itemsViewLayout, itemsViewController) { }
public ItemsViewDelegator(ItemsViewLayout itemsViewLayout, TViewController itemsViewController) { ItemsViewLayout = itemsViewLayout; ViewController = itemsViewController; }