public void RecycleCell(object data, FastCollectionTemplateSelector dataTemplate, VisualElement parent) { if (ViewCell == null) { var cellSize = new Size(Bounds.Width, Bounds.Height); if (!(dataTemplate is FastCollectionTemplateSelector templateSelector)) { throw new NotSupportedException(@"DataTemplate should be FastGridTemplateSelector"); } var template = templateSelector.SelectTemplate(data) as FastCollectionDataTemplate; ViewCell = template?.CreateContent() as FastCollectionCell; cellSize = template?.CellSize ?? cellSize; if (ViewCell != null) { ViewCell.BindingContext = data; ViewCell.PrepareCell(cellSize); ViewCell.Parent = parent; _originalBindingContext = data; _view = ConvertFormsToNative(ViewCell.View, new Rectangle(new Point(0, 0), cellSize)); } if (_view == null) { return; } _view.AutoresizingMask = UIViewAutoresizing.All; _view.ContentMode = UIViewContentMode.ScaleAspectFit; _view.ClipsToBounds = true; ContentView.AddSubview(_view); } else if (data == _originalBindingContext) { ViewCell.BindingContext = _originalBindingContext; } else { ViewCell.BindingContext = data; } var gr = GestureRecognizers; if (gr != null && gr.Length > 0) { gr.ForEach(RemoveGestureRecognizer); } _tapGestureRecognizer = new UITapGestureRecognizer(Tapped); AddGestureRecognizer(_tapGestureRecognizer); }
protected override void Dispose(bool disposing) { if (_tapGestureRecognizer != null) { Device.BeginInvokeOnMainThread(() => { RemoveGestureRecognizer(_tapGestureRecognizer); _tapGestureRecognizer = null; }); } ; _view = null; _originalBindingContext = null; if (ViewCell != null) { ViewCell.BindingContext = null; ViewCell.Parent = null; ViewCell = null; } base.Dispose(disposing); }