-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Gestures are a vital part to any mobile application. We've all become very familiar with swiping, pinching, tapping, dragging, etc. to perform all our common mobile app tasks. In fact, how many of you have found yourself trying these gestures on a non-touch screen only to remember, "Blast! This doesn't have touch!" Yep, me too...
So we need to support gestures, but unfortunately the current version of Xamarin.Forms is pretty lacking in this area, only supporting taps. Thankfully, with all the extensibility it isn't too difficult to extend the platform and create support for the gestures that you need. I've been working on this recently and I've seen quite a bit of confusion around this area, so I thought I would create this project to demo one approach to tackling this problem.
First off, let me give a heap of credit to Rob Gibbens for getting me started. If you haven't already, definitely check out his post on the same topic as I am not going to repeat the code explanation, just extend upon it. Another very helpful project is SimpleCustomGestureFrame. I actually found this after I started my own implementation, but used nearly identical code and refactored mine to follow his implementation pattern. There, credit given where it's due. Thanks guys for the wonderful starting point!
Now then, my implementation is slightly different because I chose to extend a ContentView, mostly because I just wanted a basically empty area to receive and act upon swipe gestures. Obviously, you should start from whatever control will work best in your situation. I also added in support for Windows Phone. In this case I didn't see a native control being created for the ContentView (maybe I'm missing something here), so after some fiddling I decided to just inject my own native control for the gesture listener. For the majority of controls that you will be inheriting from this would not be necessary because there will already be a native control you can access. The gesture listening code would then be the same.