void Add(NotifyCollectionChangedEventArgs args)
        {
            if (NotLoadedYet())
            {
                _collectionView.ReloadData();
                return;
            }

            var startIndex = args.NewStartingIndex > -1 ? args.NewStartingIndex : IndexOf(args.NewItems[0]);
            var count      = args.NewItems.Count;

            if (!_grouped && _collectionView.NumberOfItemsInSection(_section) == 0)
            {
                // Okay, we're going from completely empty to more than 0 items; there's an iOS bug which apparently
                // will just crash if we call InsertItems here, so we have to do ReloadData.
                _collectionView.ReloadData();
                Count += count;
                return;
            }

            _collectionView.PerformBatchUpdates(() =>
            {
                var indexes = CreateIndexesFrom(startIndex, count);
                _collectionView.InsertItems(indexes);
                Count += count;
            }, null);
        }
Example #2
0
        void Add(NotifyCollectionChangedEventArgs args)
        {
            var startIndex = args.NewStartingIndex > -1 ? args.NewStartingIndex : _itemsSource.IndexOf(args.NewItems[0]);
            var count      = args.NewItems.Count;

            _collectionView.InsertItems(CreateIndexesFrom(startIndex, count));
        }
 private async Task InsertItemsAsync(UICollectionView collectionView, IReadOnlyCollection <int> indexes)
 {
     await collectionView.PerformBatchUpdatesAsync(() => {
         ItemsCount = _itemCollection.Count;
         InvokeHeightWillChange();
         collectionView.InsertItems(indexes.ToNSIndexPaths().ToArray());
     });
 }
Example #4
0
 public virtual void InsertItems(IndexPath[] indexPaths)
 {
     if (!_collectionView.Busy)
     {
         _collectionView.Progress = 0.0f;
         _collectionView.InsertItems(indexPaths);
     }
 }
Example #5
0
 private void AddItem(IAutoDropItem item)
 {
     CollectionResult.PerformBatchUpdates(delegate {
         var now = ResultItems.Count;
         ResultItems.Add(item);
         CollectionResult.InsertItems(new NSIndexPath[] { NSIndexPath.FromRowSection(now, 0) });
     }, null);
     HeightOfCollection.Constant = CollectionResult.CollectionViewLayout.CollectionViewContentSize.Height;
 }
        void Add(NotifyCollectionChangedEventArgs args)
        {
            var count = args.NewItems.Count;

            Count += count;
            var startIndex = args.NewStartingIndex > -1 ? args.NewStartingIndex : IndexOf(args.NewItems[0]);

            // Queue up the updates to the UICollectionView
            Update(() => CollectionView.InsertItems(CreateIndexesFrom(startIndex, count)), args);
        }
Example #7
0
        public NSIndexPath InsertItemView(DateTimeOffset startTime, TimeSpan duration)
        {
            if (!IsEditing)
            {
                throw new InvalidOperationException("Set IsEditing before calling insert/update/remove");
            }

            editingItemIndexPath = insertCalendarItem(startTime, duration);
            collectionView.InsertItems(new NSIndexPath[] { editingItemIndexPath });
            return(editingItemIndexPath);
        }
Example #8
0
        async Task Add(NotifyCollectionChangedEventArgs args)
        {
            if (ReloadRequired())
            {
                await Reload();

                return;
            }

            var count = args.NewItems.Count;

            Count += count;
            var startIndex = args.NewStartingIndex > -1 ? args.NewStartingIndex : IndexOf(args.NewItems[0]);

            // Queue up the updates to the UICollectionView
            BatchUpdate(() => _collectionView.InsertItems(CreateIndexesFrom(startIndex, count)));
        }
Example #9
0
        void Add(NotifyCollectionChangedEventArgs args)
        {
            var startIndex = args.NewStartingIndex > -1 ? args.NewStartingIndex : _itemsSource.IndexOf(args.NewItems[0]);
            var count      = args.NewItems.Count;

            _collectionView.PerformBatchUpdates(() =>
            {
                if (!_grouped && _collectionView.NumberOfSections() != GroupCount)
                {
                    // We had an empty non-grouped list, and now we're trying to add an item;
                    // we need to give it a section as well
                    _collectionView.InsertSections(new NSIndexSet(0));
                }

                _collectionView.InsertItems(CreateIndexesFrom(startIndex, count));
            }, null);
        }
        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();
            });
        }
Example #11
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);
        }
Example #12
0
        void Add(NotifyCollectionChangedEventArgs args)
        {
            var startIndex = args.NewStartingIndex > -1 ? args.NewStartingIndex : _itemsSource.IndexOf(args.NewItems[0]);
            var count      = args.NewItems.Count;

            if (!_grouped && _collectionView.NumberOfSections() != GroupCount && count > 0)
            {
                // Okay, we're going from completely empty to more than 0 items; this means we don't even
                // have a section 0 yet. Inserting a section 0 manually results in an unexplained crash, so instead
                // we'll just reload the data so the UICollectionView can get its internal state sorted out.
                _collectionView.ReloadData();
            }
            else
            {
                _collectionView.PerformBatchUpdates(() =>
                {
                    var indexes = CreateIndexesFrom(startIndex, count);
                    _collectionView.InsertItems(indexes);
                }, 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);
        }
        void HandleChatMessagesCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            InvokeOnMainThread(() =>
            {
                var indexPaths = new List <NSIndexPath>();
                if (e.NewItems != null)
                {
                    for (var i = 0; i < e.NewItems.Count; i++)
                    {
                        indexPaths.Add(NSIndexPath.FromItemSection(e.NewStartingIndex + i, 0));
                    }

                    chatCollectionView.PerformBatchUpdates(
                        () => chatCollectionView.InsertItems(indexPaths.ToArray()),
                        finished => ScrollChatToBottom()
                        );
                }
                else
                {
                    chatCollectionView.ReloadSections(NSIndexSet.FromIndex(0));
                }
            });
        }
        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();
            }
        }