private void RemovePreview(bool animated)
        {
            if (m_CurrentPreviews == null || m_RemovedPreviews != null)
            {
                return;
            }

            if (m_AddAnimations != null)
            {
                foreach (ValueAnimation <Rect> addAnimation in m_AddAnimations)
                {
                    addAnimation.Stop();
                }
                m_AddAnimations = null;
            }

            m_RemovedPreviews = m_CurrentPreviews;

            if (animated)
            {
                m_RemoveAnimations = new List <ValueAnimation <Rect> >(m_CurrentPreviews.Count);

                foreach (VisualElement preview in m_RemovedPreviews)
                {
                    Rect startRect = new Rect(Vector2.zero, preview.layout.size);
                    Rect endRect   = startRect;

                    endRect.height = 0f;

                    var removeAnimations = new ValueAnimation <Rect>(this)
                    {
                        from     = startRect,
                        to       = endRect,
                        duration = animationDuration
                    };
                    removeAnimations.valueUpdated += value => UpdatePreviewLayout(preview, value);
                    removeAnimations.finished     += OnRemoveAnimationFinished;
                    removeAnimations.Start();
                    m_RemoveAnimations.Add(removeAnimations);
                }
            }
            else
            {
                RemovePreviewHelper();
            }
        }
        private void AddPreview(IList <VisualElement> previews, int index, bool animated)
        {
            // Update the current preview with the newly added preview
            m_CurrentPreviews = previews;

            foreach (VisualElement preview in m_CurrentPreviews)
            {
                Insert(index++, preview);
            }

            if (animated)
            {
                m_AddAnimations = new List <ValueAnimation <Rect> >(m_CurrentPreviews.Count);

                foreach (VisualElement preview in m_CurrentPreviews)
                {
                    Vector2 size      = new Vector2(preview.style.width.value.value, preview.style.height.value.value);
                    Rect    startRect = new Rect(Vector2.zero, size);
                    Rect    endRect   = startRect;

                    startRect.height = 0f;

                    var addAnimation = new ValueAnimation <Rect>(this)
                    {
                        from     = startRect,
                        to       = endRect,
                        duration = animationDuration
                    };
                    addAnimation.valueUpdated += value => UpdatePreviewLayout(preview, value);
                    addAnimation.Start();
                    m_AddAnimations.Add(addAnimation);
                }
            }
            else
            {
                foreach (VisualElement currentPreview in m_CurrentPreviews)
                {
                    currentPreview.style.position = Position.Relative;
                }
            }
        }