public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath)
        {
            if (lastSelectedCell != null) {
                lastSelectedCell.BackgroundColor = UIColor.Clear;
            }

            var cell = collectionView.CellForItem (indexPath);
            cell.BackgroundColor = UIColor.Cyan;

            lastSelectedCell = cell;

            if (cell is FriendsPuzzleListCellViewController) {
            //				var friendsCell = cell as FriendsPuzzleListCellViewController;
            //				var puzzle = puzzlesWitHFriends [indexPath.Item - 1];

            } else if (cell is FriendsPuzzleListNewCellViewController) {

                var vc = this.Storyboard.InstantiateViewController("MenuCreateViewController") as MenuCreateViewController;
                vc.IsFriendMatch = true;

                NavigationController.PushViewController(
                    vc,
                    true
                    );
            }
        }
 protected UIImage RastertizedImage(UICollectionViewCell cell)
 {
     UIGraphics.BeginImageContextWithOptions(cell.Bounds.Size, cell.Opaque, 0.0f);
     cell.Layer.RenderInContext(UIGraphics.GetCurrentContext());
     var img = UIGraphics.GetImageFromCurrentImageContext();
     UIGraphics.EndImageContext();
     return img;
 }
		public override void WillDisplayCell (UICollectionView collectionView, UICollectionViewCell cell, NSIndexPath indexPath)
		{
			var currentCell = cell as CollectionViewContainerCell;
			if (currentCell == null)
				throw new Exception ("Expected to display a `CollectionViewContainerCell`.");

			var sectionDataItems = DataItemsByGroup [indexPath.Section];
			currentCell.ConfigureWithDataItems (sectionDataItems);
		}
        public override void WillDisplayCell(UICollectionView collectionView, UICollectionViewCell cell, NSIndexPath indexPath)
        {
            var currentCell = cell as DataItemCollectionViewCell;
            if (currentCell == null)
                throw new Exception ("Expected to display a `DataItemCollectionViewCell`.");

            var item = filteredDataItems[indexPath.Row];
            cellComposer.ComposeCell (currentCell, item);
        }
		public void WillDisplayCell (UICollectionView collectionView, UICollectionViewCell cell, NSIndexPath indexPath)
		{
			var currentCell = cell as DataItemCollectionViewCell;
			if (currentCell == null)
				throw new Exception ("Expected to display a DataItemCollectionViewCell");

			var item = dataItems [indexPath.Section];

			// Configure the cell.
			cellComposer.ComposeCell (currentCell, item);
		}
        public override void CellDisplayingEnded(UICollectionView collectionView, UICollectionViewCell cell, NSIndexPath indexPath)
        {
            var key = cell as ListViewBaseInternalContainer;

            if (_onRecycled.TryGetValue(key, out var actions))
            {
                foreach (var a in actions)
                {
                    a();
                }
                _onRecycled.Remove(key);
            }

            if (this.Log().IsEnabled(LogLevel.Debug))
            {
                this.Log().LogDebug($"CellDisplayingEnded for cell at {indexPath}");
            }
        }
        void UpdateSelectionForCell(UICollectionViewCell cell)
        {
            if (cell == null)
            {
                return;
            }

            bool isSelected = cell.Selected;

            UIImageView imageView = (UIImageView)cell.ViewWithTag(999);

            imageView.Layer.BorderColor = View.TintColor.CGColor;
            imageView.Layer.BorderWidth = isSelected ? 2 : 0;

            UILabel label = (UILabel)cell.ViewWithTag(998);

            label.TextColor = isSelected ? View.TintColor : UIColor.White;
        }
Example #8
0
        internal UICollectionViewCell CellForItem(UICollectionView view, NSIndexPath path)
        {
            if (path == null)
            {
                return(null);
            }
            UICollectionViewCell cell = view.CellForItem(path);

            if (cell != null)
            {
                return(cell);
            }
            if (_lastCreatedCellPath != null && path.Equals(_lastCreatedCellPath))
            {
                return(_lastCreatedCell);
            }
            return(null);
        }
