Browse Source

WIP

fixes/11167-pagetransition-flicker
Steven Kirk 3 years ago
parent
commit
aa6c6032c6
  1. 10
      src/Avalonia.Controls/VirtualizingCarouselPanel.cs
  2. 4
      tests/Avalonia.Controls.UnitTests/VirtualizingCarouselPanelTests.cs

10
src/Avalonia.Controls/VirtualizingCarouselPanel.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
@ -128,7 +129,7 @@ namespace Avalonia.Controls
// Get or create an element for the new item.
if (index >= 0 && index < items.Count)
{
_realized = GetOrCreateElement(items, index);
_realized = GetOrCreateElement(items, index, _transitionFrom is not null);
_realizedIndex = index;
}
}
@ -245,7 +246,7 @@ namespace Avalonia.Controls
InvalidateMeasure();
}
private Control GetOrCreateElement(IReadOnlyList<object?> items, int index)
private Control GetOrCreateElement(IReadOnlyList<object?> items, int index, bool willTransition)
{
Debug.Assert(ItemContainerGenerator is not null);
@ -265,6 +266,10 @@ namespace Avalonia.Controls
{
e = GetItemAsOwnContainer(item, index);
}
// If there is a transition, we want the control to be initially invisible, and
// shown by the transition at the correct time.
e.IsVisible = !willTransition;
}
return e;
@ -306,7 +311,6 @@ namespace Avalonia.Controls
if (_recyclePool?.TryGetValue(recycleKey, out var recyclePool) == true && recyclePool.Count > 0)
{
var recycled = recyclePool.Pop();
recycled.IsVisible = true;
generator.PrepareItemContainer(recycled, item, index);
generator.ItemContainerPrepared(recycled, item, index);
return recycled;

4
tests/Avalonia.Controls.UnitTests/VirtualizingCarouselPanelTests.cs

@ -168,14 +168,14 @@ namespace Avalonia.Controls.UnitTests
Layout(target);
Assert.Equal(items, target.Children);
Assert.All(items, x => Assert.True(x.IsVisible));
Assert.True(items[0].IsVisible);
Assert.False(items[1].IsVisible);
transitionTask.SetResult();
sync.ExecutePostedCallbacks();
Assert.Equal(items, target.Children);
Assert.False(items[0].IsVisible);
Assert.True(items[1].IsVisible);
}
[Fact]

Loading…
Cancel
Save