Esempio n. 1
0
 private static void OnLayoutContentCell(ContentCell contentCell)
 {
     if (!string.IsNullOrEmpty(contentCell?.SubtextLabel.Text) && contentCell.MinHeight == Cell.StandardCellHeight)
     {
         contentCell.MinHeight = Cell.StandardCellHeight * 4 / 3;
     }
 }
Esempio n. 2
0
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();

            if (_scroller == null || (_scroller != null && _scroller.Frame == Bounds))
            {
                return;
            }

            Update(_tableView, _cell, ContentCell);

            _scroller.Frame   = Bounds;
            ContentCell.Frame = Bounds;

            if (ContentCell is ViewCellRenderer.ViewTableCell && ContentCell.Subviews.Length > 0 && Math.Abs(ContentCell.Subviews[0].Frame.Height - Bounds.Height) > 1)
            {
                // Something goes weird inside iOS where LayoutSubviews wont get called when updating the bounds if the user
                // forces us to flip flop between a ContextActionCell and a normal cell in the middle of actually displaying the cell
                // so here we are going to hack it a forced update. Leave room for 1px of play because the border is 1 or .5px and must
                // be accounted for.
                //
                // Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=39450
                ContentCell.LayoutSubviews();
            }
        }
        protected virtual ContentCellContainer GetNativeCell(ContentCell cell, NSIndexPath indexPath, bool recycleCells = false, string templateId = "")
        {
            var id = recycleCells ? templateId : cell.GetType().FullName;

            var renderer = (ContentCellRenderer)Xamarin.Forms.Internals.Registrar.Registered.GetHandlerForObject <IRegisterable>(cell);

            // Note that UICollectionView returns the instance even if called in the first time, unlike UITableView.
            var reusableCell = _uiCollectionView.DequeueReusableCell(id, indexPath) as ContentCellContainer;

            var nativeCell = renderer.GetCell(cell, reusableCell, _uiCollectionView) as ContentCellContainer;

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

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

            return(nativeCell);
        }
Esempio n. 4
0
        public void HavingEmptyRow_WhenANullContentCellIsAdded_ThenAddedCellIsSameAsTheAddedOne()
        {
            ContentRow row = new();

            ContentCell returnedCell = row.AddCell(null as ContentCell);

            Assert.That(returnedCell, Is.SameAs(row[0]));
        }
        public void HavingCellWithNoPadding_WhenCalculatingPaddingLeft_ThenPaddingLeftIs1()
        {
            ContentCell contentCell = new ContentCell();

            int actual = contentCell.CalculatePaddingLeft();

            Assert.That(actual, Is.EqualTo(1));
        }
Esempio n. 6
0
        public void HavingEmptyRow_WhenAContentCellIsAdded_ThenAddedCellIsReturned()
        {
            ContentRow  row  = new();
            ContentCell cell = new("cell 1");

            ContentCell returnedCell = row.AddCell(cell);

            Assert.That(returnedCell, Is.SameAs(cell));
        }
Esempio n. 7
0
        public void HavingAnEmptyNormalRowList_WhenThreeCellsAreAdded_ThenRowCountIs1()
        {
            ContentCell contentCell1 = new ContentCell();
            ContentCell contentCell2 = new ContentCell();
            ContentCell contentCell3 = new ContentCell();

            contentRowList.Add(contentCell1, contentCell2, contentCell3);

            Assert.That(contentRowList.Count, Is.EqualTo(1));
        }
        public void HavingCellWithPaddingLeft5_WhenCalculatingPaddingLeft_ThenPaddingLeftIs5()
        {
            ContentCell contentCell = new ContentCell
            {
                PaddingLeft = 5
            };

            int actual = contentCell.CalculatePaddingLeft();

            Assert.That(actual, Is.EqualTo(5));
        }
        protected virtual AView GetCell(ContentCell item, ContentCellContainer convertView, ViewGroup parent, Context context, Xamarin.Forms.View view)
        {
            var renderer = ContentCellRenderer.GetRenderer(item);

            if (renderer == null)
            {
                renderer = Registrar.Registered.GetHandlerForObject <ContentCellRenderer>(item);
            }


            return(renderer.GetCell(item, convertView, parent, context));
        }
