Exemple #1
0
        protected override void Dispose(bool disposing)
        {
            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);
                        }
                    }
                }
            }

            base.Dispose(disposing);
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_packager == null)
                {
                    return;
                }

                Element?.ClearValue(Platform.RendererProperty);
                SetElement(null);

                _packager.Dispose();
                _packager = null;

                _tracker.NativeControlUpdated -= OnNativeControlUpdated;
                _tracker.Dispose();
                _tracker = null;

                _events.Dispose();
                _events = null;

                _insetTracker.Dispose();
                _insetTracker = null;

                ScrollAnimationEnded -= HandleScrollAnimationEnded;
                Scrolled             -= HandleScrolled;
            }

            base.Dispose(disposing);
        }
        public void SetElement(VisualElement element)
        {
            _requestedScroll = null;
            var oldElement = Element;

            Element = element;

            if (oldElement != null)
            {
                oldElement.PropertyChanged -= HandlePropertyChanged;
                ((ScrollView)oldElement).ScrollToRequested -= OnScrollToRequested;
            }

            if (element != null)
            {
                element.PropertyChanged += HandlePropertyChanged;
                ((ScrollView)element).ScrollToRequested += OnScrollToRequested;
                if (_packager == null)
                {
                    _packager = new VisualElementPackager(this);
                    _packager.Load();

                    _tracker = new VisualElementTracker(this);
                    _tracker.NativeControlUpdated += OnNativeControlUpdated;
                    _events = new EventTracker(this);
                    _events.LoadEvents(this);

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

                UpdateDelaysContentTouches();
                UpdateContentSize();
                UpdateBackgroundColor();
                UpdateIsEnabled();
                UpdateVerticalScrollBarVisibility();
                UpdateHorizontalScrollBarVisibility();

                _shellScrollTracker = new ShellScrollViewTracker(this);

                OnElementChanged(new VisualElementChangedEventArgs(oldElement, element));

                EffectUtilities.RegisterEffectControlProvider(this, oldElement, element);

                if (element != null)
                {
                    element.SendViewInitialized(this);
                }

                if (!string.IsNullOrEmpty(element.AutomationId))
                {
                    AccessibilityIdentifier = element.AutomationId;
                }
            }
        }
Exemple #4
0
        protected override void OnElementChanged(ElementChangedEventArgs <TableView> e)
        {
            if (e.NewElement != null)
            {
                var style = UITableViewStyle.Plain;
                if (e.NewElement.Intent != TableIntent.Data)
                {
                    style = UITableViewStyle.Grouped;
                }

                if (Control == null || Control.Style != style)
                {
                    if (Control != null)
                    {
                        _insetTracker.Dispose();
                        Control.Dispose();
                    }

                    var tv = new UITableView(RectangleF.Empty, style);
                    _originalBackgroundView = tv.BackgroundView;

                    SetNativeControl(tv);
                    if (Forms.IsiOS9OrNewer)
                    {
                        tv.CellLayoutMarginsFollowReadableWidth = false;
                    }

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

                SetSource();
                UpdateRowHeight();

                UpdateBackgroundView();
            }

            base.OnElementChanged(e);
        }
        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);
        }
        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);
        }
Exemple #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);
        }