Example #9
0
        public override void WillDisplayCell(UICollectionView collectionView, UICollectionViewCell cell, NSIndexPath indexPath)
        {
            var index        = Owner?.XamlParent?.GetIndexFromIndexPath(IndexPath.FromNSIndexPath(indexPath)) ?? -1;
            var container    = cell as ListViewBaseInternalContainer;
            var selectorItem = container?.Content as SelectorItem;

            //Update IsSelected immediately before display, in case it was modified after cell was prefetched but before it became visible
            if (selectorItem != null)
            {
                selectorItem.IsSelected = Owner?.XamlParent?.IsSelected(index) ?? false;
            }

            FrameworkElement.RegisterPhaseBinding(container.Content, a => RegisterForRecycled(container, a));

            if (this.Log().IsEnabled(LogLevel.Debug))
            {
                this.Log().LogDebug($"WillDisplayCell for cell at {indexPath}");
            }
        }
        public static void SetupStyle(this UICollectionViewCell self, View model)
        {
            if (model == null)
            {
                return;
            }

            if (model.Layer != null)
            {
                self.Layer.SetupStyle(model.Layer);

                if (self.ContentView != null)
                {
                    self.ContentView.Layer.SetupStyle(null, model.Layer.Border, model.Layer.CornerRadius, true, model.Layer.Background);
                }
            }

            self.BackgroundColor = model.Background?.ToUIColor() ?? UIColor.Clear;
        }
        public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
        {
            UICollectionViewCell cell = (UICollectionViewCell)CollectionView.DequeueReusableCell(reuseIdentifier, indexPath);

            UIImageView image = (UIImageView)cell.ViewWithTag(1);

            image.Image = UIImage.FromBundle(list[indexPath.Row].Key);

            UILabel label = (UILabel)cell.ViewWithTag(2);

            label.Text = list[indexPath.Row].Value;

            cell.Layer.MasksToBounds = false;
            cell.Layer.ShadowOffset  = new CoreGraphics.CGSize(0, 1);
            cell.Layer.ShadowRadius  = 1;
            cell.Layer.ShadowColor   = UIColor.Black.CGColor;
            cell.Layer.ShadowOpacity = 0.2f;

            return(cell);
        }
        public override void CellDisplayingEnded(UICollectionView collectionView, UICollectionViewCell cell, NSIndexPath indexPath)
        {
            if (ItemsViewLayout.ScrollDirection == UICollectionViewScrollDirection.Horizontal)
            {
                var actualWidth = collectionView.ContentSize.Width - collectionView.Bounds.Size.Width;
                if (collectionView.ContentOffset.X >= actualWidth || collectionView.ContentOffset.X < 0)
                {
                    return;
                }
            }
            else
            {
                var actualHeight = collectionView.ContentSize.Height - collectionView.Bounds.Size.Height;

                if (collectionView.ContentOffset.Y >= actualHeight || collectionView.ContentOffset.Y < 0)
                {
                    return;
                }
            }
        }
Example #13
0
        public override void WillDisplayCell(UICollectionView collectionView, UICollectionViewCell cell,
                                             NSIndexPath indexPath)
        {
            switch (indexPath.Section)
            {
            case var section when section == Layout.Configuration.SectionIndexForActions:
                _delegate?.WillDisplayActionCell(cell, indexPath.Row);
                break;

            case var section when section == Layout.Configuration.SectionIndexForCamera:
                _delegate?.WillDisplayCameraCell(cell as CameraCollectionViewCell);
                break;

            case var section when section == Layout.Configuration.SectionIndexForAssets:
                _delegate?.WillDisplayAssetCell(cell as ImagePickerAssetCell, indexPath.Row);
                break;

            default: throw new ImagePickerException("index path not supported");
            }
        }
        public override void WillDisplayActionItem(ImagePickerController controller, UICollectionViewCell cell,
                                                   int index)
        {
            if (cell is IconWithTextCell iconWithTextCell)
            {
                iconWithTextCell.TitleLabel.TextColor = UIColor.Black;

                switch (index)
                {
                case 0:
                    iconWithTextCell.TitleLabel.Text = "Camera";
                    iconWithTextCell.ImageView.Image = UIImageExtensions.FromBundle(BundleAssets.ButtonCamera);
                    break;

                case 1:
                    iconWithTextCell.TitleLabel.Text = "Photos";
                    iconWithTextCell.ImageView.Image =
                        UIImageExtensions.FromBundle(BundleAssets.ButtonPhotoLibrary);
                    break;
                }
            }
        }
