protected void NotifyCollectionChanged(object sender, NotifyKeyGroupCollectionChangedEventArgs <TKey, TItem> e)
 {
     NSThreadExtensions.ExecuteOnMainThread(() =>
     {
         IosDataSourceHandler.Handle(_tableViewRef.Target, e);
     });
 }
Esempio n. 2
0
        private void NotifyCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (_tableViewRef.Target == null)
            {
                return;
            }

            NSThreadExtensions.ExecuteOnMainThread(() =>
            {
                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);
                        }

                        _tableViewRef.Target?.InsertRows(paths, UITableViewRowAnimation.Automatic);
                    }
                    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;
                        }

                        _tableViewRef.Target?.DeleteRows(paths, UITableViewRowAnimation.Automatic);
                    }
                    break;

                case NotifyCollectionChangedAction.Move:
                    {
                        if (e.NewItems.Count != 1 || e.OldItems.Count != 1)
                        {
                            _tableViewRef.Target?.ReloadData();
                            break;
                        }

                        if (e.NewStartingIndex != e.OldStartingIndex)
                        {
                            _tableViewRef.Target?.MoveRow(NSIndexPath.FromRowSection(e.OldStartingIndex, 0),
                                                          NSIndexPath.FromRowSection(e.NewStartingIndex, 0));
                        }

                        break;
                    }

                default:
                    _tableViewRef.Target?.ReloadData();
                    break;
                }
            });
        }