コード例 #1
0
        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 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);
            }
        }
コード例 #2
0
        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;
        }
コード例 #3
0
ファイル: CellTableViewCell.cs プロジェクト: zhamppx97/maui
        internal static UITableViewCell GetNativeCell(UITableView tableView, Cell cell, bool recycleCells = false, string templateId = "")
        {
            var id = cell.GetType().FullName;

            var renderer = (CellRenderer)Controls.Internals.Registrar.Registered.GetHandlerForObject <IRegisterable>(cell);

            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);
            }

            var nativeCell = renderer.GetCell(cell, reusableCell, tableView);

            var cellWithContent = nativeCell;

            // 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, nativeCell);
                var viewTableCell = contextCell.ContentCell as ViewCellRenderer.ViewTableCell;
                if (viewTableCell != null)
                {
                    viewTableCell.SupressSeparator = tableView.SeparatorStyle == UITableViewCellSeparatorStyle.None;
                }
                nativeCell = contextCell;
            }

            // Because the layer was hidden we need to layout the cell by hand
            if (cellWithContent != null)
            {
                cellWithContent.LayoutSubviews();
            }

            return(nativeCell);
        }