Let's add the CalculatePanState() method to calculate how far we have panned the image, and if it should start to affect the GUI, by following these few steps:
- Open Controls/SwiperControl.xaml.cs.
- Add the properties at the top and the CalculatePanState() method anywhere in the class, as shown in the following code block:
private const double DeadZone = 0.4d;
private const double DecisionThreshold = 0.4d;
private void CalculatePanState(double panX)
{
var halfScreenWidth = _screenWidth / 2;
var deadZoneEnd = DeadZone * halfScreenWidth;
if (Math.Abs(panX) < deadZoneEnd)
{
return;
}
var passedDeadzone = panX < 0 ? panX + deadZoneEnd : panX -
deadZoneEnd;
var decisionZoneEnd = DecisionThreshold * halfScreenWidth;
var opacity = passedDeadzone / decisionZoneEnd;
opacity = Clamp(opacity, -1, 1);
likeStackLayout.Opacity = opacity;
denyStackLayout.Opacity = -opacity;
}
We define...