Пример #1
0
        async Task Remove(NotifyCollectionChangedEventArgs args)
        {
            var startIndex = args.OldStartingIndex;

            if (startIndex < 0)
            {
                // INCC implementation isn't giving us enough information to know where the removed items were in the
                // collection. So the best we can do is a ReloadData()
                await Reload();

                return;
            }

            if (ReloadRequired())
            {
                await Reload();

                return;
            }

            // If we have a start index, we can be more clever about removing the item(s) (and get the nifty animations)
            var count = args.OldItems.Count;

            Count -= count;

            // Queue up the updates to the UICollectionView
            BatchUpdate(() => _collectionView.DeleteItems(CreateIndexesFrom(startIndex, count)));
        }
        void Remove(NotifyCollectionChangedEventArgs args)
        {
            var startIndex = args.OldStartingIndex > -1 ? args.OldStartingIndex : _itemsSource.IndexOf(args.OldItems[0]);
            var count      = args.OldItems.Count;

            _collectionView.DeleteItems(CreateIndexesFrom(startIndex, count));
        }
        void Remove(NotifyCollectionChangedEventArgs args)
        {
            if (NotLoadedYet())
            {
                _collectionView.ReloadData();
                return;
            }

            var startIndex = args.OldStartingIndex;

            if (startIndex < 0)
            {
                // INCC implementation isn't giving us enough information to know where the removed items were in the
                // collection. So the best we can do is a ReloadData()
                Reload();
                return;
            }

            // If we have a start index, we can be more clever about removing the item(s) (and get the nifty animations)
            var count = args.OldItems.Count;

            _collectionView.PerformBatchUpdates(() =>
            {
                _collectionView.DeleteItems(CreateIndexesFrom(startIndex, count));
                Count -= count;
            }, null);
        }
Пример #4
0
        void Remove(NotifyCollectionChangedEventArgs args)
        {
            var startIndex = args.OldStartingIndex;

            if (startIndex < 0)
            {
                // INCC implementation isn't giving us enough information to know where the removed items were in the
                // collection. So the best we can do is a ReloadData()
                Reload();
                return;
            }

            // If we have a start index, we can be more clever about removing the item(s) (and get the nifty animations)
            var count = args.OldItems.Count;

            _collectionView.PerformBatchUpdates(() =>
            {
                _collectionView.DeleteItems(CreateIndexesFrom(startIndex, count));

                if (!_grouped && _collectionView.NumberOfSections() != GroupCount)
                {
                    // We had a non-grouped list with items, and we're removing the last one;
                    // we also need to remove the group it was in
                    _collectionView.DeleteSections(new NSIndexSet(0));
                }
            }, null);
        }
        /// <summary>
        /// Compares the album state before and after the drag to delete items in the collection view that represent photos moved elsewhere.
        /// </summary>
        void DeleteItems(UICollectionView collectionView)
        {
            var albumAfterDrag = album;

            if (albumBeforeDrag is null || albumAfterDrag is null)
            {
                return;
            }

            var indexPathsToDelete = new List <NSIndexPath> ();

            for (var i = 0; i < albumBeforeDrag.Photos.Count; i++)
            {
                var photo = albumBeforeDrag.Photos[i];
                if (!albumAfterDrag.Contains(photo))
                {
                    indexPathsToDelete.Add(NSIndexPath.FromItemSection(i, 0));
                }
            }
            if (indexPathsToDelete.Count > 0)
            {
                collectionView.PerformBatchUpdates(() => {
                    collectionView.DeleteItems(indexPathsToDelete.ToArray());
                }, (finished) => {});
            }
        }
Пример #6
0
 private void RemoveItem(int index)
 {
     CollectionResult.PerformBatchUpdates(delegate {
         ResultItems.RemoveAt(index);
         CollectionResult.DeleteItems(new NSIndexPath[] { NSIndexPath.FromRowSection(index, 0) });
     }, null);
     HeightOfCollection.Constant = CollectionResult.CollectionViewLayout.CollectionViewContentSize.Height;
 }
 private async Task DeleteItemsAsync(UICollectionView collectionView, IReadOnlyCollection <int> indexes)
 {
     await collectionView.PerformBatchUpdatesAsync(() => {
         ItemsCount -= indexes.Count;
         InvokeHeightWillChange();
         collectionView.DeleteItems(indexes.ToNSIndexPaths().ToArray());
     });
 }