Example #15
0
        public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
        {
            var selector = _itemTemplateProvider.CollectionCellTemplateSelector;

            if (selector == null)
            {
                throw new NotSupportedException("The ItemTemplate is null to create UICollectionViewCell use the ItemTemplate with ICollectionCellTemplateSelector value.");
            }
            object item = GetItemAt(indexPath);
            UICollectionViewCell cell;

            if (selector is ICollectionCellTemplateSelectorSupportDequeueReusableCell)
            {
                cell = ((ICollectionCellTemplateSelectorSupportDequeueReusableCell)selector).DequeueReusableCell(collectionView, item, indexPath);
            }
            else
            {
                cell = (UICollectionViewCell)collectionView.DequeueReusableCell(selector.GetIdentifier(item, collectionView), indexPath);
            }

            _lastCreatedCell     = cell;
            _lastCreatedCellPath = indexPath;

            if (Equals(item, _selectedItem) && !cell.Selected)
            {
                collectionView.SelectItem(indexPath, false, UICollectionViewScrollPosition.None);
            }
            cell.Tag |= InitializingStateMask;
            cell.SetDataContext(item);
            if (!HasMask(cell, InitializedStateMask))
            {
                cell.Tag |= InitializedStateMask;
                ParentObserver.GetOrAdd(cell).Parent = collectionView;
                selector.InitializeTemplate(collectionView, cell);
            }
            cell.Tag &= ~InitializingStateMask;
            (cell as IHasDisplayCallback)?.WillDisplay();
            return(cell);
        }
Example #16
0
        private void UpdateCellLayer(UICollectionViewCell cell, nfloat sx, nfloat sy, int zPosition, nfloat alpha)
        {
            cell.Transform       = CGAffineTransform.MakeScale(sx, sy);
            cell.Layer.ZPosition = zPosition;

            foreach (var subView in cell.ContentView.Subviews)
            {
                if (subView.GetType() == typeof(UIImageView) && baseCellImage != null)
                {
                    if (alpha != 1)
                    {
                        var newImage = ChangeImageColor(baseCellImage, alpha, fadeColor);
                        (subView as UIImageView).Image = newImage;
                    }
                    else
                    {
                        var newImage = ChangeImageToColor(baseCellImage, alpha, fadeColor);
                        (subView as UIImageView).Image = newImage;
                    }
                }
            }
        }
        public virtual bool UpdateSelectedBindValue(UICollectionViewCell cell, bool selected)
        {
            var collectionView = CollectionView;

            if (collectionView == null || collectionView.AllowsMultipleSelection)
            {
                return(selected);
            }

            if (!collectionView.AllowsSelection)
            {
                return(false);
            }
            if (HasMask(cell, InitializingStateMask))
            {
                if (Equals(cell.DataContext(), SelectedItem))
                {
                    return(true);
                }
                return(selected && SelectedItem == null);
            }
            return(selected);
        }
