[iOS,Android] Fix gap when setting Separator None and recycle element and on Android when using grouping (#949)

* [Controls] Add repo for bugzilla 39802

* [iOS] Make ContextCell hide the gap when we aren't using a separator

* [Controls] Update test

* [iOS] Only fix height if separator is hidden.

* [iOS] Only fix if it's a ListiView

* [Android] Fix separator showing when using Grouping

* Update Bugzilla39802.cs
This commit is contained in:
Rui Marinho 2017-06-14 23:58:03 +01:00 коммит произвёл Jason Smith
Родитель 02c93b6b99
Коммит ec5492cd0d
4 изменённых файлов: 104 добавлений и 2 удалений

Просмотреть файл

@ -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<GroupedData>();
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<GroupedData> ListItems { get; set; }
public class MyItem
{
public string Title { get; set; }
public Color Color { get; set; }
}
[Preserve(AllMembers = true)]
public class GroupedData : List<MyItem>
{
public string GroupName { get; set; }
}
}
}

Просмотреть файл

@ -291,6 +291,7 @@
<Compile Include="$(MSBuildThisFileDirectory)ListViewNRE.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla55745.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla55365.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla39802.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla53179.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla54036.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla40161.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) };

Просмотреть файл

@ -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);