Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 75885

Cross platform compositional Gestures - using Xamarin's own mechanism

$
0
0

Hi guys,

please chomp on the juicy fruit of my last month's worth of toil. :)

http://blog.twintechs.com//cross-platform-compositional-gesture-advanced-xamarin-forms-techniques-for-flexible-and-performant-cross-platform-apps-part-4?hs_preview=0RXjEI_S-3195102908

As some of you know, I've been writing a series on how to really push Xamarin Forms to the limit without having to write custom renderers all over the place.

I thought the section on gesture recognizers would be a fairly simple exercise in factories and composition : but I'm iOS guy, not an Android guy. I had no idea how hard it would be to get gesture parity across iOS and Android, while adhering to my design goals:

  • No inheritence,
  • No special views,
  • Use Xamarin's system for recognizers,
  • As uobtrusive as possible.

However, I have strived hard and I've managed to adhere to that with:

  • Pan (get transform in any view, can reset it),
  • Tap (specify required number of taps and touches),
  • LongPress (specify duration),
  • Swipe,
  • Ability to easily add other gestures,
  • Ability to add gestures in superviews, and not have to worry about child views consuming them,
  • Cancel touches,
  • Delegates to choose if gesture begins,
  • Delaying touches (experimental),
  • All gestures Can report their locaiton inside any xamarin forms view,
  • More I don't recall right now

The blog post is really long and indepth, as I wanted to share the process just as much as the result. The goal here is not a product and while we are supporting and developing this, we don't advise you to use this in prod code, unless you know what you're doing. We do hope however, you are inspired to push Xamarin Forms forward in your own work using these techniques.

If you appreciate my efforts here (thousands of words of blog and thousands of lines of code, then please like this forum post (it will help others find it, and makes it easy for me to justify the investment to my boss and my wife, and maybe earn me enough good karma to outweigh my bad, so that I might one day even eaarn an MVP [i doubt that though ;)]).

Here's a teaser video of what you can do with it:

image

I'll upload a couple of links to youtube videos talking through the libraries in more depth soon (I'm too tired to write more ;) ).

@TheRealJasonSmith , @MigueldeIcaza any chance of getting some love to get hooks to know when a gesture has been added/removed from the IGestureRecgonizer collection on a view, so I can make my system 100% Xamarin forms compliant? And also - can you please give some more thought about officially supporting the mechanism I use for doing the page in page embedding (or at least getting someone to give me some pointers on how to support the couple of edge cases I have)? : That's what makes these cool kinds of app possible. pretty please :)

Edit : here's what it looks like to use:

    <Label
            Text="Tap me twice"
            x:Name="Label1"
            BackgroundColor="Olive"
            HeightRequest="90"
            TextColor="White"
            FontSize="20">

            <Label.GestureRecognizers>

                <gestures:TapGestureRecognizer
                    NumberOfTapsRequired="2"
                    OnAction="OnAction" />

            </Label.GestureRecognizers>

        </Label>

<StackLayout
        x:Name="MyStack2"
        AbsoluteLayout.LayoutBounds="0.5, 0.3, 0.5, 0.3"
        BackgroundColor="White"
        AbsoluteLayout.LayoutFlags="All">
        <StackLayout.GestureRecognizers>

            <gestures:PanGestureRecognizer
                x:Name="ListGesture"
                OnAction="OnAction" />

        </StackLayout.GestureRecognizers>

    </StackLayout>

<Label
        Text="Swipe Left, right up or down"
        x:Name="Label5"
        BackgroundColor="Olive"
        HeightRequest="100"
        TextColor="White"
        FontSize="20">

        <Label.GestureRecognizers>

            <gestures:SwipeGestureRecognizer
                Direction="Left"
                OnAction="OnAction" />

            <gestures:SwipeGestureRecognizer
                Direction="Down"
                OnAction="OnAction" />

            <gestures:SwipeGestureRecognizer
                Direction="Right"
                OnAction="OnAction" />

            <gestures:SwipeGestureRecognizer
                Direction="Up"
                OnAction="OnAction" />

        </Label.GestureRecognizers>

    </Label>

No subclassing. No special views. Just one override one method on your Android mainactivity, and while we wait for Xamarin to give us some hooks, two additional method calls (which can be deleted in the future, when we get hooks) for wiring into the system. (that's why we need IGestureRecognizer to have somethign like GestureAdded and GestureRemoved or Created/destroyed or whatever/whatever else, etc.


Viewing all articles
Browse latest Browse all 75885

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>