Example #18
0
        public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
        {
            var selector = _itemTemplateMember.TryGetValue <ICollectionCellTemplateSelector>(collectionView);

            if (selector == null)
            {
                throw new NotSupportedException(
                          "The ItemTemplate is null to create UICollectionViewCell use the ItemTemplate with ICollectionCellTemplateSelector value.");
            }
            object   item       = GetItemAt(indexPath);
            NSString identifier = selector.GetIdentifier(item, collectionView);
            var      cell       = (UICollectionViewCell)collectionView.DequeueReusableCell(identifier, indexPath);

            if (!BindingServiceProvider.ContextManager.HasBindingContext(cell))
            {
                selector.InitializeTemplate(collectionView, cell);
            }

            SetCellContext(collectionView, cell, indexPath, item);
            _lastCreatedCell     = cell;
            _lastCreatedCellPath = indexPath;
            return(cell);
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                _lastCreatedCell     = null;
                _lastCreatedCellPath = null;
                _selectedItem        = null;

                var collectionView = CollectionView;
                if (collectionView.IsAlive())
                {
                    if (ReferenceEquals(collectionView.Source, this))
                    {
                        collectionView.Source = null;
                    }
                    var controllerView = collectionView.FindParent <IViewControllerView>();
                    if (controllerView != null && _listener != null)
                    {
                        controllerView.Mediator.DisposeHandler -= _listener.Handle;
                    }
                }
            }
            base.Dispose(disposing);
        }
        public virtual void OnCellSelectionChanged(UICollectionViewCell cell, bool selected, bool setFromBinding)
        {
            var collectionView = CollectionView;

            if (!setFromBinding || collectionView == null)
            {
                return;
            }
            UpdateSelectedItemInternal(collectionView, cell.DataContext(), selected);
            var path = IndexPathForCell(collectionView, cell);

            if (path == null)
            {
                return;
            }
            if (selected)
            {
                collectionView.SelectItem(path, false, UICollectionViewScrollPosition.None);
            }
            else
            {
                collectionView.DeselectItem(path, false);
            }
        }
        public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
        {
            UICollectionViewCell cell = (UICollectionViewCell)collectionView.DequeueReusableCell("textReuseCell", indexPath);

            cell.BackgroundColor = UIColor.Clear;

            UIButton label  = (UIButton)cell.ViewWithTag(500);
            UIButton labelX = (UIButton)cell.ViewWithTag(510);

            labelX.TouchUpInside += (sender, e) =>
            {
                if (controller.TypesIndexPath != indexPath)
                {
                    HighlightCell(label, labelX, collectionView, indexPath);
                }
            };

            label.TouchUpInside += (sender, e) =>
            {
                if (controller.TypesIndexPath != indexPath)
                {
                    HighlightCell(label, labelX, collectionView, indexPath);
                }
            };

            label.SetTitle(string.Empty, UIControlState.Normal);
            labelX.SetTitle(string.Empty, UIControlState.Normal);

            Control item = samplesCollections.GetItem <Control>((nuint)indexPath.Row);

            NSString sampleName = item.Name;
            NSString dispName   = item.DisplayName;

            dispName = string.IsNullOrEmpty(dispName) ? sampleName : dispName;

            UIImageView tag = (UIImageView)cell.ViewWithTag(502);

            if (item.Tag == "NEW")
            {
                label.SetTitle(dispName, UIControlState.Normal);
                tag.Image = UIImage.FromBundle("Controls/Tags/x_new.png");
            }
            else if (item.Tag == "UPDATED")
            {
                label.SetTitle(dispName, UIControlState.Normal);
                tag.Image = UIImage.FromBundle("Controls/Tags/x_update.png");
            }
            else
            {
                labelX.SetTitle(dispName, UIControlState.Normal);
                tag.Image = null;
            }

            label.SetTitleColor(UIColor.FromRGB(45.0f / 255.0f, 45.0f / 255.0f, 45.0f / 255.0f), UIControlState.Normal);
            labelX.SetTitleColor(UIColor.FromRGB(45.0f / 255.0f, 45.0f / 255.0f, 45.0f / 255.0f), UIControlState.Normal);
            label.SetTitleColor(UIColor.FromRGB(45.0f / 255.0f, 45.0f / 255.0f, 45.0f / 255.0f), UIControlState.Highlighted);
            labelX.SetTitleColor(UIColor.FromRGB(45.0f / 255.0f, 45.0f / 255.0f, 45.0f / 255.0f), UIControlState.Highlighted);

            if (indexPath.Row == (int)controller.TypesIndexPath.Row)
            {
                label.SetTitleColor(Utility.ThemeColor, UIControlState.Normal);
                labelX.SetTitleColor(Utility.ThemeColor, UIControlState.Normal);
            }

            return(cell);
        }
        void UpdateSelectionForCell(UICollectionViewCell cell)
        {
            if (cell == null)
                return;

            bool isSelected = cell.Selected;

            UIImageView imageView = (UIImageView)cell.ViewWithTag (999);
            imageView.Layer.BorderColor = View.TintColor.CGColor;
            imageView.Layer.BorderWidth = isSelected ? 2 : 0;

            UILabel label = (UILabel)cell.ViewWithTag (998);
            label.TextColor = isSelected ? View.TintColor : UIColor.White;
        }
