Esempio n. 1
0
        internal static UITableViewCell GetNativeCell(UITableView tableView, Cell cell, bool recycleCells = false, string templateId = "")
        {
            var id = cell.GetType().FullName;

            var renderer = (CellRenderer)Registrar.Registered.GetHandler(cell.GetType());

            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);
                nativeCell = contextCell;
            }

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

            return(nativeCell);
        }
		internal static UITableViewCell GetNativeCell(UITableView tableView, Cell cell, bool recycleCells = false, string templateId = "")
		{
			var id = cell.GetType().FullName;

			var renderer = (CellRenderer)Registrar.Registered.GetHandler(cell.GetType());

			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 = true;
				nativeCell = contextCell;
			}

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

			return nativeCell;
		}
        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;
        }
        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       = () =>
                            {
                                if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                                {
                                    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);

                if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                {
                    RestoreHighlight(scrollView);
                }
            }
        }