Changes to cell separators now happen more reactively.

This commit is contained in:
Troy Stanger 2018-11-09 15:20:52 -06:00
parent eb2a8ec367
commit e4cb4e1123
1 changed files with 27 additions and 5 deletions

View File

@ -41,6 +41,7 @@ namespace Ooui.Forms.Renderers
e.NewElement.ScrollToRequested += ListView_ScrollToRequested; e.NewElement.ScrollToRequested += ListView_ScrollToRequested;
UpdateItems (); UpdateItems ();
UpdateSeparator ();
UpdateBackgroundColor (); UpdateBackgroundColor ();
} }
@ -53,6 +54,10 @@ namespace Ooui.Forms.Renderers
if (e.PropertyName == ItemsView<Cell>.ItemsSourceProperty.PropertyName) if (e.PropertyName == ItemsView<Cell>.ItemsSourceProperty.PropertyName)
UpdateItems (); UpdateItems ();
else if (e.PropertyName == Xamarin.Forms.ListView.SeparatorColorProperty.PropertyName)
UpdateSeparator ();
else if (e.PropertyName == Xamarin.Forms.ListView.SeparatorVisibilityProperty.PropertyName)
UpdateSeparator ();
} }
protected override void Dispose (bool disposing) protected override void Dispose (bool disposing)
@ -76,6 +81,7 @@ namespace Ooui.Forms.Renderers
private void OnCollectionChanged (object sender, NotifyCollectionChangedEventArgs e) private void OnCollectionChanged (object sender, NotifyCollectionChangedEventArgs e)
{ {
UpdateItems (); UpdateItems ();
UpdateSeparator ();
} }
private void UnsubscribeCellClicks () private void UnsubscribeCellClicks ()
@ -108,11 +114,6 @@ namespace Ooui.Forms.Renderers
for (var i = listItems.Count; i < items.Count; i++) { for (var i = listItems.Count; i < items.Count; i++) {
var li = new ListItem (); var li = new ListItem ();
li.Style["list-style-type"] = "none"; li.Style["list-style-type"] = "none";
if (Element.SeparatorVisibility == SeparatorVisibility.Default)
{
var color = Element.SeparatorColor.ToOouiColor(Color.FromStyleValue("#999"));
li.Style["border-bottom"] = string.Format("{0}px {1} {2}", 1, "solid", color.ToString());
}
li.Click += ListItem_Click; li.Click += ListItem_Click;
Control.AppendChild (li); Control.AppendChild (li);
listItems.Add (li); listItems.Add (li);
@ -139,6 +140,27 @@ namespace Ooui.Forms.Renderers
} }
} }
private void UpdateSeparator()
{
if (Control == null)
return;
var listItems = Control.Children.OfType<ListItem>().ToList();
foreach (var li in listItems)
{
if (Element.SeparatorVisibility == SeparatorVisibility.Default)
{
var color = Element.SeparatorColor.ToOouiColor(Color.FromStyleValue("#999"));
li.Style["border-bottom"] = string.Format("{0}px {1} {2}", 1, "solid", color.ToString());
}
else
{
li.Style["border-bottom"] = null;
}
}
}
void ListItem_Click (object sender, TargetEventArgs e) void ListItem_Click (object sender, TargetEventArgs e)
{ {
if (Control == null) if (Control == null)