diff --git a/PanCardView/CardsView.cs b/PanCardView/CardsView.cs index a3dbf84..1e218a3 100644 --- a/PanCardView/CardsView.cs +++ b/PanCardView/CardsView.cs @@ -549,8 +549,10 @@ protected virtual void OnSizeChanged() protected virtual void SetupBackViews(int? index = null) { - SetupNextView(index); - SetupPrevView(index); + var realIndex = index ?? SelectedIndex; + + SetupNextView(realIndex); + SetupPrevView(realIndex); if (IsRightToLeftFlowDirectionEnabled) { @@ -634,9 +636,11 @@ protected virtual async Task TryAutoNavigate() realDirection = (AnimationDirection)Sign(-(int)realDirection); } + var oldView = CurrentView; SetupBackViews(OldIndex); ResetActiveInactiveBackViews(realDirection); SwapViews(realDirection); + AddChild(oldView, CurrentView); var views = CurrentBackViews .Union(CurrentInactiveBackViews) @@ -644,8 +648,8 @@ protected virtual async Task TryAutoNavigate() .Where(x => x != null); var animationId = Guid.NewGuid(); - StartAutoNavigation(views, animationId, animationDirection); + await Task.Delay(5); var autoNavigationTask = Task.WhenAll( BackViewProcessor.HandleAutoNavigate(CurrentBackViews, this, realDirection, CurrentInactiveBackViews), FrontViewProcessor.HandleAutoNavigate(Enumerable.Repeat(CurrentView, 1), this, realDirection, Enumerable.Empty())); @@ -657,25 +661,22 @@ protected virtual async Task TryAutoNavigate() return true; } - protected virtual void SetupNextView(int? index = null) + protected virtual void SetupNextView(int index) { - var realIndex = index ?? SelectedIndex; var indeces = new int[BackViewsDepth]; for (int i = 0; i < indeces.Length; ++i) { - indeces[i] = realIndex + 1 + i; + indeces[i] = index + 1 + i; } NextViews = GetViews(AnimationDirection.Next, BackViewProcessor, indeces); } - protected virtual void SetupPrevView(int? index = null) + protected virtual void SetupPrevView(int index) { - var realIndex = index ?? SelectedIndex; - var prevIndex = IsOnlyForwardDirection - ? realIndex + 1 - : realIndex - 1; + ? index + 1 + : index - 1; var indeces = new int[BackViewsDepth]; @@ -686,7 +687,7 @@ protected virtual void SetupPrevView(int? index = null) { incValue = -incValue; } - indeces[i] = realIndex + incValue; + indeces[i] = index + incValue; } PrevViews = GetViews(AnimationDirection.Prev, BackViewProcessor, indeces); @@ -795,20 +796,29 @@ private void StartAutoNavigation(IEnumerable views, Guid animationId, Anim private void EndAutoNavigation(IEnumerable views, Guid animationId, AnimationDirection animationDirection) { + var isProcessingNow = !_interactions.CheckLastId(animationId); + _inCoursePanDelay = 0; if (views != null) { lock (_viewsInUseLocker) { + var depth = BackViewsDepth; foreach (var view in views) { _viewsInUse.Remove(view); + if (isProcessingNow && + !_viewsInUse.Contains(view) && + depth <= 1 && + view != CurrentView) + { + CleanView(view); + } } } } - IsAutoInteractionRunning = false; - var isProcessingNow = !_interactions.CheckLastId(animationId); + IsAutoInteractionRunning = false; RemoveRedundantChildren(isProcessingNow); FireItemAppearing(InteractionType.Auto, animationDirection != AnimationDirection.Prev, SelectedIndex); _interactions.Remove(animationId); diff --git a/PanCardView/Processors/BaseCardFrontViewProcessor.cs b/PanCardView/Processors/BaseCardFrontViewProcessor.cs index ee60db1..94da6bb 100644 --- a/PanCardView/Processors/BaseCardFrontViewProcessor.cs +++ b/PanCardView/Processors/BaseCardFrontViewProcessor.cs @@ -104,12 +104,14 @@ protected virtual void ResetInitialState(View view, bool isVisible = true) { if (view != null) { + view.BatchBegin(); view.Scale = 1; view.Opacity = 1; view.TranslationX = 0; view.Rotation = 0; view.TranslationY = 0; view.IsVisible = isVisible; + view.BatchCommit(); } } diff --git a/PanCardView/Processors/BaseCarouselFrontViewProcessor.cs b/PanCardView/Processors/BaseCarouselFrontViewProcessor.cs index e2dd743..15b8266 100644 --- a/PanCardView/Processors/BaseCarouselFrontViewProcessor.cs +++ b/PanCardView/Processors/BaseCarouselFrontViewProcessor.cs @@ -21,8 +21,10 @@ public virtual void HandleInitView(IEnumerable views, CardsView cardsView, var view = views.FirstOrDefault(); if (view != null) { + view.BatchBegin(); view.TranslationX = 0; view.IsVisible = true; + view.BatchCommit(); } } diff --git a/PanCardView/Processors/BaseCoverFlowFrontViewProcessor.cs b/PanCardView/Processors/BaseCoverFlowFrontViewProcessor.cs index 8df3028..5fb89e8 100644 --- a/PanCardView/Processors/BaseCoverFlowFrontViewProcessor.cs +++ b/PanCardView/Processors/BaseCoverFlowFrontViewProcessor.cs @@ -22,8 +22,10 @@ public virtual void HandleInitView(IEnumerable views, CardsView cardsView, var view = views.FirstOrDefault(); if (view != null) { + view.BatchBegin(); view.TranslationX = 0; view.IsVisible = true; + view.BatchCommit(); } } diff --git a/PanCardViewSample/PanCardViewSample/ViewModels/CardsSampleViewModel.cs b/PanCardViewSample/PanCardViewSample/ViewModels/CardsSampleViewModel.cs index 1f0d874..7d7718a 100644 --- a/PanCardViewSample/PanCardViewSample/ViewModels/CardsSampleViewModel.cs +++ b/PanCardViewSample/PanCardViewSample/ViewModels/CardsSampleViewModel.cs @@ -28,6 +28,11 @@ public CardsSampleViewModel() PanPositionChangedCommand = new Command(v => { + if(IsAutoAnimationRunning || IsUserInteractionRunning) + { + return; + } + var index = CurrentIndex + ((bool)v ? 1 : -1); if (index < 0 || index >= Items.Count) { @@ -60,7 +65,11 @@ public int CurrentIndex } } - public ObservableCollection Items { get; } + public bool IsAutoAnimationRunning { get; set; } + + public bool IsUserInteractionRunning { get; set; } + + public ObservableCollection Items { get; } private string CreateSource() { diff --git a/PanCardViewSample/PanCardViewSample/Views/CoverFlowSampleXamlView.xaml b/PanCardViewSample/PanCardViewSample/Views/CoverFlowSampleXamlView.xaml index a83374a..35d5ea6 100644 --- a/PanCardViewSample/PanCardViewSample/Views/CoverFlowSampleXamlView.xaml +++ b/PanCardViewSample/PanCardViewSample/Views/CoverFlowSampleXamlView.xaml @@ -17,6 +17,8 @@