Пример #8
0
        public void RemoveItemView()
        {
            if (!IsEditing)
            {
                throw new InvalidOperationException("Set IsEditing before calling insert/update/remove");
            }

            removeCalendarItem(editingItemIndexPath);
            collectionView.DeleteItems(new NSIndexPath[] { editingItemIndexPath });
        }
        public void PhotoLibraryDidChange(PHChange changeInstance)
        {
            // Check if there are changes to the assets we are showing.
            var collectionChanges = changeInstance.GetFetchResultChangeDetails(AssetsFetchResults);

            if (collectionChanges == null)
            {
                return;
            }

            DispatchQueue.MainQueue.DispatchAsync(() => {
                // Get the new fetch result.
                AssetsFetchResults = collectionChanges.FetchResultAfterChanges;
                UICollectionView collectionView = CollectionView;
                if (collectionChanges.HasIncrementalChanges || !collectionChanges.HasMoves)
                {
                    collectionView.PerformBatchUpdates(() => {
                        var removedIndexes = collectionChanges.RemovedIndexes;
                        if (removedIndexes != null && removedIndexes.Count > 0)
                        {
                            collectionView.DeleteItems(removedIndexes.GetIndexPaths(0));
                        }

                        var insertedIndexes = collectionChanges.InsertedIndexes;
                        if (insertedIndexes != null && insertedIndexes.Count > 0)
                        {
                            collectionView.InsertItems(insertedIndexes.GetIndexPaths(0));
                        }

                        var changedIndexes = collectionChanges.ChangedIndexes;
                        if (changedIndexes != null && changedIndexes.Count > 0)
                        {
                            collectionView.ReloadItems(changedIndexes.GetIndexPaths(0));
                        }
                    }, null);
                }
                else
                {
                    collectionView.ReloadData();
                }

                ResetCachedAssets();
            });
        }
Пример #10
0
        public void Execute()
        {
            // If we have incremental diffs, animate them in the collection view
            _collectionView.PerformBatchUpdates(() =>
            {
                // For indexes to make sense, updates must be in this order:
                // delete, insert, reload, move
                if (_changes.RemovedIndexes?.Count > 0)
                {
                    var result = new List <NSIndexPath>();
                    _changes.RemovedIndexes.EnumerateIndexes((nuint idx, ref bool stop) =>
                                                             result.Add(NSIndexPath.FromItemSection((nint)idx, _sectionIndex)));

                    _collectionView.DeleteItems(result.ToArray());
                }

                if (_changes.InsertedIndexes?.Count > 0)
                {
                    var result = new List <NSIndexPath>();

                    _changes.InsertedIndexes.EnumerateIndexes((nuint idx, ref bool stop) =>
                                                              result.Add(NSIndexPath.FromItemSection((nint)idx, _sectionIndex)));

                    _collectionView.InsertItems(result.ToArray());
                }

                if (_changes.ChangedIndexes?.Count > 0)
                {
                    var result = new List <NSIndexPath>();
                    _changes.ChangedIndexes.EnumerateIndexes((nuint idx, ref bool stop) =>
                                                             result.Add(NSIndexPath.FromItemSection((nint)idx, _sectionIndex)));

                    _collectionView.ReloadItems(result.ToArray());
                }

                _changes.EnumerateMoves((fromIndex, toIndex) =>
                {
                    _collectionView.MoveItem(NSIndexPath.FromItemSection((nint)fromIndex, _sectionIndex),
                                             NSIndexPath.FromItemSection((nint)toIndex, _sectionIndex));
                });
            }, null);
        }
        void HandleChatPromptTypesCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            collectionView.PerformBatchUpdates(() =>
            {
                var safetyCheckAdded = e.NewItems != null && e.NewItems.Count > 0;
                if (safetyCheckAdded)
                {
                    collectionView.InsertItems(new NSIndexPath[] { NSIndexPath.FromItemSection(e.NewStartingIndex, 0) });
                }
                else
                {
                    collectionView.DeleteItems(new NSIndexPath[] { NSIndexPath.FromItemSection(2, 0) });
                }

                ((UICollectionViewFlowLayout)collectionView.CollectionViewLayout).ItemSize = new CGSize
                {
                    Height = Shared.Constants.PulloutBottomMargin,
                    Width  = UIScreen.MainScreen.Bounds.Width / (safetyCheckAdded ? 3 : 2),
                };

                collectionView.CollectionViewLayout.InvalidateLayout();
            }, null);
        }
        private void HandleCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (_view == null)
            {
                return;
            }

            Action act = () =>
            {
                switch (e.Action)
                {
                case NotifyCollectionChangedAction.Add:
                {
                    var count = e.NewItems.Count;
                    var paths = new NSIndexPath[count];

                    for (var i = 0; i < count; i++)
                    {
                        paths[i] = NSIndexPath.FromRowSection(e.NewStartingIndex + i, 0);
                    }

                    _view.InsertItems(paths);
                }
                break;

                case NotifyCollectionChangedAction.Remove:
                {
                    var count = e.OldItems.Count;
                    var paths = new NSIndexPath[count];

                    for (var i = 0; i < count; i++)
                    {
                        var index = NSIndexPath.FromRowSection(e.OldStartingIndex + i, 0);
                        paths[i] = index;

                        var item = e.OldItems[i];

                        if (Equals(SelectedItem, item))
                        {
                            SelectedItem = default(TItem);
                        }
                    }

                    _view.DeleteItems(paths);
                }
                break;

                default:
                    _view.ReloadData();
                    break;
                }
            };

            var isMainThread = Thread.CurrentThread == _mainThread;

            if (isMainThread)
            {
                act();
            }
            else
            {
                NSOperationQueue.MainQueue.AddOperation(act);
                NSOperationQueue.MainQueue.WaitUntilAllOperationsAreFinished();
            }
        }
Пример #13
0
 public virtual void DeleteItems(IndexPath[] indexPaths)
 {
     _collectionView.DeleteItems(indexPaths);
 }