Esempio n. 10
0
        protected virtual void CreateNewRenderer(ContentCell cell)
        {
            if (cell.View == null)
            {
                throw new InvalidOperationException($"ViewCell must have a {nameof(cell.View)}");
            }

            _contentCell         = cell;
            _contentViewRenderer = Platform.CreateRendererWithContext(cell.View, Context);
            AddView(_contentViewRenderer.View);
            Platform.SetRenderer(cell.View, _contentViewRenderer);

            cell.View.IsPlatformEnabled = true;
        }
        public void HavingRowWithPaddingLeft5_WhenCalculatingPaddingLeft_ThenPaddingLeftIs5()
        {
            ContentCell contentCell = new ContentCell();
            ContentRow  contentRow  = new ContentRow
            {
                CellPaddingLeft = 5
            };

            contentRow.AddCell(contentCell);

            int actual = contentCell.CalculatePaddingLeft();

            Assert.That(actual, Is.EqualTo(5));
        }
Esempio n. 12
0
        protected virtual void UpdateCell(ContentCell cell)
        {
            Performance.Start(out string reference);

            if (_contentCell != null)
            {
                Device.BeginInvokeOnMainThread(_contentCell.SendDisappearing);
            }

            _contentCell = cell;

            Device.BeginInvokeOnMainThread(_contentCell.SendAppearing);

            IVisualElementRenderer renderer;

            if (_rendererRef == null || !_rendererRef.TryGetTarget(out renderer))
            {
                renderer = GetNewRenderer();
            }
            else
            {
                if (renderer.Element != null && renderer == Platform.GetRenderer(renderer.Element))
                {
                    renderer.Element.ClearValue(RendererProperty);
                }

                var type            = Xamarin.Forms.Internals.Registrar.Registered.GetHandlerTypeForObject(this._contentCell.View);
                var reflectableType = renderer as System.Reflection.IReflectableType;
                var rendererType    = reflectableType != null?reflectableType.GetTypeInfo().AsType() : renderer.GetType();

                if (rendererType == type || (renderer.GetType() == DefaultRenderer) && type == null)
                {
                    renderer.SetElement(this._contentCell.View);
                }
                else
                {
                    //when cells are getting reused the element could be already set to another cell
                    //so we should dispose based on the renderer and not the renderer.Element
                    var platform = renderer.Element.Platform as Platform;
                    DisposeRendererAndChildren(renderer);
                    renderer = GetNewRenderer();
                }
            }

            Platform.SetRenderer(this._contentCell.View, renderer);
            Performance.Stop(reference);
        }
Esempio n. 13
0
        public void HavingAnEmptyNormalRowList_WhenThreeCellsAreAdded_ThenRowContainsTheThreeCells()
        {
            ContentCell contentCell1 = new ContentCell();
            ContentCell contentCell2 = new ContentCell();
            ContentCell contentCell3 = new ContentCell();

            contentRowList.Add(contentCell1, contentCell2, contentCell3);

            List <ContentCell> expected = new List <ContentCell>
            {
                contentCell1,
                contentCell2,
                contentCell3
            };

            Assert.That(contentRowList[0], Is.EqualTo(expected));
        }
Esempio n. 14
0
        public virtual UICollectionViewCell GetCell(ContentCell item, ContentCellContainer reusableCell, UICollectionView cv)
        {
            Performance.Start(out string reference);

            if (reusableCell.ContentCell != null)
            {
                ClearPropertyChanged(reusableCell);
            }

            reusableCell.ContentCell = item;

            SetUpPropertyChanged(reusableCell);

            reusableCell.UpdateNativeCell();

            Performance.Stop(reference);

            return(reusableCell);
        }
        public void HavingDataGridWithPaddingLeft5_WhenCalculatingPaddingLeft_ThenPaddingLeftIs5()
        {
            ContentCell contentCell = new ContentCell();

            ContentRow contentRow = new ContentRow();

            contentRow.AddCell(contentCell);

            DataGrid dataGrid = new DataGrid
            {
                CellPaddingLeft = 5
            };

            dataGrid.Rows.Add(contentRow);

            int actual = contentCell.CalculatePaddingLeft();

            Assert.That(actual, Is.EqualTo(5));
        }
