Ejemplo n.º 1
0
        public static IObserver <IEnumerable <TSection> > AnimateSections <TSection, THeader, TModel, TKey>(
            this IReactive <UITableView> reactive,
            BaseTableViewSource <TSection, THeader, TModel> dataSource)
            where TKey : IEquatable <TKey>
            where TSection : IAnimatableSectionModel <THeader, TModel, TKey>, new()
            where TModel : IDiffable <TKey>, IEquatable <TModel>
            where THeader : IDiffable <TKey>
        {
            return(Observer.Create <IEnumerable <TSection> >(finalSections =>
            {
                var initialSections = dataSource.Sections;
                if (initialSections == null || initialSections.Count == 0)
                {
                    dataSource.SetSections(finalSections);
                    reactive.Base.ReloadData();
                    return;
                }

                // if view is not in view hierarchy, performing batch updates will crash the app
                if (reactive.Base.Window == null)
                {
                    dataSource.SetSections(finalSections);
                    reactive.Base.ReloadData();
                    return;
                }

                var stopwatchProvider = Mvx.Resolve <IStopwatchProvider>();
                var stopwatch = stopwatchProvider.Create(MeasuredOperation.Diffing);
                stopwatch.Start();

                var diff = new Diffing <TSection, THeader, TModel, TKey>(initialSections, finalSections);
                var changeset = diff.ComputeDifferences();

                stopwatch.Stop();

                // The changesets have to be applied one after another. Not in one transaction.
                // iOS is picky about the changes which can happen in a single transaction.
                // Don't put BeginUpdates() ... EndUpdates() around the foreach, it has to stay this way,
                // otherwise the app might crash from time to time.

                foreach (var difference in changeset)
                {
                    reactive.Base.BeginUpdates();
                    dataSource.SetSections(difference.FinalSections);
                    reactive.Base.performChangesetUpdates(difference);
                    reactive.Base.EndUpdates();

                    foreach (var section in difference.UpdatedSections)
                    {
                        if (reactive.Base.GetHeaderView(section) is BaseTableHeaderFooterView <THeader> headerView)
                        {
                            headerView.Item = difference.FinalSections[section].Header;
                        }
                    }
                }
            }));
        }
 public static IObserver <IEnumerable <TModel> > ReloadItems <THeader, TModel>(
     this IReactive <UITableView> reactive, BaseTableViewSource <THeader, TModel> dataSource)
 {
     return(Observer.Create <IEnumerable <TModel> >(list =>
     {
         dataSource.SetItems(list);
         reactive.Base.ReloadData();
     }));
 }
Ejemplo n.º 3
0
 public static IObserver <IEnumerable <TSection> > ReloadSections <TSection, THeader, TModel>(
     this IReactive <UITableView> reactive, BaseTableViewSource <TSection, THeader, TModel> dataSource)
     where TSection : ISectionModel <THeader, TModel>, new()
 {
     return(Observer.Create <IEnumerable <TSection> >(list =>
     {
         dataSource.SetSections(list);
         reactive.Base.ReloadData();
     }));
 }
Ejemplo n.º 4
0
 public static IObserver <IImmutableList <TModel> > ReloadItems <TSection, THeader, TModel>(
     this IReactive <UITableView> reactive, BaseTableViewSource <TSection, THeader, TModel> dataSource)
     where TSection : SectionModel <THeader, TModel>, new()
 {
     return(Observer.Create <IImmutableList <TModel> >(list =>
     {
         dataSource.SetItems(list);
         reactive.Base.ReloadData();
     }));
 }
Ejemplo n.º 5
0
 public static IObserver <IImmutableList <TSection> > ReloadSections <TSection, THeader, TModel>(
     this IReactive <UITableView> reactive, BaseTableViewSource <TSection, THeader, TModel> dataSource)
     where TSection : ISectionModel <THeader, TModel>, new()
 {
     return(Observer.Create <IImmutableList <TSection> >(list =>
     {
         dataSource.SetSections(list);
         reactive.Base.ReloadData();
         dataSource.OnItemsChanged?.Invoke(dataSource, new EventArgs());
     }));
 }