Skip to content

Commit

Permalink
Try and make scroll-to test more solid (#24286)
Browse files Browse the repository at this point in the history
  • Loading branch information
Foda authored Aug 17, 2024
2 parents 1385a01 + ed36001 commit fe89b55
Showing 1 changed file with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,23 +224,30 @@ into groups
})
};

var desiredItemIndex = 134; // 13th group (letter: N), 4th item
var firstVisibleItemIndex = -1;
var lastVisibleItemIndex = -1;
collectionView.Scrolled += (s, e) =>
{
firstVisibleItemIndex = e.FirstVisibleItemIndex;
lastVisibleItemIndex = e.LastVisibleItemIndex;
};

await CreateHandlerAndAddToWindow<CollectionViewHandler>(collectionView, async handler =>
{
collectionView.ScrollTo(index: 4, groupIndex: 13, animate: false); // Item "N_4"

await Task.Delay(500);
int retryCount = 3;
bool foundItem = false;

while (retryCount > 0 && !foundItem)
{
retryCount--;
await Task.Delay(500);

for (int i = 0; i < collectionView.LogicalChildrenInternal.Count; i++)
{
var item = collectionView.LogicalChildrenInternal[i];
if (item is Label label && label.Text.Equals("n_4", StringComparison.OrdinalIgnoreCase))
{
foundItem = true;
break;
}
}
}

Assert.True(desiredItemIndex >= firstVisibleItemIndex &&
desiredItemIndex <= lastVisibleItemIndex);
Assert.True(foundItem);
});
}

Expand Down

0 comments on commit fe89b55

Please sign in to comment.