Esempio n. 16
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_contentCell != null)
                {
                    _contentCell.PropertyChanged -= CellPropertyChanged;
                    CellParent.PropertyChanged   -= ParentPropertyChanged;
                    _contentCell = null;
                }

                ViewHolder = null;

                _contentViewRenderer?.View?.RemoveFromParent();
                _contentViewRenderer?.Dispose();
                _contentViewRenderer = null;
            }
            base.Dispose(disposing);
        }
Esempio n. 17
0
        public AView GetCell(ContentCell formsCell, ContentCellContainer nativeCell, Android.Views.ViewGroup parent, Context context)
        {
            Performance.Start(out string reference);

            if (nativeCell.ContentCell != null)
            {
                ClearPropertyChanged(nativeCell);
            }

            nativeCell.ContentCell = formsCell;

            SetUpPropertyChanged(nativeCell);

            nativeCell.UpdateNativeCell();

            Performance.Stop(reference);

            return(nativeCell);
        }
Esempio n. 18
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                if (_contentCell != null)
                {
                    _contentCell.PropertyChanged -= CellPropertyChanged;
                    CellParent.PropertyChanged   -= ParentPropertyChanged;
                }


                IVisualElementRenderer renderer;
                if (_rendererRef != null && _rendererRef.TryGetTarget(out renderer) && renderer.Element != null)
                {
                    var platform = renderer.Element.Platform as Platform;
                    if (platform != null)
                    {
                        DisposeModelAndChildrenRenderers(renderer.Element);
                    }

                    _rendererRef = null;
                }

                _selectedForegroundView?.RemoveFromSuperview();
                _selectedForegroundView?.Dispose();
                _selectedForegroundView = null;

                _contentCell = null;
            }

            _disposed = true;

            base.Dispose(disposing);
        }
        public void HavingColumnWithPaddingRight5_WhenCalculatingPaddingRight_ThenPaddingRightIs5()
        {
            ContentCell contentCell = new ContentCell();

            ContentRow contentRow = new ContentRow();

            contentRow.AddCell(contentCell);

            DataGrid dataGrid = new DataGrid();

            dataGrid.Rows.Add(contentRow);

            Column column = new Column
            {
                CellPaddingRight = 5
            };

            dataGrid.Columns.Add(column);

            int actual = contentCell.CalculatePaddingRight();

            Assert.That(actual, Is.EqualTo(5));
        }
        public void SetUp()
        {
            Content content = new Content();

            contentCell = new ContentCell(content, HorizontalAlignment.Center);
        }
