Пример #1
0
            public ListViewDataSource(ListViewDataSource source)
            {
                _uiTableViewController = source._uiTableViewController;
                List                  = source.List;
                _uiTableView          = source._uiTableView;
                _defaultSectionHeight = source._defaultSectionHeight;
                _selectionFromNative  = source._selectionFromNative;

                Counts = new Dictionary <int, int>();
            }
Пример #2
0
            public ListViewDataSource(ListView list, FormsUITableViewController uiTableViewController)
            {
                _uiTableViewController = uiTableViewController;
                _uiTableView           = uiTableViewController.TableView;
                _defaultSectionHeight  = DefaultRowHeight;
                List = list;
                List.ItemSelected += OnItemSelected;
                UpdateShortNameListener();

                Counts = new Dictionary <int, int>();
            }
Пример #3
0
            protected override void Dispose(bool disposing)
            {
                if (_disposed)
                {
                    return;
                }

                if (disposing)
                {
                    if (List != null)
                    {
                        List.ItemSelected -= OnItemSelected;
                        List = null;
                    }

                    _templateToId          = null;
                    _uiTableView           = null;
                    _uiTableViewController = null;
                }

                _disposed = true;

                base.Dispose(disposing);
            }
Пример #4
0
        protected override void Dispose(bool disposing)
        {
            // check inset tracker for null to
            if (disposing && _insetTracker != null)
            {
                _insetTracker.Dispose();
                _insetTracker = null;

                var viewsToLookAt = new Stack <UIView>(Subviews);
                while (viewsToLookAt.Count > 0)
                {
                    var view             = viewsToLookAt.Pop();
                    var viewCellRenderer = view as ViewCellRenderer.ViewTableCell;
                    if (viewCellRenderer != null)
                    {
                        viewCellRenderer.Dispose();
                    }
                    else
                    {
                        foreach (var child in view.Subviews)
                        {
                            viewsToLookAt.Push(child);
                        }
                    }
                }

                if (Element != null)
                {
                    var templatedItems = TemplatedItemsView.TemplatedItems;
                    templatedItems.CollectionChanged        -= OnCollectionChanged;
                    templatedItems.GroupedCollectionChanged -= OnGroupedCollectionChanged;
                }

                if (_tableViewController != null)
                {
                    _tableViewController.Dispose();
                    _tableViewController = null;
                }
            }

            if (disposing)
            {
                if (_headerRenderer != null)
                {
                    var platform = _headerRenderer.Element.Platform as Platform;
                    if (platform != null)
                    {
                        platform.DisposeModelAndChildrenRenderers(_headerRenderer.Element);
                    }
                    _headerRenderer = null;
                }
                if (_footerRenderer != null)
                {
                    var platform = _footerRenderer.Element.Platform as Platform;
                    if (platform != null)
                    {
                        platform.DisposeModelAndChildrenRenderers(_footerRenderer.Element);
                    }
                    _footerRenderer = null;
                }

                var headerView = Controller?.HeaderElement as VisualElement;
                if (headerView != null)
                {
                    headerView.MeasureInvalidated -= OnHeaderMeasureInvalidated;
                }
                Control?.TableHeaderView?.Dispose();

                var footerView = Controller?.FooterElement as VisualElement;
                if (footerView != null)
                {
                    footerView.MeasureInvalidated -= OnFooterMeasureInvalidated;
                }
                Control?.TableFooterView?.Dispose();
            }

            base.Dispose(disposing);
        }
Пример #5
0
 public UnevenListViewDataSource(ListView list, FormsUITableViewController uiTableViewController) : base(list, uiTableViewController)
 {
 }
