public override void WillEndDragging(UIScrollView scrollView, PointF velocity, ref PointF targetContentOffset) { if (ShouldIgnoreScrolling(scrollView)) { return; } var width = ButtonsWidth; var x = targetContentOffset.X; var parentThreshold = scrollView.Frame.Width * .4f; var contentThreshold = width * .8f; if (x >= parentThreshold || x >= contentThreshold) { IsOpen = true; targetContentOffset = new PointF(width, 0); RemoveHighlight(scrollView); if (_globalCloser == null) { UIView view = scrollView; while (view.Superview != null) { view = view.Superview; var table = view as UITableView; if (table != null) { ContextActionsCell contentCell = GetContextCell(scrollView); NSAction close = () => { RestoreHighlight(scrollView); IsOpen = false; scrollView.SetContentOffset(new PointF(0, 0), true); ClearCloserRecognizer(contentCell); contentCell = null; }; _table = table; _globalCloser = new Controls.Compatibility.Platform.iOS.GlobalCloseContextGestureRecognizer(scrollView, close); _globalCloser.ShouldRecognizeSimultaneously = (recognizer, r) => r == _table?.PanGestureRecognizer; table.AddGestureRecognizer(_globalCloser); _closer = new UITapGestureRecognizer(close); contentCell.ContentCell.AddGestureRecognizer(_closer); } } } } else { ClearCloserRecognizer(GetContextCell(scrollView)); IsOpen = false; targetContentOffset = new PointF(0, 0); RestoreHighlight(scrollView); } }
void ClearCloserRecognizer(ContextActionsCell cell) { if (_globalCloser == null || _globalCloser.State == UIGestureRecognizerState.Cancelled) { return; } cell?.ContentCell?.RemoveGestureRecognizer(_closer); _closer.Dispose(); _closer = null; _table.RemoveGestureRecognizer(_globalCloser); _table = null; _globalCloser.Dispose(); _globalCloser = null; }
internal static UITableViewCell GetPlatformCell(UITableView tableView, Cell cell, bool recycleCells = false, string templateId = "") { var id = cell.GetType().FullName; ContextActionsCell contextCell = null; UITableViewCell reusableCell = null; if (cell.HasContextActions || recycleCells) { contextCell = (ContextActionsCell)tableView.DequeueReusableCell(ContextActionsCell.Key + templateId); if (contextCell == null) { contextCell = new ContextActionsCell(templateId); reusableCell = tableView.DequeueReusableCell(id); } else { contextCell.Close(); reusableCell = contextCell.ContentCell; if (reusableCell.ReuseIdentifier.ToString() != id) { reusableCell = null; } } } else { reusableCell = tableView.DequeueReusableCell(id); } cell.Handler?.DisconnectHandler(); cell.ReusableCell = reusableCell; cell.TableView = tableView; var handler = cell.ToHandler(cell.FindMauiContext()); var renderer = (handler as CellRenderer) ?? (handler.PlatformView as CellRenderer); var platformCell = renderer.PlatformView; var cellWithContent = platformCell; // Sometimes iOS for returns a dequeued cell whose Layer is hidden. // This prevents it from showing up, so lets turn it back on! if (cellWithContent.Layer.Hidden) { cellWithContent.Layer.Hidden = false; } if (contextCell != null) { contextCell.Update(tableView, cell, platformCell); var viewTableCell = contextCell.ContentCell as ViewCellRenderer.ViewTableCell; if (viewTableCell != null) { viewTableCell.SupressSeparator = tableView.SeparatorStyle == UITableViewCellSeparatorStyle.None; } platformCell = contextCell; } // Because the layer was hidden we need to layout the cell by hand if (cellWithContent != null) { cellWithContent.LayoutSubviews(); } return(platformCell); }