Esempio n. 21
0
        public void Update(UITableView tableView, Cell cell, UITableViewCell nativeCell)
        {
            var parentListView = cell.RealParent as ListView;
            var recycling      = parentListView != null && parentListView.CachingStrategy == ListViewCachingStrategy.RecycleElement;

            if (_cell != cell && recycling)
            {
                if (_cell != null)
                {
                    ((INotifyCollectionChanged)_cell.ContextActions).CollectionChanged -= OnContextItemsChanged;
                }

                ((INotifyCollectionChanged)cell.ContextActions).CollectionChanged += OnContextItemsChanged;
            }

            var height = Frame.Height;
            var width  = tableView.Frame.Width;

            nativeCell.Frame = new RectangleF(0, 0, width, height);
            nativeCell.SetNeedsLayout();

            var handler = new PropertyChangedEventHandler(OnMenuItemPropertyChanged);

            _tableView = tableView;
            SetupSelection(tableView);

            if (_cell != null)
            {
                if (!recycling)
                {
                    _cell.PropertyChanged -= OnCellPropertyChanged;
                }
                if (_menuItems.Count > 0)
                {
                    if (!recycling)
                    {
                        ((INotifyCollectionChanged)_cell.ContextActions).CollectionChanged -= OnContextItemsChanged;
                    }

                    foreach (var item in _menuItems)
                    {
                        item.PropertyChanged -= handler;
                    }
                }

                _menuItems.Clear();
            }

            _menuItems.AddRange(cell.ContextActions);

            _cell = cell;
            if (!recycling)
            {
                cell.PropertyChanged += OnCellPropertyChanged;
                ((INotifyCollectionChanged)_cell.ContextActions).CollectionChanged += OnContextItemsChanged;
            }

            var isOpen = false;

            if (_scroller == null)
            {
                _scroller = new UIScrollView(new RectangleF(0, 0, width, height));
                _scroller.ScrollsToTop = false;
                _scroller.ShowsHorizontalScrollIndicator = false;

                if (Forms.IsiOS8OrNewer)
                {
                    _scroller.PreservesSuperviewLayoutMargins = true;
                }

                ContentView.AddSubview(_scroller);
            }
            else
            {
                _scroller.Frame = new RectangleF(0, 0, width, height);
                isOpen          = ScrollDelegate.IsOpen;

                for (var i = 0; i < _buttons.Count; i++)
                {
                    var b = _buttons[i];
                    b.RemoveFromSuperview();
                    b.Dispose();
                }

                _buttons.Clear();

                ScrollDelegate.Unhook(_scroller);
                ScrollDelegate.Dispose();
            }

            if (ContentCell != nativeCell)
            {
                if (ContentCell != null)
                {
                    ContentCell.RemoveFromSuperview();
                    ContentCell = null;
                }

                ContentCell = nativeCell;

                //Hack: if we have a ImageCell the insets are slightly different,
                //the inset numbers user below were taken using the Reveal app from the default cells
                if ((ContentCell as CellTableViewCell)?.Cell is ImageCell)
                {
                    nfloat imageCellInsetLeft  = 57;
                    nfloat imageCellInsetRight = 0;
                    if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
                    {
                        imageCellInsetLeft  = 89;
                        imageCellInsetRight = imageCellInsetLeft / 2;
                    }
                    SeparatorInset = new UIEdgeInsets(0, imageCellInsetLeft, 0, imageCellInsetRight);
                }

                _scroller.AddSubview(nativeCell);
            }

            SetupButtons(width, height);

            UIView container = null;

            var totalWidth = width;

            for (var i = _buttons.Count - 1; i >= 0; i--)
            {
                var b = _buttons[i];
                totalWidth += b.Frame.Width;

                if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                {
                    _scroller.AddSubview(b);
                }
                else
                {
                    if (container == null)
                    {
                        container = new iOS7ButtonContainer(b.Frame.Width);
                        _scroller.InsertSubview(container, 0);
                    }

                    container.AddSubview(b);
                }
            }

            _scroller.Delegate    = new ContextScrollViewDelegate(container, _buttons, isOpen);
            _scroller.ContentSize = new SizeF(totalWidth, height);

            if (isOpen)
            {
                _scroller.SetContentOffset(new PointF(ScrollDelegate.ButtonsWidth, 0), false);
            }
            else
            {
                _scroller.SetContentOffset(new PointF(0, 0), false);
            }
        }
Esempio n. 22
0
 public override SizeF SizeThatFits(SizeF size)
 {
     return(ContentCell.SizeThatFits(size));
 }
        public void SetUp()
        {
            MultilineText multilineText = new MultilineText("some content");

            contentCell = new ContentCell(multilineText, HorizontalAlignment.Center);
        }