Пример #6
0
        protected override void OnElementChanged(ElementChangedEventArgs <ListView> e)
        {
            _requestedScroll = null;

            if (e.OldElement != null)
            {
                var controller = (IListViewController)e.OldElement;
                var headerView = (VisualElement)controller.HeaderElement;
                if (headerView != null)
                {
                    headerView.MeasureInvalidated -= OnHeaderMeasureInvalidated;
                }

                var footerView = (VisualElement)controller.FooterElement;
                if (footerView != null)
                {
                    footerView.MeasureInvalidated -= OnFooterMeasureInvalidated;
                }

                controller.ScrollToRequested -= OnScrollToRequested;
                var templatedItems = ((ITemplatedItemsView <Cell>)e.OldElement).TemplatedItems;

                templatedItems.CollectionChanged        -= OnCollectionChanged;
                templatedItems.GroupedCollectionChanged -= OnGroupedCollectionChanged;
            }

            if (e.NewElement != null)
            {
                if (Control == null)
                {
                    _tableViewController = new FormsUITableViewController(e.NewElement);
                    SetNativeControl(_tableViewController.TableView);
                    if (Forms.IsiOS9OrNewer)
                    {
                        Control.CellLayoutMarginsFollowReadableWidth = false;
                    }

                    _insetTracker = new KeyboardInsetTracker(_tableViewController.TableView, () => Control.Window, insets => Control.ContentInset = Control.ScrollIndicatorInsets = insets, point =>
                    {
                        var offset = Control.ContentOffset;
                        offset.Y  += point.Y;
                        Control.SetContentOffset(offset, true);
                    });
                }
                _shouldEstimateRowHeight = true;

                var controller = (IListViewController)e.NewElement;

                controller.ScrollToRequested += OnScrollToRequested;
                var templatedItems = ((ITemplatedItemsView <Cell>)e.NewElement).TemplatedItems;

                templatedItems.CollectionChanged        += OnCollectionChanged;
                templatedItems.GroupedCollectionChanged += OnGroupedCollectionChanged;

                UpdateRowHeight();

                Control.Source = _dataSource = e.NewElement.HasUnevenRows ? new UnevenListViewDataSource(e.NewElement, _tableViewController) : new ListViewDataSource(e.NewElement, _tableViewController);

                UpdateEstimatedRowHeight();
                UpdateHeader();
                UpdateFooter();
                UpdatePullToRefreshEnabled();
                UpdateIsRefreshing();
                UpdateSeparatorColor();
                UpdateSeparatorVisibility();

                var selected = e.NewElement.SelectedItem;
                if (selected != null)
                {
                    _dataSource.OnItemSelected(null, new SelectedItemChangedEventArgs(selected));
                }
            }

            base.OnElementChanged(e);
        }
Пример #7
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                if (_insetTracker != null)
                {
                    _insetTracker.Dispose();
                    _insetTracker = null;
                }

                foreach (UIView subview in Subviews)
                {
                    DisposeSubviews(subview);
                }

                if (Element != null)
                {
                    var templatedItems = TemplatedItemsView.TemplatedItems;
                    templatedItems.CollectionChanged        -= OnCollectionChanged;
                    templatedItems.GroupedCollectionChanged -= OnGroupedCollectionChanged;
                }

                if (_dataSource != null)
                {
                    _dataSource.Dispose();
                    _dataSource = null;
                }

                if (_tableViewController != null)
                {
                    _tableViewController.Dispose();
                    _tableViewController = null;
                }

                if (_headerRenderer != null)
                {
                    var platform = _headerRenderer.Element?.Platform as Platform;
                    platform?.DisposeModelAndChildrenRenderers(_headerRenderer.Element);
                    _headerRenderer = null;
                }
                if (_footerRenderer != null)
                {
                    var platform = _footerRenderer.Element?.Platform as Platform;
                    platform?.DisposeModelAndChildrenRenderers(_footerRenderer.Element);
                    _footerRenderer = null;
                }

                var headerView = Controller?.HeaderElement as VisualElement;
                if (headerView != null)
                {
                    headerView.MeasureInvalidated -= OnHeaderMeasureInvalidated;
                }
                Control?.TableHeaderView?.Dispose();

                var footerView = Controller?.FooterElement as VisualElement;
                if (footerView != null)
                {
                    footerView.MeasureInvalidated -= OnFooterMeasureInvalidated;
                }
                Control?.TableFooterView?.Dispose();
            }

            _disposed = true;

            base.Dispose(disposing);
        }