コード例 #1
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);
        }
コード例 #2
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));
        }
コード例 #3
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);
        }
コード例 #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);
            }
        }
コード例 #5
0
 public CarouselViewController(CarouselView itemsView, ItemsViewLayout layout) : base(itemsView, layout)
 {
     Carousel = itemsView;
     CollectionView.AllowsSelection         = false;
     CollectionView.AllowsMultipleSelection = false;
     Carousel.Scrolled += CarouselViewScrolled;
     _oldViews          = new List <View>();
 }
コード例 #6
0
 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;
 }
コード例 #7
0
 public virtual void UpdateItemsSource()
 {
     _measurementCells.Clear();
     ItemsViewLayout?.ClearCellSizeCache();
     ItemsSource = CreateItemsViewSource();
     CollectionView.ReloadData();
     CollectionView.CollectionViewLayout.InvalidateLayout();
 }
コード例 #8
0
        protected virtual void UpdateDefaultCell(DefaultCell cell, NSIndexPath indexPath)
        {
            cell.Label.Text = ItemsSource[indexPath].ToString();

            if (cell is ItemsViewCell constrainedCell)
            {
                ItemsViewLayout.PrepareCellForLayout(constrainedCell);
            }
        }
コード例 #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));
        }
コード例 #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);
            }
        }
コード例 #11
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);
        }
コード例 #12
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();
            }
        }
コード例 #13
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();
        }
コード例 #14
0
 protected ItemsViewController(TItemsView itemsView, ItemsViewLayout layout) : base(layout)
 {
     ItemsView       = itemsView;
     ItemsViewLayout = layout;
 }
コード例 #15
0
 protected override ItemsViewController <TItemsView> CreateController(TItemsView itemsView, ItemsViewLayout layout)
 => new ReorderableItemsViewController <TItemsView>(itemsView, layout);
コード例 #16
0
 public StructuredItemsViewController(TItemsView structuredItemsView, ItemsViewLayout layout)
     : base(structuredItemsView, layout)
 {
 }
コード例 #17
0
 protected override ItemsViewController <TItemsView> CreateController(TItemsView itemsView, ItemsViewLayout layout)
 => new StructuredItemsViewController <TItemsView>(itemsView, layout);
コード例 #18
0
 protected virtual void UpdateLayout()
 {
     _layout = SelectLayout();
     Controller?.UpdateLayout(_layout);
 }
コード例 #19
0
 public CarouselViewDelegator(ItemsViewLayout itemsViewLayout, CarouselViewController itemsViewController)
     : base(itemsViewLayout, itemsViewController)
 {
 }
コード例 #20
0
 public SelectableItemsViewController(TItemsView selectableItemsView, ItemsViewLayout layout)
     : base(selectableItemsView, layout)
 {
 }
コード例 #21
0
 protected override CarouselViewController CreateController(CarouselView newElement, ItemsViewLayout layout)
 => new CarouselViewController(newElement, layout);
コード例 #22
0
 protected abstract ItemsViewController <TItemsView> CreateController(TItemsView newElement, ItemsViewLayout layout);
コード例 #23
0
 public GroupableItemsViewController(TItemsView groupableItemsView, ItemsViewLayout layout)
     : base(groupableItemsView, layout)
 {
     _isGrouped = ItemsView.IsGrouped;
 }
コード例 #24
0
 public GroupableItemsViewDelegator(ItemsViewLayout itemsViewLayout, TViewController itemsViewController)
     : base(itemsViewLayout, itemsViewController)
 {
 }
コード例 #25
0
 public ItemsViewDelegator(ItemsViewLayout itemsViewLayout, TViewController itemsViewController)
 {
     ItemsViewLayout = itemsViewLayout;
     ViewController  = itemsViewController;
 }