Ejemplo n.º 1
0
        public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
        {
            var section   = indexPath.Section;
            var itemIndex = (int)indexPath.Item;

            var(template, info) = Renderer.TemplateSelector.GetTemplateAndInfo(Renderer.Adapter, section, itemIndex);

            var reuseId = info.Kind switch
            {
                PositionKind.Item => itemIdManager.GetReuseId(collectionView, template),
                PositionKind.SectionHeader => sectionHeaderIdManager.GetReuseId(collectionView, template),
                PositionKind.SectionFooter => sectionFooterIdManager.GetReuseId(collectionView, template),
                PositionKind.Header => globalIdManager.GetReuseId(collectionView, template),
                PositionKind.Footer => globalIdManager.GetReuseId(collectionView, template),
                _ => itemIdManager.GetReuseId(collectionView, template)
            };

            if (info.SectionIndex < 0 || info.ItemIndex < 0)
            {
                info.IsSelected = false;
            }
            else
            {
                info.IsSelected = IsSelectedHandler?.Invoke(info.SectionIndex, info.ItemIndex) ?? false;
            }


            var cell = collectionView.DequeueReusableCell(reuseId, indexPath)
                       as CvCell;

            cell.IndexPath = indexPath;
            cell.EnsureFormsTemplate(template, info);

            return(cell);
        }
Ejemplo n.º 2
0
        public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
        {
            var section   = indexPath.Section;
            var itemIndex = (int)indexPath.Item;

            var info = Handler?.PositionalViewSelector?.GetInfo((int)indexPath.Section, (int)indexPath.Item);

            var data = Handler?.PositionalViewSelector?.Adapter?.DataFor(info.Kind, info.SectionIndex, info.ItemIndex);

            var reuseId = Handler?.PositionalViewSelector?.ViewSelector?.GetReuseId(info, data);

            var nativeReuseId = info.Kind switch
            {
                PositionKind.Item => itemIdManager.GetReuseId(collectionView, reuseId),
                PositionKind.SectionHeader => sectionHeaderIdManager.GetReuseId(collectionView, reuseId),
                PositionKind.SectionFooter => sectionFooterIdManager.GetReuseId(collectionView, reuseId),
                PositionKind.Header => globalIdManager.GetReuseId(collectionView, reuseId),
                PositionKind.Footer => globalIdManager.GetReuseId(collectionView, reuseId),
                _ => "UNKNOWN",
            };

            var cell = collectionView.DequeueReusableCell(nativeReuseId, indexPath) as CvCell;

            cell.Handler   = Handler;
            cell.IndexPath = indexPath;
            cell.Init(Handler?.MauiContext);

            cell.ReuseCallback = rv =>
                                 Handler.VirtualView.ViewSelector.ViewDetached(info, cell.VirtualView);

            if (info.SectionIndex < 0 || info.ItemIndex < 0)
            {
                info.IsSelected = false;
            }
            else
            {
                info.IsSelected = IsSelectedHandler?.Invoke(info.SectionIndex, info.ItemIndex) ?? false;
            }

            if (cell.NeedsView)
            {
                var view = Handler?.PositionalViewSelector?.ViewSelector?.CreateView(info, data);
                cell.SwapView(view);
            }

            if (data is IPositionInfo dataPositionInfo)
            {
                dataPositionInfo.SetPositionInfo(info);
            }

            cell.Update(info);

            Handler?.PositionalViewSelector?.ViewSelector?.RecycleView(info, data, cell.Container.VirtualView);

            Handler.VirtualView.ViewSelector.ViewAttached(info, cell.VirtualView);

            return(cell);
        }