Example #23
0
        public static NSIndexPath IndexPathForCellEx(this UICollectionView collectionView, UICollectionViewCell cell)
        {
            Should.NotBeNull(collectionView, "collectionView");
            var sourceBase = collectionView.Source as CollectionViewSourceBase;

            if (sourceBase == null)
            {
                return(collectionView.IndexPathForCell(cell));
            }
            return(sourceBase.IndexPathForCell(collectionView, cell));
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                _lastCreatedCell = null;
                _lastCreatedCellPath = null;
                _selectedItem = null;

                var collectionView = CollectionView;
                if (collectionView.IsAlive())
                {
                    if (ReferenceEquals(collectionView.Source, this))
                        collectionView.Source = null;
                    var controllerView = collectionView.FindParent<IViewControllerView>();
                    if (controllerView != null && _listener != null)
                        controllerView.Mediator.DisposeHandler -= _listener.Handle;
                }
            }
            base.Dispose(disposing);
        }
 public override void CellDisplayingEnded(UICollectionView collectionView, UICollectionViewCell cell,
     NSIndexPath indexPath)
 {
     cell.SetDataContext(null);
     var callback = cell as IHasDisplayCallback;
     if (callback != null)
         callback.DisplayingEnded();
 }
 internal static bool HasMask(UICollectionViewCell cell, int mask)
 {
     return (cell.Tag & mask) == mask;
 }
        public virtual bool UpdateSelectedBindValue(UICollectionViewCell cell, bool selected)
        {
            var collectionView = CollectionView;
            if (collectionView == null || collectionView.AllowsMultipleSelection)
                return selected;

            if (!collectionView.AllowsSelection)
                return false;
            if (HasMask(cell, InitializingStateMask))
            {
                if (Equals(cell.GetDataContext(), SelectedItem))
                    return true;
                return selected && SelectedItem == null;
            }
            return selected;
        }
