public void RecycleCell(object data, FastGridTemplateSelector dataTemplate, VisualElement parent) { if (ViewCell == null) { var cellSize = new Size(Bounds.Width, Bounds.Height); if (!(dataTemplate is FastGridTemplateSelector templateSelector)) { throw new NotSupportedException(@"DataTemplate should be FastGridTemplateSelector"); } var template = templateSelector.SelectTemplate(data) as FastGridDataTemplate; ViewCell = template?.CreateContent() as FastGridCell; 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); }
Size GetSizeByItem(FastGridTemplateSelector templateSelector, object item) { var cellSize = Size.Zero; if (templateSelector?.OnSelectTemplate(item) is FastGridDataTemplate template) { cellSize = template.CellSize; } return(cellSize); }