diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39802.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39802.cs new file mode 100644 index 000000000..cb926e67a --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39802.cs @@ -0,0 +1,100 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; +using System.Collections.ObjectModel; +using System.Collections.Generic; + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 39802, "Gap between ListView cells even if SeparatorVisablity is set to none ", PlatformAffected.iOS)] + public class Bugzilla39802 : TestContentPage // or TestMasterDetailPage, etc ... + { + protected override void Init() + { + BackgroundColor = Color.Yellow; + + var list = new ObservableCollection(); + + for (int i = 1; i <= 2; i++) + { + var group = new GroupedData { GroupName = $"Group #{i}" }; + + for (int j = 1; j < 30; j++) + { + var item = new MyItem { Title = $"Item: #{i}-{j}", Color = (j % 2 == 0) ? Color.Blue : Color.Red }; + + group.Add(item); + } + list.Add(group); + } + + ListItems = list; + + BindingContext = this; + var lst = new ListView(ListViewCachingStrategy.RecycleElement) + { + BackgroundColor = Color.Transparent, + ItemTemplate = new DataTemplate(typeof(ItemTemplate)), + GroupHeaderTemplate = new DataTemplate(typeof(GroupHeaderTemplate)), + IsGroupingEnabled = true, + GroupDisplayBinding = new Binding(nameof(GroupedData.GroupName)), + GroupShortNameBinding = new Binding(nameof(GroupedData.GroupName)), + }; + lst.SeparatorVisibility = SeparatorVisibility.None; + lst.SeparatorColor = Color.Green; + lst.SetBinding(ListView.ItemsSourceProperty, nameof(ListItems)); + Content = lst; + } + + public class ItemTemplate : ViewCell + { + public ItemTemplate() + { + var stk = new StackLayout + { + Padding = new Thickness(15, 0, 0, 0) + }; + stk.SetBinding(VisualElement.BackgroundColorProperty, nameof(MyItem.Color)); + var lbl = new Label + { + TextColor = Color.Yellow, + VerticalOptions = LayoutOptions.CenterAndExpand + }; + lbl.SetBinding(Label.TextProperty, nameof(MyItem.Title)); + stk.Children.Add(lbl); + View = stk; + } + } + public class GroupHeaderTemplate : ViewCell + { + public GroupHeaderTemplate() + { + var title = new Label { TextColor = Color.White, FontSize = 16 }; + title.SetBinding(Label.TextProperty, new Binding(nameof(GroupedData.GroupName), BindingMode.OneWay)); + + View = new StackLayout + { + Padding = new Thickness(8, 0), + VerticalOptions = LayoutOptions.StartAndExpand, + BackgroundColor = Color.Pink, + Orientation = StackOrientation.Horizontal, + Children = { title }, + }; + } + } + + public ObservableCollection ListItems { get; set; } + public class MyItem + { + public string Title { get; set; } + + public Color Color { get; set; } + } + + [Preserve(AllMembers = true)] + public class GroupedData : List + { + public string GroupName { get; set; } + } + } +} diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 81e4bda08..97f26f7f8 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -291,6 +291,7 @@ + diff --git a/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs b/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs index b577ec1c1..1fa361419 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs @@ -541,7 +541,8 @@ namespace Xamarin.Forms.Platform.Android bline = null; if (cellIsBeingReused) return; - var makeBline = _listView.SeparatorVisibility == SeparatorVisibility.Default || isHeader && !nextCellIsHeader; + bool isSeparatorVisible = _listView.SeparatorVisibility == SeparatorVisibility.Default; + var makeBline = isSeparatorVisible || isHeader && isSeparatorVisible && !nextCellIsHeader; if (makeBline) { bline = new AView(_context) { LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 1) }; diff --git a/Xamarin.Forms.Platform.iOS/ContextActionCell.cs b/Xamarin.Forms.Platform.iOS/ContextActionCell.cs index 4ff7f87c8..d58219138 100644 --- a/Xamarin.Forms.Platform.iOS/ContextActionCell.cs +++ b/Xamarin.Forms.Platform.iOS/ContextActionCell.cs @@ -127,7 +127,7 @@ namespace Xamarin.Forms.Platform.iOS ((INotifyCollectionChanged)cell.ContextActions).CollectionChanged += OnContextItemsChanged; } - var height = Frame.Height; + var height = Frame.Height + (parentListView != null && parentListView.SeparatorVisibility == SeparatorVisibility.None ? 0.5f : 0f); var width = ContentView.Frame.Width; nativeCell.Frame = new RectangleF(0, 0, width, height);