Example #28
0
 public override void WillDisplayCell(UICollectionView collectionView, UICollectionViewCell cell, NSIndexPath indexPath)
 {
     customView.RaiseAppeared(indexPath.Row);
 }
 void ICollectionCellTemplateSelector.InitializeTemplate(UICollectionView container, UICollectionViewCell cell)
 {
     if (!SupportInitialize)
     {
         return;
     }
     if (_bindingSet == null)
     {
         _bindingSet = new BindingSet <TTemplate, TSource>(null);
     }
     try
     {
         _bindingSet.Target = (TTemplate)cell;
         InitializeTemplate(container, _bindingSet.Target, _bindingSet);
         _bindingSet.Apply();
     }
     finally
     {
         _bindingSet.Target = null;
     }
 }
 public override void CellDisplayingEnded(UICollectionView collectionView, UICollectionViewCell cell, NSIndexPath indexPath)
 {
     CellMediator.Deattach(cell);
 }
 public override void CellDisplayingEnded(UICollectionView collectionView, UICollectionViewCell cell, NSIndexPath indexPath)
 {
     ItemsViewController.PrepareCellForRemoval(cell);
 }
        void HandleLongPressGesture(UILongPressGestureRecognizer sender)
        {
            if (sender.State == UIGestureRecognizerState.Changed)
            {
                return;
            }

            if (!this.CollectionView.DataSource.ConformsToProtocol(Runtime.GetProtocol("UICollectionViewDataSource")))
            {
                return;
            }

            _hasShouldAlterTranslationDelegateMethod = this.CollectionView.DataSource.RespondsToSelector(new Selector("collectionView:alterTranslation:"));
            PointF      point     = sender.LocationInView(this.CollectionView);
            NSIndexPath indexPath = this.IndexPathForItemClosestToPoint(point);

            switch (sender.State)
            {
            case UIGestureRecognizerState.Began:

            {
                if (indexPath == null)
                {
                    return;
                }

                if (!((UICollectionViewDataSourceDraggable)this.CollectionView.DataSource).CollectionViewCanMoveItemAtIndexPath(this.CollectionView, indexPath))
                {
                    return;
                }

                UICollectionViewCell cell = this.CollectionView.CellForItem(indexPath);
                cell.Highlighted = false;
                mockCell.RemoveFromSuperview();
                mockCell       = new UIImageView(cell.Frame);
                mockCell.Alpha = 0.8f;
                if (this.CollectionView.DataSource.RespondsToSelector(new Selector("collectionView:imageForDraggingItemAtIndexPath:")))
                {
                    mockCell.Image = ((UICollectionViewDataSourceDraggable)this.CollectionView.DataSource).CollectionViewImageForDraggingItemAtIndexPath(this.CollectionView, indexPath);
                }

                if (mockCell.Image == null)
                {
                    mockCell.Image = this.ImageFromCell(cell);
                }

                mockCell.SizeToFit();
                mockCell.Layer.MasksToBounds = false;
                mockCell.Layer.ShadowColor   = UIColor.Black.CGColor;
                mockCell.Layer.ShadowOpacity = (0.65f);
                mockCell.Layer.ShadowRadius  = (10.0f);
                mockCell.Layer.ShadowOffset  = (new SizeF(0, 0));
                mockCell.Layer.ShadowPath    = (UIBezierPath.FromRect(mockCell.Bounds).CGPath);
                mockCenter = mockCell.Center;
                this.CollectionView.AddSubview(mockCell);
                if (this.DropOnToDeleteView != null)
                {
                    bool canDelete = false;
                    if (this.CollectionView.DataSource.RespondsToSelector(new Selector("collectionView:canDeleteItemAtIndexPath:")))
                    {
                        canDelete = ((UICollectionViewDataSourceDraggable)this.CollectionView.DataSource).CollectionViewCanDeleteItemAtIndexPath(this.CollectionView, indexPath);
                    }

                    if (canDelete)
                    {
                        RectangleF bounds = this.CollectionView.Bounds;
                        this.DropOnToDeleteView.Center      = new PointF(bounds.GetMinX() + _dropOnToDeleteViewCenter.X, bounds.GetMinY() + _dropOnToDeleteViewCenter.Y);
                        this.DropOnToDeleteView.Highlighted = false;
                        this.CollectionView.AddSubview(this.DropOnToDeleteView);
                        this.DropOnToDeleteView.Alpha = 0.2f;
                    }
                }

                if (this.CollectionView.DataSource.RespondsToSelector(new Selector("collectionView:transformForDraggingItemAtIndexPath:duration:")))
                {
                    TimeInterval      duration  = 0.3;
                    CGAffineTransform transform = ((UICollectionViewDataSourceDraggable)this.CollectionView.DataSource).CollectionViewTransformForDraggingItemAtIndexPathDuration(this.CollectionView, indexPath, duration);
                    UIView.Animate(duration, delegate()
                        {
                            mockCell.Transform = transform;
                        }, null);
                }

                lastIndexPath = indexPath;
                this.LayoutHelper.FromIndexPath = indexPath;
                this.LayoutHelper.HideIndexPath = indexPath;
                this.LayoutHelper.ToIndexPath   = indexPath;
                this.CollectionView.CollectionViewLayout.InvalidateLayout();
            }
            break;

            case UIGestureRecognizerState.Ended:
            case UIGestureRecognizerState.Cancelled:

            {
                if (this.LayoutHelper.FromIndexPath == null)
                {
                    return;
                }

                NSIndexPath fromIndexPath = this.LayoutHelper.FromIndexPath;
                NSIndexPath toIndexPath   = this.LayoutHelper.ToIndexPath;
                UICollectionViewDataSourceDraggable dataSource = (UICollectionViewDataSourceDraggable)this.CollectionView.DataSource;
                bool toDelete = sender.State == UIGestureRecognizerState.Ended && this.DropOnToDeleteView.Highlighted;
                if (toDelete)
                {
                    this.CollectionView.PerformBatchUpdates(delegate()
                        {
                            dataSource.CollectionViewDeleteItemAtIndexPath(this.CollectionView, fromIndexPath);
                            this.CollectionView.DeleteItems(new NSIndexPath[] { fromIndexPath });
                            this.LayoutHelper.FromIndexPath = null;
                            this.LayoutHelper.ToIndexPath   = null;
                        }, delegate(bool finished)
                        {
                            if (((NSObject)dataSource).RespondsToSelector(new Selector("collectionView:didDeleteItemAtIndexPath:")))
                            {
                                dataSource.CollectionViewDidDeleteItemAtIndexPath(this.CollectionView, fromIndexPath);
                            }
                        });
                    UIView.Animate(0.3, delegate()
                        {
                            mockCell.Center               = this.DropOnToDeleteView.Center;
                            mockCell.Transform            = CGAffineTransform.Scale(CGAffineTransform.MakeRotation(10), 0.01f, 0.01f);
                            this.DropOnToDeleteView.Alpha = 0.0f;
                        },                                 //delegate(bool finished)
                                   delegate()
                        {
                            mockCell.RemoveFromSuperview();
                            mockCell = null;
                            this.DropOnToDeleteView.RemoveFromSuperview();
                            this.DropOnToDeleteView.Alpha   = 1.0f;
                            this.LayoutHelper.HideIndexPath = null;
                            this.CollectionView.CollectionViewLayout.InvalidateLayout();
                        });
                }
                else
                {
                    this.CollectionView.PerformBatchUpdates(delegate()
                        {
                            dataSource.CollectionViewMoveItemAtIndexPathToIndexPath(this.CollectionView, fromIndexPath, toIndexPath);
                            this.CollectionView.MoveItem(fromIndexPath, toIndexPath);
                            this.LayoutHelper.FromIndexPath = null;
                            this.LayoutHelper.ToIndexPath   = null;
                        }, delegate(bool finished)
                        {
                            if (((NSObject)dataSource).RespondsToSelector(new Selector("collectionView:didMoveItemAtIndexPath:toIndexPath:")))
                            {
                                dataSource.CollectionViewDidMoveItemAtIndexPathToIndexPath(this.CollectionView, fromIndexPath, toIndexPath);
                            }
                        });
                    UICollectionViewLayoutAttributes layoutAttributes = this.CollectionView.GetLayoutAttributesForItem(this.LayoutHelper.HideIndexPath);
                    UIView.Animate(0.3, delegate()
                        {
                            RectangleF frame   = layoutAttributes.Frame;
                            frame.Size         = mockCell.Frame.Size;
                            mockCell.Frame     = frame;
                            mockCell.Transform = CGAffineTransform.MakeIdentity();
                        },                                 //delegate(bool finished)
                                   delegate()
                        {
                            mockCell.RemoveFromSuperview();
                            mockCell = null;
                            this.DropOnToDeleteView.RemoveFromSuperview();
                            this.LayoutHelper.HideIndexPath = null;
                            this.CollectionView.CollectionViewLayout.InvalidateLayout();
                        });
                }

                this.InvalidatesScrollTimer();
                lastIndexPath = null;
            }
            break;

            default:
                break;
            }
        }
