If we determine that an image has panned far enough for it to exit, we want to animate it off the screen and then remove the image from the page. To do this, proceed as follows:
- Open Controls/SwiperControl.xaml.cs.
- Add the Exit() method to the class, as shown in the following code block:
private void Exit()
{
Device.BeginInvokeOnMainThread(async () =>
{
var direction = photo.TranslationX < 0 ? -1 : 1;
await photo.TranslateTo(photo.TranslationX +
(_screenWidth * direction),
photo.TranslationY, 200, Easing.CubicIn);
var parent = Parent as Layout<View>;
parent?.Children.Remove(this);
});
}
Let's break down the preceding code block to understand what the Exit() method does, as follows:
- We begin by making sure that this call is done on the UI thread, which is also known as the MainThread thread. This is because only the UI thread can do animations.
- We also need to run this...