Skip to content

Commit

Permalink
fixes #394
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiMisiukevich committed Jul 1, 2021
1 parent 794bef2 commit 33cd68f
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions PanCardView/CardsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ protected virtual void SetAllViews(bool shouldCleanUnprocessingChildren)
}
else
{
Processor?.Clean(this, new ProcessorItem { Views = oldAllViews.Where(view => !CheckIsProcessingView(view)) });
Processor.Clean(this, new ProcessorItem { Views = oldAllViews.Where(view => !CheckIsProcessingView(view)) });
}
}
}
Expand Down Expand Up @@ -929,7 +929,7 @@ protected virtual async Task<bool> TryAutoNavigate()
await Task.Delay(5);
_currentBackAnimationDirection = realDirection;

await (Processor?.Navigate(this, GetAnimationProcessorItems()) ?? Task.FromResult(true));
await InvokeOnMainThreadIfNeededAsync(() => Processor.Navigate(this, GetAnimationProcessorItems()));
PerformUWPFrontViewProcessorHandlePanChanged(0, realDirection);
EndAutoNavigation(views, animationId, animationDirection);
return true;
Expand Down Expand Up @@ -978,7 +978,7 @@ protected override void OnSizeAllocated(double width, double height)
prevAnimationDirection = AnimationDirection.Next;
nextAnimationDirection = AnimationDirection.Prev;
}
Processor?.Init(this,
Processor.Init(this,
new ProcessorItem { IsFront = true, Views = Enumerable.Repeat(CurrentView, 1) },
new ProcessorItem { Views = PrevViews, Direction = prevAnimationDirection },
new ProcessorItem { Views = NextViews, Direction = nextAnimationDirection });
Expand Down Expand Up @@ -1007,7 +1007,7 @@ protected override void OnPropertyChanged([CallerMemberName] string propertyName
return;
}
AdjustSlideShow(true);
Processor?.Clean(this, new ProcessorItem { Views = GetNextPrevCurrentViews() });
Processor.Clean(this, new ProcessorItem { Views = GetNextPrevCurrentViews() });
return;
}
}
Expand Down Expand Up @@ -1256,7 +1256,7 @@ private void OnTouchChanged(double diff, double oppositeDirectionDiff, bool isTo
try
{
BatchBegin();
Processor?.Change(this, diff, GetAnimationProcessorItems());
Processor.Change(this, diff, GetAnimationProcessorItems());
}
finally
{
Expand Down Expand Up @@ -1321,12 +1321,12 @@ private async void OnTouchEnded()

SelectedIndex = index;

endingTask = Processor?.Proceed(this, GetAnimationProcessorItems()) ?? Task.FromResult(true);
endingTask = Processor.Proceed(this, GetAnimationProcessorItems());
}
else
{
endingTask = interactionItem.IsInvolved
? Processor?.Reset(this, GetAnimationProcessorItems()) ?? Task.FromResult(true)
? Processor.Reset(this, GetAnimationProcessorItems())
: Task.FromResult(true);
}

Expand Down Expand Up @@ -1604,7 +1604,7 @@ private IEnumerable<View> InitViews(bool isFront, AnimationDirection animationDi
return Enumerable.Empty<View>();
}

Processor?.Init(this, new ProcessorItem { IsFront = isFront, Views = views, Direction = animationDirection });
Processor.Init(this, new ProcessorItem { IsFront = isFront, Views = views, Direction = animationDirection });

SetupLayout(views);

Expand Down Expand Up @@ -1681,7 +1681,7 @@ private View CreateRetrieveView(object context, DataTemplate template, IEnumerab
var duplicatedViews = notUsingViews
.Except(Enumerable.Repeat(view, 1))
.Where(v => Equals(GetItem(v), GetItem(view)));
Processor?.Clean(this, new ProcessorItem { Views = duplicatedViews });
Processor.Clean(this, new ProcessorItem { Views = duplicatedViews });
}

return view;
Expand Down Expand Up @@ -1780,7 +1780,7 @@ private void CleanView(View view)
view.BindingContext = null;
}
view.Behaviors.Remove(_contextAssignedBehavior);
Processor?.Clean(this, new ProcessorItem { Views = Enumerable.Repeat(view, 1) });
Processor.Clean(this, new ProcessorItem { Views = Enumerable.Repeat(view, 1) });
}

private void SetItemsSource(IEnumerable oldCollection)
Expand Down Expand Up @@ -1968,6 +1968,11 @@ private void InvokeOnMainThreadIfNeeded(Action action)
Device.BeginInvokeOnMainThread(action);
}

private Task InvokeOnMainThreadIfNeededAsync(Func<Task> action)
=> !Device.IsInvokeRequired
? action.Invoke()
: Device.InvokeOnMainThreadAsync(action);

private void ExecutePreventException(Action action)
{
try
Expand Down Expand Up @@ -1999,7 +2004,7 @@ private void PerformUWPFrontViewProcessorHandlePanChanged(double value, Animatio
{
return;
}
Processor?.Change(this, value,
Processor.Change(this, value,
new ProcessorItem
{
IsFront = true,
Expand Down

0 comments on commit 33cd68f

Please sign in to comment.