<commit_before>// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Avalonia.Media;
using Avalonia.Styling;
using Avalonia.VisualTree;

namespace Avalonia.Animation
{
    /// <summary>
    /// Transitions between two pages by sliding them horizontally.
    /// </summary>
    public class PageSlide : IPageTransition
    {
        /// <summary>
        /// The axis on which the PageSlide should occur
        /// </summary>
        public enum SlideAxis
        {
            Horizontal,
            Vertical
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="PageSlide"/> class.
        /// </summary>
        public PageSlide()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="PageSlide"/> class.
        /// </summary>
        /// <param name="duration">The duration of the animation.</param>
        /// <param name="orientation">The axis on which the animation should occur</param>
        public PageSlide(TimeSpan duration, SlideAxis orientation = SlideAxis.Horizontal)
        {
            Duration = duration;
            Orientation = orientation;
        }

        /// <summary>
        /// Gets the duration of the animation.
        /// </summary>
        public TimeSpan Duration { get; set; }

        /// <summary>
        /// Gets the duration of the animation.
        /// </summary>
        public SlideAxis Orientation { get; set; }

        /// <summary>
        /// Starts the animation.
        /// </summary>
        /// <param name="from">
        /// The control that is being transitioned away from. May be null.
        /// </param>
        /// <param name="to">
        /// The control that is being transitioned to. May be null.
        /// </param>
        /// <param name="forward">
        /// If true, the new page is slid in from the right, or if false from the left.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> that tracks the progress of the animation.
        /// </returns>
        public async Task Start(Visual from, Visual to, bool forward)
        {
            var tasks = new List<Task>();
            var parent = GetVisualParent(from, to);
            var distance = Orientation == SlideAxis.Horizontal ? parent.Bounds.Width : parent.Bounds.Height;
            var translateProperty = Orientation == SlideAxis.Horizontal ? TranslateTransform.XProperty : TranslateTransform.YProperty;


            // TODO: Implement relevant transition logic here (or discard this class)
            // in favor of XAML based transition for pages
            if (from != null)
            {
                var animation = new Animation
                {
                    new KeyFrame
                    (
                        new Setter
                        {
                            Property = translateProperty,
                            Value = 0d
                        }
                    )
                    {
                        Cue = new Cue(0d)
                    },
                    new KeyFrame
                    (
                        new Setter
                        {
                            Property = translateProperty,
                            Value = forward ? distance : -distance
                        }
                    )
                    {
                        Cue = new Cue(1d)
                    }
                };
                animation.Duration = Duration;
                tasks.Add(animation.RunAsync(from));
            }

            if (to != null)
            {
                to.IsVisible = true;
                var animation = new Animation
                {

                    new KeyFrame
                    (
                        new Setter
                        {
                            Property = translateProperty,
                            Value = forward ? distance : -distance
                        }
                    )<commit_msg>Flip the sign on the outgoing carousel animation.<commit_after>// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Avalonia.Media;
using Avalonia.Styling;
using Avalonia.VisualTree;

namespace Avalonia.Animation
{
    /// <summary>
    /// Transitions between two pages by sliding them horizontally.
    /// </summary>
    public class PageSlide : IPageTransition
    {
        /// <summary>
        /// The axis on which the PageSlide should occur
        /// </summary>
        public enum SlideAxis
        {
            Horizontal,
            Vertical
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="PageSlide"/> class.
        /// </summary>
        public PageSlide()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="PageSlide"/> class.
        /// </summary>
        /// <param name="duration">The duration of the animation.</param>
        /// <param name="orientation">The axis on which the animation should occur</param>
        public PageSlide(TimeSpan duration, SlideAxis orientation = SlideAxis.Horizontal)
        {
            Duration = duration;
            Orientation = orientation;
        }

        /// <summary>
        /// Gets the duration of the animation.
        /// </summary>
        public TimeSpan Duration { get; set; }

        /// <summary>
        /// Gets the duration of the animation.
        /// </summary>
        public SlideAxis Orientation { get; set; }

        /// <summary>
        /// Starts the animation.
        /// </summary>
        /// <param name="from">
        /// The control that is being transitioned away from. May be null.
        /// </param>
        /// <param name="to">
        /// The control that is being transitioned to. May be null.
        /// </param>
        /// <param name="forward">
        /// If true, the new page is slid in from the right, or if false from the left.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> that tracks the progress of the animation.
        /// </returns>
        public async Task Start(Visual from, Visual to, bool forward)
        {
            var tasks = new List<Task>();
            var parent = GetVisualParent(from, to);
            var distance = Orientation == SlideAxis.Horizontal ? parent.Bounds.Width : parent.Bounds.Height;
            var translateProperty = Orientation == SlideAxis.Horizontal ? TranslateTransform.XProperty : TranslateTransform.YProperty;


            // TODO: Implement relevant transition logic here (or discard this class)
            // in favor of XAML based transition for pages
            if (from != null)
            {
                var animation = new Animation
                {
                    new KeyFrame
                    (
                        new Setter
                        {
                            Property = translateProperty,
                            Value = 0d
                        }
                    )
                    {
                        Cue = new Cue(0d)
                    },
                    new KeyFrame
                    (
                        new Setter
                        {
                            Property = translateProperty,
                            Value = forward ? -distance : distance
                        }
                    )
                    {
                        Cue = new Cue(1d)
                    }
                };
                animation.Duration = Duration;
                tasks.Add(animation.RunAsync(from));
            }

            if (to != null)
            {
                to.IsVisible = true;
                var animation = new Animation
                {

                    new KeyFrame
                    (
                        new Setter
                        {
                            Property = translateProperty,
                            Value = forward ? distance : -distance
                        }
                    )
{'fraction_non_alphanumeric': 0.09143600662408327, 'fraction_numerical': 0.0007097232079489, 'mean_word_length': 1.1388818618770553, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '402929', 'n_tokens_mistral': 1971, 'n_tokens_neox': 1850, 'n_words': 621}