diff options
author | Rui Marinho <me@ruimarinho.net> | 2016-06-17 17:29:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-17 17:29:43 +0100 |
commit | dae4dfa94c71246bfc597d23449a6ba43e5255ff (patch) | |
tree | c6b7a06f930c8bf21a412b748f226ad844895362 /Xamarin.Forms.Platform.Android | |
parent | 925fc0aa588a060eb23fa16c1d225dd030012c23 (diff) | |
download | xamarin-forms-dae4dfa94c71246bfc597d23449a6ba43e5255ff.tar.gz xamarin-forms-dae4dfa94c71246bfc597d23449a6ba43e5255ff.tar.bz2 xamarin-forms-dae4dfa94c71246bfc597d23449a6ba43e5255ff.zip |
Fix 39802 (#217)
* [iOS] When using ContextActionsCell make sure we don't show the ContentCell separator
* [Android] Don't write separator view if not needed
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r-- | Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs | 88 |
1 files changed, 53 insertions, 35 deletions
diff --git a/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs b/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs index 667226f6..64d9d180 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs @@ -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, |