Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with StartBringIntoView scrolling for items already visible #3167

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions dev/Repeater/APITests/RepeaterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using System.Threading;
using System.Collections.Generic;
using Windows.UI.Xaml.Tests.MUXControls.ApiTests.RepeaterTests.Common.Mocks;
using System.Diagnostics;

namespace Windows.UI.Xaml.Tests.MUXControls.ApiTests.RepeaterTests
{
Expand Down Expand Up @@ -665,52 +666,76 @@ public void VerifyRepeaterDoesNotLeakItemContainers()
[TestMethod]
public void BringIntoViewOfExistingItemsDoesNotChangeScrollOffset()
{
ScrollViewer scroll = null;
ScrollViewer scrollViewer = null;
ItemsRepeater repeater = null;
AutoResetEvent scrollViewerLoadedEvent = new AutoResetEvent(false);

RunOnUIThread.Execute(() =>
{
repeater = new ItemsRepeater();
repeater.ItemsSource = Enumerable.Range(0, 100).Select(x => x.ToString()).ToList();

scroll = new ScrollViewer() {
scrollViewer = new ScrollViewer() {
Content = repeater,
MaxHeight = 400,
MaxWidth = 200
};

Content = scroll;
scrollViewer.Loaded += (object sender, RoutedEventArgs e) =>
{
Log.Comment("ScrollViewer.Loaded event handler");
scrollViewerLoadedEvent.Set();
};

Content = scrollViewer;
Content.UpdateLayout();
});

IdleSynchronizer.Wait();

RunOnUIThread.Execute(() =>
{
scroll.ChangeView(null, repeater.ActualHeight, null);
scroll.UpdateLayout();
Log.Comment("Scroll to end");
scrollViewer.ChangeView(null, repeater.ActualHeight, null);
scrollViewer.UpdateLayout();
});

Log.Comment("Wait for scrolling");
if (Debugger.IsAttached)
{
scrollViewerLoadedEvent.WaitOne();
}
else
{
if (!scrollViewerLoadedEvent.WaitOne(TimeSpan.FromMilliseconds(5000)))
{
throw new Exception("Timeout expiration in WaitForEvent.");
}
}

IdleSynchronizer.Wait();

double endOfScrollOffset = 0;

RunOnUIThread.Execute(() =>
{
endOfScrollOffset = scroll.VerticalOffset;
Log.Comment("Determine scrolled offset");
endOfScrollOffset = scrollViewer.VerticalOffset;
// Idea: we might not have scrolled to the end, however we should at least have moved so much that the end is not too far away
Verify.IsTrue(Math.Abs(endOfScrollOffset - repeater.ActualHeight) < 500, $"We should at least have scrolled some amount. " +
$"ScrollOffset:{endOfScrollOffset} Repeater height: {repeater.ActualHeight}");

var lastItem = repeater.GetOrCreateElement(99);
lastItem.UpdateLayout();
Log.Comment("Bring last element into view");
lastItem.StartBringIntoView();
});

IdleSynchronizer.Wait();

RunOnUIThread.Execute(() =>
{
Verify.IsTrue(Math.Abs(endOfScrollOffset - scroll.VerticalOffset) < 1);
Log.Comment("Verify position did not change");
Verify.IsTrue(Math.Abs(endOfScrollOffset - scrollViewer.VerticalOffset) < 1);
});
}

Expand Down