From aa6c6032c6eebca53333107eb7811ac32fc9f774 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 10 May 2023 14:52:26 +0200 Subject: [PATCH] WIP --- src/Avalonia.Controls/VirtualizingCarouselPanel.cs | 10 +++++++--- .../VirtualizingCarouselPanelTests.cs | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Avalonia.Controls/VirtualizingCarouselPanel.cs b/src/Avalonia.Controls/VirtualizingCarouselPanel.cs index 958c19826d..956421caa2 100644 --- a/src/Avalonia.Controls/VirtualizingCarouselPanel.cs +++ b/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 items, int index) + private Control GetOrCreateElement(IReadOnlyList 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; diff --git a/tests/Avalonia.Controls.UnitTests/VirtualizingCarouselPanelTests.cs b/tests/Avalonia.Controls.UnitTests/VirtualizingCarouselPanelTests.cs index 5e276b5911..42000f7e21 100644 --- a/tests/Avalonia.Controls.UnitTests/VirtualizingCarouselPanelTests.cs +++ b/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]