Example #33
0
 protected override Action <NSObject> GetGestureActionForCell(UICollectionViewCell cell)
 {
     return(longPressAction);
 }
        void ICollectionCellTemplateSelector.InitializeTemplate(UICollectionView container, UICollectionViewCell cell)
        {
            if (!SupportInitialize)
            {
                return;
            }
            var bindingSet = new BindingSet <TTemplate, TSource>((TTemplate)cell);

            InitializeTemplate(container, (TTemplate)cell, bindingSet);
            bindingSet.Apply();
        }
Example #35
0
		public virtual UIView GetView (UICollectionViewCell value)
		{
			var layout = new UICollectionViewFlowLayout ();
			var bounds = UIScreen.MainScreen.Bounds;
			var collectionView = new UICollectionView (
				                     bounds,
				                     layout);
			layout.ItemSize = new CGSize (bounds.Width / 3, bounds.Width / 4);
			collectionView.RegisterClassForCell (typeof (HostCell), "C");
			collectionView.DataSource = new SingleCollectionViewCellDataSource (value);
			return collectionView;
		}
 public override void CellDisplayingEnded(UICollectionView collectionView, UICollectionViewCell cell, NSIndexPath indexPath)
 {
     var bindable = cell as IMvxDataConsumer;
     if (bindable != null)
         bindable.DataContext = null;
 }
Example #37
0
			public SingleCollectionViewCellDataSource (UICollectionViewCell cell)
			{
				this.cell = cell;
			}
 public virtual void OnCellSelectionChanged(UICollectionViewCell cell, bool selected, bool setFromBinding)
 {
     var collectionView = CollectionView;
     if (!setFromBinding || collectionView == null)
         return;
     UpdateSelectedItemInternal(collectionView, cell.GetDataContext(), selected);
     var path = IndexPathForCell(collectionView, cell);
     if (path == null)
         return;
     if (selected)
         collectionView.SelectItem(path, false, UICollectionViewScrollPosition.None);
     else
         collectionView.DeselectItem(path, false);
 }
