We need to add code in the Exit() method to raise the events we created earlier, as follows:
- Open Controls/SwiperControl.xaml.cs.
- Add the following code in bold to the Exit() method:
private void Exit()
{
Device.BeginInvokeOnMainThread(async () =>
{
var direction = photo.TranslationX < 0 ? -1 : 1;
if (direction > 0)
{
OnLike?.Invoke(this, new EventArgs());
}
if (direction < 0)
{
OnDeny?.Invoke(this, new EventArgs());
}
await photo.TranslateTo(photo.TranslationX + (_screenWidth
* direction),
photo.TranslationY, 200, Easing.CubicIn);
var parent = Parent as Layout<View>;
parent?.Children.Remove(this);
});
}
Here, we inject the code to check whether we are liking or denying an image. We then raise the correct event based on this information.