Example #1
0
        public UICollectionViewCell CreateMeasurementCell(NSIndexPath indexPath)
        {
            if (ItemsView.ItemTemplate == null)
            {
                var frame = new CGRect(0, 0, ItemsViewLayout.EstimatedItemSize.Width, ItemsViewLayout.EstimatedItemSize.Height);

                DefaultCell cell;
                if (ItemsViewLayout.ScrollDirection == UICollectionViewScrollDirection.Horizontal)
                {
                    cell = new HorizontalDefaultCell(frame);
                }
                else
                {
                    cell = new VerticalDefaultCell(frame);
                }

                UpdateDefaultCell(cell, indexPath);
                return(cell);
            }

            TemplatedCell templatedCell = CreateAppropriateCellForLayout();

            UpdateTemplatedCell(templatedCell, indexPath);

            // Keep this cell around, we can transfer the contents to the actual cell when the UICollectionView creates it
            _measurementCells[ItemsSource[indexPath]] = templatedCell;

            return(templatedCell);
        }
Example #2
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 #3
0
 internal void UseContent(TemplatedCell measurementCell)
 {
     // Copy all the content and values from the measurement cell
     ConstrainedDimension = measurementCell.ConstrainedDimension;
     ConstrainedSize      = measurementCell.ConstrainedSize;
     CurrentTemplate      = measurementCell.CurrentTemplate;
     _size = measurementCell._size;
     SetRenderer(measurementCell.VisualElementRenderer);
 }
Example #4
0
        void UpdateTemplatedSupplementaryView(TemplatedCell cell, NSString elementKind, NSIndexPath indexPath)
        {
            DataTemplate template = elementKind == UICollectionElementKindSectionKey.Header
                                ? ItemsView.GroupHeaderTemplate
                                : ItemsView.GroupFooterTemplate;

            var bindingContext = ItemsSource.Group(indexPath);

            cell.Bind(template, bindingContext, ItemsView);

            if (cell is ItemsViewCell)
            {
                cell.ConstrainTo(GetLayoutSpanCount() * ItemsViewLayout.ConstrainedDimension);
            }
        }
Example #5
0
        // These measurement methods are only necessary for iOS 10 and lower
        CGSize MeasureTemplatedSupplementaryCell(NSString elementKind, nint section, NSString reuseId)
        {
            if (_measurementCellTemplated == null)
            {
                if (reuseId == HorizontalSupplementaryView.ReuseId)
                {
                    _measurementCellTemplated = new HorizontalSupplementaryView(CGRect.Empty);
                }
                else if (reuseId == VerticalSupplementaryView.ReuseId)
                {
                    _measurementCellTemplated = new VerticalSupplementaryView(CGRect.Empty);
                }
            }

            if (_measurementCellTemplated == null)
            {
                return(CGSize.Empty);
            }

            UpdateTemplatedSupplementaryView(_measurementCellTemplated, elementKind, NSIndexPath.FromItemSection(0, section));
            return(_measurementCellTemplated.Measure());
        }