Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Animation Playback in Avalonia Composition #17368

Closed
lindexi opened this issue Oct 28, 2024 · 0 comments · Fixed by #17370
Closed

Issue with Animation Playback in Avalonia Composition #17368

lindexi opened this issue Oct 28, 2024 · 0 comments · Fixed by #17370

Comments

@lindexi
Copy link
Contributor

lindexi commented Oct 28, 2024

Describe the bug

I hope this message finds you well. I am writing to report an issue I encountered with the animation playback in Avalonia's Composition API. Specifically, when triggering a Composition animation multiple times, the second frame of the animation stops playing.

To Reproduce

Step:

  1. Place a UI control, such as a Border control, on the interface.
  2. Use the ElementComposition.GetElementVisual method to obtain a CompositionVisual object, and then create and play a Vector3DKeyFrameAnimation using this object.
  3. Repeat step 2.

Upon repeating step 2, you will observe that the originally playing animation stops.

XAML Code:

    <Grid>
        <Border x:Name="ScanBorder" ZIndex="101" IsVisible="True" HorizontalAlignment="Center" VerticalAlignment="Top"
                Height="220" Width="600">
            <Border.Background>
                <LinearGradientBrush StartPoint="0%,0%" EndPoint="0%,100%">
                    <GradientStop Color="#0033CEFF" Offset="0" />
                    <GradientStop Color="#CC3592FF" Offset="1" />
                </LinearGradientBrush>
            </Border.Background>
            <Border.RenderTransform>
                <TranslateTransform />
            </Border.RenderTransform>
        </Border>

        <Button x:Name="ControlButton" Content="Click" Click="ControlButton_OnClick"></Button>
    </Grid>

C# Code:

    private Vector3DKeyFrameAnimation? _vector3DKeyFrameAnimation;
    private CompositionVisual? _scanBorderCompositionVisual;

    private void ControlButton_OnClick(object? sender, RoutedEventArgs e)
    {
        _scanBorderCompositionVisual = ElementComposition.GetElementVisual(ScanBorder)!;
        var compositor = _scanBorderCompositionVisual.Compositor;
        _vector3DKeyFrameAnimation = compositor.CreateVector3DKeyFrameAnimation();
        _vector3DKeyFrameAnimation.InsertKeyFrame(0f, _scanBorderCompositionVisual.Offset with { Y = 0 });
        _vector3DKeyFrameAnimation.InsertKeyFrame(1f, _scanBorderCompositionVisual.Offset with { Y = this.Bounds.Height - ScanBorder.Height });
        _vector3DKeyFrameAnimation.Duration = TimeSpan.FromSeconds(2);
        _vector3DKeyFrameAnimation.IterationBehavior = AnimationIterationBehavior.Count;
        _vector3DKeyFrameAnimation.IterationCount = 30;

        _scanBorderCompositionVisual.StartAnimation("Offset", _vector3DKeyFrameAnimation);
    }

I have uploaded a minimal reproducible example project on GitHub for your reference, see https://github.com/lindexi/lindexi_gd/tree/f82af28bab6f5cdfbd13c48c19b4f0a21a50ae06/AvaloniaIDemo/JallkeleejurCihayaiqalker

You can pull my project code and run it. And then you can click the Click button to reproduce this issues.

Expected behavior

The expected behavior is to be able to control the stopping of an existing Composition animation and start a new one seamlessly.

Avalonia version

11.1.0

OS

Windows

Additional context

I found some links to related issues, but these links do not help with this issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants