I am trying to create Xamarin Forms cross-platform switch control of my own that can be switched from on and off. I want it to use pan gestures to move the switch and also tap gestures to hit off and on labels.
Here is a picture of my control to provide a bit more context:
Here is my code for the gesture setup (I think the XAML is irrelevant):
public CustomSlider()
{
SizeChanged += OnSizeChanged;
_panGesture.PanUpdated += OnPanGestureUpdated;
_gestureListener = new StackLayout { Orientation = StackOrientation.Horizontal };
_gestureListener.GestureRecognizers.Add(_panGesture);
_leftTapGesture.Tapped += LeftTapped;
_rightTapGesture.Tapped += RightTapped;
var leftBox = new BoxView { HorizontalOptions = LayoutOptions.FillAndExpand, };
var rightBox = new BoxView { HorizontalOptions = LayoutOptions.FillAndExpand, };
leftBox.GestureRecognizers.Add(_leftTapGesture);
rightBox.GestureRecognizers.Add(_rightTapGesture);
_gestureListener.Children.Add(leftBox);
_gestureListener.Children.Add(rightBox);
}
This works well on iOS. I am able to swipe swipe my button like a switch but also tap the value I want to make it toggle explicitly. It has a great look and feel.
On Android, however, only the tap events work. The pan gesture recognizer seems to be blocked by the tap gesture recognizers. I need 2 separate views for these as Xamarin doesn't offer any touch coordinates with tap gesture recognizers (and I don't want to resort to Mr. Gestures just yet!).
Interestingly, if I pan right in the center of the control, I assume the pan gesture directly effects the parent and I am able to pan the toggle as intended. And weirdly, the control starts to work at that point as it should! Is some sort of variable getting set here that allows pan gesture pass through?
I am looking for a cross-platform solution as I have neatly been able to do this without the use of custom renderers up to now. Does anyone know how I can achieve the desired effect?