Exemplo n.º 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);
            }
        }
Exemplo n.º 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;
        }