Fix 39802 (#217)
authorRui Marinho <me@ruimarinho.net>
Fri, 17 Jun 2016 16:29:43 +0000 (17:29 +0100)
committerGitHub <noreply@github.com>
Fri, 17 Jun 2016 16:29:43 +0000 (17:29 +0100)
* [iOS] When using ContextActionsCell make sure we don't show the ContentCell separator

* [Android] Don't write separator view if not needed

Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs
Xamarin.Forms.Platform.iOS/Cells/CellTableViewCell.cs
Xamarin.Forms.Platform.iOS/Cells/ViewCellRenderer.cs

index 667226f..64d9d18 100644 (file)
@@ -187,11 +187,11 @@ namespace Xamarin.Forms.Platform.Android
                                }
                        }
 
-                       var makeBline = true;
+                       var cellIsBeingReused = false;
                        var layout = convertView as ConditionalFocusLayout;
                        if (layout != null)
                        {
-                               makeBline = false;
+                               cellIsBeingReused = true;
                                convertView = layout.GetChildAt(0);
                        }
                        else
@@ -262,7 +262,7 @@ namespace Xamarin.Forms.Platform.Android
 
                        Performance.Start("AddView");
 
-                       if (!makeBline)
+                       if (cellIsBeingReused)
                        {
                                if (convertView != view)
                                {
@@ -275,42 +275,13 @@ namespace Xamarin.Forms.Platform.Android
 
                        Performance.Stop("AddView");
 
-                       AView bline;
-                       if (makeBline)
-                       {
-                               bline = new AView(_context) { LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 1) };
-
-                               layout.AddView(bline);
-                       }
-                       else
-                               bline = layout.GetChildAt(1);
-
                        bool isHeader = cell.GetIsGroupHeader<ItemsView<Cell>, Cell>();
 
-                       Color separatorColor = _listView.SeparatorColor;
-
-                       if (nextCellIsHeader || _listView.SeparatorVisibility == SeparatorVisibility.None)
-                               bline.SetBackgroundColor(global::Android.Graphics.Color.Transparent);
-                       else if (isHeader || !separatorColor.IsDefault)
-                               bline.SetBackgroundColor(separatorColor.ToAndroid(Color.Accent));
-                       else
-                       {
-                               if (s_dividerHorizontalDarkId == int.MinValue)
-                               {
-                                       using (var value = new TypedValue())
-                                       {
-                                               int id = global::Android.Resource.Drawable.DividerHorizontalDark;
-                                               if (_context.Theme.ResolveAttribute(global::Android.Resource.Attribute.ListDivider, value, true))
-                                                       id = value.ResourceId;
-                                               else if (_context.Theme.ResolveAttribute(global::Android.Resource.Attribute.Divider, value, true))
-                                                       id = value.ResourceId;
+                       AView bline;
 
-                                               s_dividerHorizontalDarkId = id;
-                                       }
-                               }
+                       UpdateSeparatorVisibility(cell, cellIsBeingReused, isHeader, nextCellIsHeader, layout, out bline);
 
-                               bline.SetBackgroundResource(s_dividerHorizontalDarkId);
-                       }
+                       UpdateSeparatorColor(isHeader, bline);
 
                        if ((bool)cell.GetValue(IsSelectedProperty))
                                Select(position, layout);
@@ -546,6 +517,53 @@ namespace Xamarin.Forms.Platform.Android
                        Select(position, view);
                }
 
+               void UpdateSeparatorVisibility(Cell cell, bool cellIsBeingReused, bool isHeader, bool nextCellIsHeader, ConditionalFocusLayout layout, out AView bline)
+               {
+                       bline = null;
+                       if (cellIsBeingReused)
+                               return;
+                       var makeBline = _listView.SeparatorVisibility == SeparatorVisibility.Default || isHeader && !nextCellIsHeader;
+                       if (makeBline)
+                       {
+                               bline = new AView(_context) { LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 1) };
+                               layout.AddView(bline);
+                       }
+                       else if (layout.ChildCount > 1)
+                       {
+                               layout.RemoveViewAt(1);
+                       }
+               }
+
+
+               void UpdateSeparatorColor(bool isHeader, AView bline)
+               {
+                       if (bline == null)
+                               return;
+
+                       Color separatorColor = _listView.SeparatorColor;
+
+                       if (isHeader || !separatorColor.IsDefault)
+                               bline.SetBackgroundColor(separatorColor.ToAndroid(Color.Accent));
+                       else
+                       {
+                               if (s_dividerHorizontalDarkId == int.MinValue)
+                               {
+                                       using (var value = new TypedValue())
+                                       {
+                                               int id = global::Android.Resource.Drawable.DividerHorizontalDark;
+                                               if (_context.Theme.ResolveAttribute(global::Android.Resource.Attribute.ListDivider, value, true))
+                                                       id = value.ResourceId;
+                                               else if (_context.Theme.ResolveAttribute(global::Android.Resource.Attribute.Divider, value, true))
+                                                       id = value.ResourceId;
+
+                                               s_dividerHorizontalDarkId = id;
+                                       }
+                               }
+
+                               bline.SetBackgroundResource(s_dividerHorizontalDarkId);
+                       }
+               }
+
                enum CellType
                {
                        Row,
index f1a5391..4d9918f 100644 (file)
@@ -89,6 +89,9 @@ namespace Xamarin.Forms.Platform.iOS
                        if (contextCell != null)
                        {
                                contextCell.Update(tableView, cell, nativeCell);
+                               var viewTableCell = contextCell.ContentCell as ViewCellRenderer.ViewTableCell;
+                               if (viewTableCell != null)
+                                       viewTableCell.SupressSeparator = true;
                                nativeCell = contextCell;
                        }
 
index f1cb2fb..4f8a43e 100644 (file)
@@ -86,11 +86,19 @@ namespace Xamarin.Forms.Platform.iOS
                                get { return ViewCell; }
                        }
 
+                       internal bool SupressSeparator { get; set; }
+
                        public override void LayoutSubviews()
                        {
                                //This sets the content views frame.
                                base.LayoutSubviews();
 
+                               if (SupressSeparator)
+                               {
+                                       var oldFrame = Frame;
+                                       ContentView.Bounds = Frame = new RectangleF(oldFrame.Location, new SizeF(oldFrame.Width, oldFrame.Height + 0.5f));
+                               }
+
                                var contentFrame = ContentView.Frame;
                                var view = ViewCell.View;
 
@@ -114,8 +122,9 @@ namespace Xamarin.Forms.Platform.iOS
                                var height = size.Height > 0 ? size.Height : double.PositiveInfinity;
                                var result = renderer.Element.Measure(width, height);
 
-                               // make sure to add in the separator
-                               return new SizeF(size.Width, (float)result.Request.Height + 1f / UIScreen.MainScreen.Scale);
+                               // make sure to add in the separator if needed
+                               var finalheight = ((float)result.Request.Height + (SupressSeparator ? 0f : 1f)) / UIScreen.MainScreen.Scale;
+                               return new SizeF(size.Width, finalheight);
                        }
 
                        protected override void Dispose(bool disposing)