Example #1
0
        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));
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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);
            }
        }
Example #5
0
 public virtual void UpdateItemsSource()
 {
     _measurementCells.Clear();
     ItemsViewLayout?.ClearCellSizeCache();
     ItemsSource = CreateItemsViewSource();
     CollectionView.ReloadData();
     CollectionView.CollectionViewLayout.InvalidateLayout();
 }
Example #6
0
        protected virtual void UpdateLayout()
        {
            _layout = SelectLayout();

            if (Controller != null)
            {
                Controller.UpdateLayout(_layout);
            }
        }
Example #7
0
        protected virtual void UpdateDefaultCell(DefaultCell cell, NSIndexPath indexPath)
        {
            cell.Label.Text = ItemsSource[indexPath].ToString();

            if (cell is ItemsViewCell constrainedCell)
            {
                ItemsViewLayout.PrepareCellForLayout(constrainedCell);
            }
        }
Example #8
0
 public CarouselViewController(CarouselView itemsView, ItemsViewLayout layout) : base(itemsView, layout)
 {
     Carousel = itemsView;
     CollectionView.AllowsSelection         = false;
     CollectionView.AllowsMultipleSelection = false;
     Carousel.PropertyChanged += CarouselViewPropertyChanged;
     Carousel.Scrolled        += CarouselViewScrolled;
     _oldViews = new List <View>();
 }
Example #9
0
        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));
        }
Example #10
0
		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);
			}
		}
Example #11
0
		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();
			}
		}
Example #12
0
        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();
        }
Example #13
0
        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);
        }
Example #14
0
 protected ItemsViewController(TItemsView itemsView, ItemsViewLayout layout) : base(layout)
 {
     ItemsView       = itemsView;
     ItemsViewLayout = layout;
 }
Example #15
0
 public SelectableItemsViewController(TItemsView selectableItemsView, ItemsViewLayout layout)
     : base(selectableItemsView, layout)
 {
 }
Example #16
0
 protected override CarouselViewController CreateController(CarouselView newElement, ItemsViewLayout layout)
 {
     return(new CarouselViewController(newElement, layout));
 }
Example #17
0
 protected override ItemsViewLayout SelectLayout() =>
 _layout = new CarouselViewLayout(Carousel.ItemsLayout, Carousel);
Example #18
0
 protected override TViewController CreateController(TItemsView itemsView, ItemsViewLayout layout)
 {
     return(new GroupableItemsViewController <TItemsView>(itemsView, layout) as TViewController);
 }
Example #19
0
 protected abstract TViewController CreateController(TItemsView newElement, ItemsViewLayout layout);
 public StructuredItemsViewController(TItemsView structuredItemsView, ItemsViewLayout layout)
     : base(structuredItemsView, layout)
 {
 }
Example #21
0
 public CarouselViewDelegator(ItemsViewLayout itemsViewLayout, CarouselViewController itemsViewController)
     : base(itemsViewLayout, itemsViewController)
 {
 }
Example #22
0
 public SelectableItemsViewDelegator(ItemsViewLayout itemsViewLayout, TViewController itemsViewController)
     : base(itemsViewLayout, itemsViewController)
 {
 }
Example #23
0
 public GroupableItemsViewController(TItemsView groupableItemsView, ItemsViewLayout layout)
     : base(groupableItemsView, layout)
 {
     _isGrouped = ItemsView.IsGrouped;
 }
Example #24
0
 public ItemsViewDelegator(ItemsViewLayout itemsViewLayout, TViewController itemsViewController)
 {
     ItemsViewLayout = itemsViewLayout;
     ViewController  = itemsViewController;
 }