Esempio n. 24
0
        private void OnLayoutContentCell(ContentCell cell)
        {
            if (!string.IsNullOrEmpty(cell.SubtextLabel.Text) && cell.MinHeight == Cell.StandardCellHeight)
            {
                cell.MinHeight = Cell.StandardCellHeight + Thickness.TopMargin + Thickness.BottomMargin;
            }
            else if (string.IsNullOrEmpty(cell.SubtextLabel.Text) && cell.MinHeight == (Cell.StandardCellHeight + Thickness.TopMargin + Thickness.BottomMargin))
            {
                cell.MinHeight = Cell.StandardCellHeight;
            }

            var tableCell = ((IPairable)cell).Pair as UITableViewCell;

            if (tableCell == null || !UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
            {
                return;
            }

            if (cell.Image.Dimensions == Size.Empty)
            {
                tableCell.SeparatorInset = new UIEdgeInsets(0, 15, 0, 0);
            }
            else
            {
                var margin = cell.Image.Margin;
                if (margin.Right < Thickness.LeftMargin)
                {
                    margin.Right      = Thickness.LeftMargin;
                    cell.Image.Margin = margin;
                }

                double height = (double.IsInfinity(cell.MaxHeight) ? double.MaxValue : cell.MaxHeight) -
                                (cell.Padding.Top + cell.Padding.Bottom) - (margin.Top + margin.Bottom);

                float width = (float)cell.Image.Measure(new Size(tableCell.ContentView.Frame.Width - (cell.Padding.Left + cell.Padding.Right) - (margin.Left + margin.Right), height)).Width;
                tableCell.SeparatorInset = new UIEdgeInsets(0, (float)(cell.Padding.Left + margin.Left + margin.Right) + width, 0, 0);

                var tableView = tableCell.GetSuperview <TableView>();
                if (tableView == null)
                {
                    return;
                }

                var indexPath = tableView.IndexPathForCell(tableCell);
                if (tableView.Style == UITableViewStyle.Grouped && tableView.Source.RowsInSection(tableView, indexPath.Section) == indexPath.Row + 1)
                {
                    return;
                }

                var contentSuper = tableCell.ContentView.Superview;
                var separator    = contentSuper.Subviews.FirstOrDefault(v => v is SeparatorView);
                if (separator != null)
                {
                    var contentFrame = tableCell.ContentView.Frame;
                    contentFrame.Height         = contentSuper.Frame.Height - (1 / UIScreen.MainScreen.Scale);
                    tableCell.ContentView.Frame = contentFrame;

                    separator.Frame = new CGRect(tableCell.SeparatorInset.Left,
                                                 tableCell.ContentView.Frame.Bottom + tableCell.SeparatorInset.Top,
                                                 tableCell.Frame.Width - tableCell.SeparatorInset.Left - tableCell.SeparatorInset.Right,
                                                 contentSuper.Frame.Height - tableCell.ContentView.Frame.Height - tableCell.SeparatorInset.Bottom - tableCell.SeparatorInset.Top);
                }
            }
        }
        public void SetUp()
        {
            MultilineText multilineText = new MultilineText("some content");

            contentCell = new ContentCell(multilineText);
        }
 public void SetUp()
 {
     contentCell = new ContentCell("some content", HorizontalAlignment.Center);
 }
        public void SetUp()
        {
            Content content = new Content();

            contentCell = new ContentCell(content);
        }
 public void SetUp()
 {
     contentCell = new ContentCell("some content");
 }
Esempio n. 29
0
 public void SetUp()
 {
     contentCell = new ContentCell();
 }
Esempio n. 30
0
        public void UpdateCell(ContentCell cell)
        {
            Performance.Start(out string reference);

            if (!IsEmpty)
            {
                _CellController.SendDisappearing();
            }

            if (_contentViewRenderer == null)
            {
                CreateNewRenderer(cell);
                _CellController.SendAppearing();
                Performance.Stop(reference);
                return;
            }

            var renderer        = GetChildAt(0) as IVisualElementRenderer;
            var viewHandlerType = Registrar.Registered.GetHandlerTypeForObject(cell.View) ?? DefaultRenderer;
            var reflectableType = renderer as System.Reflection.IReflectableType;
            var rendererType    = reflectableType != null?reflectableType.GetTypeInfo().AsType() : (renderer != null ? renderer.GetType() : typeof(System.Object));

            if (renderer != null && rendererType == viewHandlerType)
            {
                Performance.Start(reference, "Reuse");
                _contentCell = cell;

                cell.View.DisableLayout = true;
                foreach (VisualElement c in cell.View.Descendants())
                {
                    c.DisableLayout = true;
                }

                Performance.Start(reference, "Reuse.SetElement");
                renderer.SetElement(cell.View);
                Performance.Stop(reference, "Reuse.SetElement");

                Platform.SetRenderer(cell.View, _contentViewRenderer);

                cell.View.DisableLayout = false;
                foreach (VisualElement c in cell.View.Descendants())
                {
                    c.DisableLayout = false;
                }

                var viewAsLayout = cell.View as Layout;
                if (viewAsLayout != null)
                {
                    viewAsLayout.ForceLayout();
                }

                Invalidate();
                _CellController.SendAppearing();
                Performance.Stop(reference, "Reuse");
                Performance.Stop(reference);
                return;
            }

            RemoveView(_contentViewRenderer.View);
            Platform.SetRenderer(_contentCell.View, null);
            _contentCell.View.IsPlatformEnabled = false;
            _contentViewRenderer.View.Dispose();

            _contentCell         = cell;
            _contentViewRenderer = Platform.CreateRendererWithContext(_contentCell.View, Context);

            Platform.SetRenderer(_contentCell.View, _contentViewRenderer);
            AddView(_contentViewRenderer.View);

            _CellController.SendAppearing();
            Performance.Stop(reference);
        }