Skip to content

Commit

Permalink
fix(listview): [Android] Fix flicker and clipping when ListViewItem.M…
Browse files Browse the repository at this point in the history
…argin is set

Fix a regression introduced by performance improvements to reduce the number of times items are measured. The margin was being omitted, leading to strange results.
  • Loading branch information
davidjohnoliver authored and jeromelaban committed Nov 5, 2021
1 parent 540f55b commit 7425947
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Uno.UI.RuntimeTests.Extensions;
#if NETFX_CORE
using Uno.UI.Extensions;
#elif __IOS__
Expand Down Expand Up @@ -309,6 +310,40 @@ private static void ScrollBy(ListViewBase listViewBase, double scrollBy)
sv.ChangeView(null, scrollBy, null);
}

private static async Task ScrollByInIncrements(ListViewBase listViewBase, double scrollBy)
{
var sv = listViewBase.FindFirstChild<ScrollViewer>();
Assert.IsNotNull(sv);
var current = sv.VerticalOffset;
if (current == scrollBy)
{
return;
}
var increment = sv.ActualHeight / 2;
if (increment == 0)
{
Assert.Fail("ScrollViewer must have non-zero height");
}
if (scrollBy > current)
{
for (double d = current + increment; d < scrollBy; d += increment)
{
sv.ChangeView(null, d, null);
await Task.Delay(10);
}
}
else
{
for (double d = current - increment; d > scrollBy; d -= increment)
{
sv.ChangeView(null, d, null);
await Task.Delay(10);
}
}

sv.ChangeView(null, scrollBy, null);
}

public class When_Item_Changes_Measure_Count_ItemViewModel : System.ComponentModel.INotifyPropertyChanged
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,19 @@ private Size TryMeasureChild(View child, Size slotSize, ViewType viewType)
}
else
{
return (child as FrameworkElement)?.AssignedActualSize ?? ViewHelper.PhysicalToLogicalPixels(new Size(child.Width, child.Height));
return GetMeasuredChildSize(child);
}
}

private static Size GetMeasuredChildSize(View child)
{
if (child is FrameworkElement fe)
{
return fe.AssignedActualSize.Add(fe.Margin);
}
else
{
return ViewHelper.PhysicalToLogicalPixels(new Size(child.Width, child.Height));
}
}

Expand Down

0 comments on commit 7425947

Please sign in to comment.