Example #39
0
        public override void WillDisplayCell(UICollectionView collectionView, UICollectionViewCell cell, NSIndexPath indexPath)
        {
            var container = cell as InternalContainer;

            FrameworkElement.RegisterPhaseBinding(container.Content, a => RegisterForRecycled(container, a));
        }
 internal NSIndexPath IndexPathForCell(UICollectionView collectionView, UICollectionViewCell cell)
 {
     if (ReferenceEquals(cell, _lastCreatedCell))
         return _lastCreatedCellPath;
     return collectionView.IndexPathForCell(cell);
 }
        public override void CellDisplayingEnded(UICollectionView collectionView, UICollectionViewCell cell, NSIndexPath indexPath)
        {
            //Don't bind to NULL to speed up cells in lists when fast scrolling
            //There should be almost no scenario in which this is required
            //If it is required, do this in your own subclass using this code:

            //var bindable = cell as IMvxDataConsumer;
            //if (bindable != null)
            //    bindable.DataContext = null;
        }
        public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
        {
            var selector = _itemTemplateMember == null
                ? null
                : _itemTemplateMember.GetValue(collectionView, null) as ICollectionCellTemplateSelector;
            if (selector == null)
                throw new NotSupportedException("The ItemTemplate is null to create UICollectionViewCell use the ItemTemplate with ICollectionCellTemplateSelector value.");
            object item = GetItemAt(indexPath);
            NSString identifier = selector.GetIdentifier(item, collectionView);
            var cell = (UICollectionViewCell)collectionView.DequeueReusableCell(identifier, indexPath);

            _lastCreatedCell = cell;
            _lastCreatedCellPath = indexPath;


            if (Equals(item, _selectedItem) && !cell.Selected)
                collectionView.SelectItem(indexPath, false, UICollectionViewScrollPosition.None);
            cell.Tag |= InitializingStateMask;
            cell.SetDataContext(item);
            if (!HasMask(cell, InitializedStateMask))
            {
                cell.Tag |= InitializedStateMask;
                ParentObserver.GetOrAdd(cell).Parent = collectionView;
                selector.InitializeTemplate(collectionView, cell);
            }
            cell.Tag &= ~InitializingStateMask;
            var initializableItem = cell as IHasDisplayCallback;
            if (initializableItem != null)
                initializableItem.WillDisplay();
            return cell;
        }
Example #43
0
        public override void CellDisplayingEnded(UICollectionView collectionView, UICollectionViewCell cell, NSIndexPath indexPath)
        {
            var songCell = cell as CurrentSongCollectionViewCell;

            songCell?.WillDissapear();
        }
Example #44
0
 public SingleCollectionViewCellDataSource(UICollectionViewCell cell)
 {
     this.cell = cell;
 }
 public override void CellDisplayingEnded(UICollectionView collectionView, UICollectionViewCell cell,
     NSIndexPath indexPath)
 {
     if (cell is UICollectionViewCellBindable)
         cell.SetDataContext(null);
     (cell as IHasDisplayCallback)?.DisplayingEnded();
 }
 protected virtual void InitializeCell(UICollectionViewCell cell)
 {
 }
 private static bool HasMask(UICollectionViewCell cell, int mask)
 {
     return((cell.Tag & mask) == mask);
 }
 protected virtual Action <NSObject> GetGestureActionForCell(UICollectionViewCell cell)
 {
     return(null);
 }
        /// <summary>
        /// Called before a Collection View Cell is displayed to allow it to be initialized.
        /// </summary>
        /// <param name="collectionView">Collection view.</param>
        /// <param name="cell">Cell.</param>
        /// <param name="indexPath">Index path.</param>
        public override void WillDisplayCell(UICollectionView collectionView, UICollectionViewCell cell, NSIndexPath indexPath)
        {
            // Grab the cell
            var currentCell = cell as SearchResultViewCell;
            if (currentCell == null)
                throw new Exception ("Expected to display a `SearchResultViewCell`.");

            // Display the current picture info in the cell
            var item = FoundPictures [indexPath.Row];
            currentCell.PictureInfo = item;
        }