Use for loop and SetLayoutPosition

This commit is contained in:
Dean Herbert 2018-06-08 21:20:15 +09:00
parent 1e7bffe5e3
commit a880e626d8
1 changed files with 6 additions and 3 deletions

View File

@ -107,16 +107,19 @@ public void ShowBadges(Badge[] badges)
visibleBadge = 0;
badgeFlowContainer.Clear();
foreach (var badge in badges)
for (var index = 0; index < badges.Length; index++)
{
LoadComponentAsync(new DrawableBadge(badge)
int displayIndex = index;
LoadComponentAsync(new DrawableBadge(badges[index])
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
}, asyncBadge =>
{
badgeFlowContainer.Add(asyncBadge);
badgeFlowContainer.ChangeChildDepth(asyncBadge, Array.IndexOf(badges, asyncBadge)); //Ensure the badges are ordered correctly
// load in stable order regardless of async load order.
badgeFlowContainer.SetLayoutPosition(asyncBadge, displayIndex);
});
}
}