Skip to content

Commit e0fbb33

Browse files
Add DelayMs to ElementTransition for per-element stagger
Add optional DelayMs parameter to the ElementTransition record. When set, the CCV applies DelayTime/SetInitialValueBeforeDelay to the per-element progress KeyFrameAnimation so callers can stagger layout transitions by element index. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ecd29c5 commit e0fbb33

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/CompositionCollectionView/CompositionCollectionLayout.Transition.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ void TransferElements()
162162
var progressAnimation = Compositor.CreateScalarKeyFrameAnimation();
163163
progressAnimation.Duration = TimeSpan.FromMilliseconds(transition.Length);
164164
progressAnimation.StopBehavior = AnimationStopBehavior.SetToFinalValue;
165+
if (transition.DelayMs > 0)
166+
{
167+
progressAnimation.DelayTime = TimeSpan.FromMilliseconds(transition.DelayMs);
168+
progressAnimation.DelayBehavior = AnimationDelayBehavior.SetInitialValueBeforeDelay;
169+
}
165170
progressAnimation.InsertKeyFrame(0, 0f, transition.EasingFunction);
166171
progressAnimation.InsertKeyFrame(1, 1f, transition.EasingFunction);
167172

src/CompositionCollectionView/CompositionCollectionLayout.Update.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ void UpdateAndTransitionElement(ElementReference<TId, TItem> element, TItem newD
239239
var progressAnimation = Compositor.CreateScalarKeyFrameAnimation();
240240
progressAnimation.Duration = TimeSpan.FromMilliseconds(transition.Length);
241241
progressAnimation.StopBehavior = AnimationStopBehavior.SetToFinalValue;
242+
if (transition.DelayMs > 0)
243+
{
244+
progressAnimation.DelayTime = TimeSpan.FromMilliseconds(transition.DelayMs);
245+
progressAnimation.DelayBehavior = AnimationDelayBehavior.SetInitialValueBeforeDelay;
246+
}
242247
progressAnimation.InsertKeyFrame(0, 0f, transition.EasingFunction);
243248
progressAnimation.InsertKeyFrame(1, 1f, transition.EasingFunction);
244249

src/CompositionCollectionView/CompositionCollectionLayout.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void StopElementAnimation(ElementReference<TId, TItem> element)
133133
element.Visual.StopAnimation(AnimationConstants.Orientation);
134134
}
135135

136-
public record ElementTransition(uint Length, CompositionEasingFunction EasingFunction);
136+
public record ElementTransition(uint Length, CompositionEasingFunction EasingFunction, uint DelayMs = 0);
137137

138138
protected virtual void Dispose(bool disposing)
139139
{

0 commit comments

Comments
 (0)