/// <summary> /// Ons the element changed. /// </summary> /// <param name="e">E.</param> protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.ListView> e) { base.OnElementChanged(e); if (e.OldElement is EnhancedListView oldElement) { oldElement.Renderer = null; if (Control != null) { Control.Delegate = null; } if (ScrollDelegate != null) { ScrollDelegate.Source = null; ScrollDelegate.Element = null; ScrollDelegate.Dispose(); ScrollDelegate = null; } } if (e.NewElement is EnhancedListView newElement) { newElement.Renderer = this; ScrollDelegate = new ScrollDelegate(newElement, Control.Source); Control.Delegate = ScrollDelegate; } }
protected override void Dispose(bool disposing) { if (!_disposed && disposing) { _disposed = true; ScrollDelegate.Source = null; ScrollDelegate.Element = null; ScrollDelegate?.Dispose(); ScrollDelegate = null; Control.Delegate = null; } base.Dispose(disposing); }
public void Update(UITableView tableView, Cell cell, UITableViewCell nativeCell) { var parentListView = cell.RealParent as ListView; var recycling = parentListView != null && parentListView.CachingStrategy == ListViewCachingStrategy.RecycleElement; if (_cell != cell && recycling) { if (_cell != null) { ((INotifyCollectionChanged)_cell.ContextActions).CollectionChanged -= OnContextItemsChanged; } ((INotifyCollectionChanged)cell.ContextActions).CollectionChanged += OnContextItemsChanged; } var height = Frame.Height; var width = tableView.Frame.Width; nativeCell.Frame = new RectangleF(0, 0, width, height); nativeCell.SetNeedsLayout(); var handler = new PropertyChangedEventHandler(OnMenuItemPropertyChanged); _tableView = tableView; SetupSelection(tableView); if (_cell != null) { if (!recycling) { _cell.PropertyChanged -= OnCellPropertyChanged; } if (_menuItems.Count > 0) { if (!recycling) { ((INotifyCollectionChanged)_cell.ContextActions).CollectionChanged -= OnContextItemsChanged; } foreach (var item in _menuItems) { item.PropertyChanged -= handler; } } _menuItems.Clear(); } _menuItems.AddRange(cell.ContextActions); _cell = cell; if (!recycling) { cell.PropertyChanged += OnCellPropertyChanged; ((INotifyCollectionChanged)_cell.ContextActions).CollectionChanged += OnContextItemsChanged; } var isOpen = false; if (_scroller == null) { _scroller = new UIScrollView(new RectangleF(0, 0, width, height)); _scroller.ScrollsToTop = false; _scroller.ShowsHorizontalScrollIndicator = false; if (Forms.IsiOS8OrNewer) { _scroller.PreservesSuperviewLayoutMargins = true; } ContentView.AddSubview(_scroller); } else { _scroller.Frame = new RectangleF(0, 0, width, height); isOpen = ScrollDelegate.IsOpen; for (var i = 0; i < _buttons.Count; i++) { var b = _buttons[i]; b.RemoveFromSuperview(); b.Dispose(); } _buttons.Clear(); ScrollDelegate.Unhook(_scroller); ScrollDelegate.Dispose(); } if (ContentCell != nativeCell) { if (ContentCell != null) { ContentCell.RemoveFromSuperview(); ContentCell = null; } ContentCell = nativeCell; //Hack: if we have a ImageCell the insets are slightly different, //the inset numbers user below were taken using the Reveal app from the default cells if ((ContentCell as CellTableViewCell)?.Cell is ImageCell) { nfloat imageCellInsetLeft = 57; nfloat imageCellInsetRight = 0; if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) { imageCellInsetLeft = 89; imageCellInsetRight = imageCellInsetLeft / 2; } SeparatorInset = new UIEdgeInsets(0, imageCellInsetLeft, 0, imageCellInsetRight); } _scroller.AddSubview(nativeCell); } SetupButtons(width, height); UIView container = null; var totalWidth = width; for (var i = _buttons.Count - 1; i >= 0; i--) { var b = _buttons[i]; totalWidth += b.Frame.Width; if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { _scroller.AddSubview(b); } else { if (container == null) { container = new iOS7ButtonContainer(b.Frame.Width); _scroller.InsertSubview(container, 0); } container.AddSubview(b); } } _scroller.Delegate = new ContextScrollViewDelegate(container, _buttons, isOpen); _scroller.ContentSize = new SizeF(totalWidth, height); if (isOpen) { _scroller.SetContentOffset(new PointF(ScrollDelegate.ButtonsWidth, 0), false); } else { _scroller.SetContentOffset(new PointF(0, 0), false); } }