MR.Gestures handles ALL touch gestures

1468910

Posts

  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

    Well, an official collection has to come from Xamarin.
    I'm glad I can do it like it is now with the existing events.

  • BastiBrauningBastiBrauning USMember

    Thanks alot for 1.3.2. Fixed my issues!

  • MarkoLudolphMarkoLudolph DEMember ✭✭

    Hi,

    for some reason, the gestures do not work on UWP, when you compile the app with the Native Tool Chain. On my Lumia 550 (or the Emulator), the gestures work in Debug mode, but not in Release mode. Is this a known problem?

  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

    @MarkoLudolph I didn't try myself, but it seems like these troubleshooting guidelines could help.

  • MarkoLudolphMarkoLudolph DEMember ✭✭

    That didn't help. And I'm using the gestures in code-behind, so this shouldn't be an issue in this case.

  • MarkoLudolphMarkoLudolph DEMember ✭✭

    @MichaelRumpler Will you look at the issue? Actually, it is possible to debug the code in the Emulator, even when the Native Tool Chain is activated.

    I had to rewrite some parts of my app too to make it work. There was problem, that some streams where already exposed, when I wanted to use them, which does not happen with iOS/Android. It seems that the memory managment is more agressive.

  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

    @MarkoLudolph Yes, I'm just fighting with something different currently.

  • MarkoLudolphMarkoLudolph DEMember ✭✭

    @MichaelRumpler Great, thanks.

  • AndrewDitmerAndrewDitmer USXamarin Team Xamurai

    @CodyRousseau said:
    @MichaelRumpler Hello! I am using the siwpe feature of MR.Gestures, but it picks up every swipe Direction as "Not Clear". Is it just really sensitive? Do you think it is the phone's issue? Thanks!

    I am also seeing this issue on Android only. I have verified that the LicenseKey matches the app name (I am using the sample app credentials while I verify the functionality). I tried forcing the app name to be wrong and it threw an exception on launch so I know that's not the issue.

    The swipe gestures come through just fine on iOS, but Android is NotClear on everything. I tested on both an Emulator and physical device. Here is my MainActivity. Am I doing any of the setup wrong?

    [Activity (Label = "GestureSample", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
        public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
        {
            protected override void OnCreate (Bundle bundle)
            {
                base.OnCreate (bundle);
    
                global::Xamarin.Forms.Forms.Init (this, bundle);
                MR.Gestures.Android.Settings.LicenseKey = "ALZ9-BPVU-XQ35-CEBG-5ZRR-URJQ-ED5U-TSY8-6THP-3GVU-JW8Z-RZGE-CQW6";
                MR.Gestures.Android.Settings.SwipeVelocityThreshold = (float) .01;
                LoadApplication (new App ());
            }
        }
    
  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

    @AndrewDitmer If you set the SwipeVelocityThreshold to such a small value, then almost every pan is recognized as swipe. When the velocity in both X and Y is big enough to count as a swipe, then the Direction will be NotClear. Just leave that property at its default value of 0.1. That should work in most cases. I just made that public so that you can adjust it on any devices, which have a weird ScaledMaximumFlingVelocity.

    If you need to check the direction more detailed, then you can also handle Panning. In the PanEventArgs you have a DeltaDistance and Velocity which you can both use to check the detailed direction of the move.

  • AndrewDitmerAndrewDitmer USXamarin Team Xamurai

    @MichaelRumpler that was it! I had set the velocity lower because the swipe wasn't firing as often as I wanted. I set it to .07 now. I'm trying to auto hide the Navigation Bar when scrolling a ListView (in Xamarin.Forms, of course). Your Swiped event on the ListView works like a charm:

    lst.Swiped += (object sender, SwipeEventArgs e) => { //Scroll down if(e.Direction == MR.Gestures.Direction.Up) { NavigationPage.SetHasNavigationBar(this, false); } //Scroll up if(e.Direction == MR.Gestures.Direction.Down) { NavigationPage.SetHasNavigationBar(this, true); } };

  • SquallLeonhart.1032SquallLeonhart.1032 USMember ✭✭
    edited March 2016

    Hello @MichaelRumpler
    Can you help me with this bug.
    This is my project repository https://github.com/Knight1988/Xamarin.Form.MultiLevelListView

    I was test it on genymotion, ASUS_Z008D.
    The bug:

    • Run project
    • tap Mr.Gestures.MultiLevelListView button
    • tap "Root 0"
    • tap "Child 0-0"
    • tap "Child 0-1"
    • tap "Child 0-2"
    • tap "Child 0-0"
    • tap "Child 0-1" -> Tapping event not fire anymore.
    • tap "Child 0-2" -> Tapping event not fire anymore.
    • tap "Child 0-0" -> Tapping event still working.
  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

    @MarkoLudolph said:
    for some reason, the gestures do not work on UWP, when you compile the app with the Native Tool Chain. On my Lumia 550 (or the Emulator), the gestures work in Debug mode, but not in Release mode. Is this a known problem?

    Sorry, first I had to release a new version of my app and then I forgot.

    I tested it now with the GestureSample. It was really not working with a release build. But as I said earlier, Xamarins troubleshooting guidelines help. I added this code to App.xaml.cs:

    var otherAssemblies = new[] {
        typeof(MR.Gestures.ContentPage).GetTypeInfo().Assembly,
        typeof(MR.Gestures.UWP.Renderers.PageRenderer).GetTypeInfo().Assembly,
    };
    Xamarin.Forms.Forms.Init(e, otherAssemblies);
    

    Now the gestures also work in release builds.

  • MarkoLudolphMarkoLudolph DEMember ✭✭

    @MichaelRumpler Thanks for looking at it. I forgot to add the UWP Assembly too, stupid me :neutral:

  • DirkWilhelmDirkWilhelm USMember ✭✭✭
    edited March 2016

    I think there is an error in your compatibility documentation. For ScrollView and TableView it says that all events are supported in UWP, but pan and swipe doesn't work, so i guess the same restrictions as with WinPhone 8.1 regarding Direct Manipulation still apply to UWP?

  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

    @DirkWilhelm Yes, I only tested UWP on my LocalMachine with the mouse. In the Simulator in touch mode it still has the same problems like WinRT. I updated the web documentation.

    @SquallLeonhart.1032 I downloaded and tested your app and can reproduce your problems. However, it is a bit too complicated to debug such a big app. I cannot debug all your apps. That simply never pays back. Sorry.

  • rockyrocky CNMember

    @MichaelRumpler if I used my custom control,how to use your MR.Gestures.
    for example,I design a contentview as a custom control:



    <Grid.RowDefinitions>


    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>

    </Grid.ColumnDefinitions>




    and I used in my contentpage:


    how to fire the tapped event?

  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

    @rocky Just inherit from MR.Gestures.ContentView instead of Xamarin.Forms.ContentView.

  • rockyrocky CNMember

    @MichaelRumpler Because my code doesn't show in correctly.I post again here:
    the contentview:







    the used page:

    ......


    My question is : where is the right place that the MR.Gestures.ContentView should be?

  • rockyrocky CNMember

    ``

    ......


    ``

  • rockyrocky CNMember

    @MichaelRumpler
    why I can't post my code?
    I place it in my file ,please see the attachment.

  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

    @rocky

    This instantiates a Xamarin.Forms.ContentView:

    <ContentView xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    

    and this a MR.Gestures.ContentView:

    <mr:ContentView xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:mr="clr-namespace:MR.Gestures;assembly=MR.Gestures"
    

    Download the GestureSample. This includes all the samples you'll ever need.

    If you want to paste multiple lines of code in this forum, then you need to put a blank line before and after it and indent each line with at least four spaces or a tab.
    If the code is shorter, then you can also select it and press ctrl-O (or click the C icon above).

  • TomasWinstonTomasWinston IEMember ✭✭

    Hi.
    I recently purchased a license for Mr.Gestures and find it great. Admittedly I am just starting implementing it but I have hit a difficulty. I am using the ListView and am binding a command to the SwipedCommand property of a ViewCell. This is great and works and I can capture the direction of the swipe in my ViewModel. However, I would like to pass a parameter to the SwipeCommand handler. When I set the SwipedCommandParameter I am getting an invalid cast exception (presumably because its trying to cast my command parameter value to a SwipeEventArgs which is a parameter I have on my handler to get the direction of the swipe??).

    So, my question - is it possible to pass a CommandParameter of my choosing and still get the Direction of the swipe?

    <mr:ListView Opacity="0.85" x:Name="myList" SeparatorColor="#999999" Grid.Row="1" RowHeight="70" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" ItemsSource="{Binding MyItems}" HasUnevenRows="true" IsPullToRefreshEnabled="True"
                    RefreshCommand="{Binding LoadCommand}" IsRefreshing="{Binding IsLoading, Mode=OneWay}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <mr:ViewCell x:Name="viewCell" SwipedCommandParameter="{Binding }" SwipedCommand="{Binding Path=BindingContext.SwipedCommand, Source={mext:ElementSource myList}}">
                <Label Text="{Binding ItemName}" />
            </mr:ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
    </mr:ListView>
    

    The following is an extract from my ViewModel:

    public MyViewModel
    {
        SwipedCommand = new Command<SwipeEventArgs>(OnSwiped);
    }
    
    public ICommand SwipedCommand { get; set; }
    private void OnSwiped(SwipeEventArgs e)
    {
        if (e.Direction == MR.Gestures.Direction.Right)
        {
                //Do something with binding of swiped object
        }
        else if (e.Direction == MR.Gestures.Direction.Left)
        {
                //Do something with binding of swiped object
        }
    }
    
  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

    @TomasWinston

    The SwipeEventArgs (and all the other gesture EventArgs) have a Sender property which is set to the control on which the event happened. The MR.Gestures.ViewCell in this case.
    In your case, if you need SwipedCommandParameter="{Binding }", then you can do this in your OnSwiped method:

    var data = ((ViewCell)e.Sender).BindingContext;
    

    If you need additional data, then you can use your own ViewCell which inherits from MR.Gestures.ViewCell and add any data you want to it.

  • TomasWinstonTomasWinston IEMember ✭✭

    Perfect. Thanks Michael!

  • TonyDTonyD USMember ✭✭✭

    Hi @MichaelRumpler

    I've been getting this on my app in production. It happens very few times (it happened around 8 times out of the last 20,000 sessions) but it crashes the app. Any ideas?

    System.NullReferenceExceptionObject reference not set to an instance of an object

    Xamarin.Forms.BindableObject.GetValue(BindableProperty property)
    MR.Gestures.AbsoluteLayout.get_TappedCommandParameter()
    MR.Gestures.GestureHandler.OnTapped(TapEventArgs args)
    MR.Gestures.GestureThrottler.OnTapped(TapEventArgs args)
    at MR.Gestures.iOS.iOSGestureHandler+<>c__DisplayClass24_0+<b__0>d.MoveNext () <0x1011a754c + 0x001c3> in :0

  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

    @AntoineElDaher said:
    System.NullReferenceExceptionObject reference not set to an instance of an object
    Xamarin.Forms.BindableObject.GetValue(BindableProperty property)
    MR.Gestures.AbsoluteLayout.get_TappedCommandParameter()

    I never saw this before. I'd need a repro to check this, but that will be difficult if it only happens every few thousand times. It may also be a XF issue. There should not be a problem when I read the TappedCommandParameter.

  • TonyDTonyD USMember ✭✭✭

    @MichaelRumpler Thanks - is there some wait I can try/catch it externally? I can send you the code section (it's pretty simple) but it's very hard to repro.

  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

    No. I only read the TappedCommandParameter when I try to execute the command and this happens somewhere in the native event handler. You cannot catch that.

  • TonyDTonyD USMember ✭✭✭
    edited April 2016

    @MichaelRumpler - OK, then maybe you can catch it (or check for NULL) ?

    Here is the code FYI:

    viewLayout.Tapped += (object sender, MR.Gestures.TapEventArgs e) => {
                        try {
                            viewLayout.Opacity = 0.6;
                            viewLayout.FadeTo (1);
                            if (OnClickProfile != null) {
                                OnClickProfile.Execute (m.UserName);
                            }
                        } catch (Exception ex) {
                            App.Report (ex);
                        }
                    };
    

    The app still crashes (.Tapped is not even invoked).

  • DanielKramerDanielKramer USMember
    edited April 2016

    Hello, I'm new to Xamarin, C# and Mr.Gestures.. I'm trying to reproduce my iOS game using Forms. I'm trying a simple test with Mr.Gestures, drag a boxView around a screen. Works great on iOS but the panning gesture doesn't seem to work on Android. There's not much code to it, just playing around.

    In my Content:

                box1 =  new Tile();
                box1.TranslationX = 100;
                box1.TranslationY = 100;
    
                MR.Gestures.AbsoluteLayout ab = new MR.Gestures.AbsoluteLayout ();
                ab.Children.Add (box1);
    
                ab.Panning +=  (object sender, MR.Gestures.PanEventArgs e) => {
                    BackgroundColor = Color.Green;
                    box1.TranslationX += e.DeltaDistance.X;
                    box1.TranslationY += e.DeltaDistance.Y;
    
                    Console.WriteLine("delta: " +  e.DeltaDistance.X);
                };
    
                Content = ab;
    

    The background does turn green, so the panEvent is happening. In the console I only see one "delta" message of 0.. so thinking maybe it's only called once rather then continuously as I attempt to drag the box around? Thanks for any pointers

    Daniel

  • DanielKramerDanielKramer USMember

    Ah.. rookie move. Thanks Michael, it's working now.

  • MarkoLudolphMarkoLudolph DEMember ✭✭

    @MichaelRumpler Could you please send me or provide on nuget a version that is compiled against 2.2-pre4 on Android? I want to release a new version of my app, but it's not possible due the Android Support Library mismatch.

  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

    @MarkoLudolph

    Are you sure that the problems are caused by MR.Gestures? I tested it with the GestureSample and that works without problems with XF 2.2.0.4. I don't use any Android resources, so it shouldn't be a problem.
    Usually you can see which component causes the errors in Resources.designer.cs. Just double click the error messages and see in which lines the errors are.

  • MarkoLudolphMarkoLudolph DEMember ✭✭

    Well, it was a nuget error. When I updated to the latest XF, I removed all external packages. Now I wanted to add them back, but nuget complained about the version mismatch.
    I simply added both dlls manually from the packages folder to the project and it's compiling and working again. Sorry for the false alarm.

  • JimmiBendtsonJimmiBendtson USMember ✭✭

    LongPressing event is not firing on Android when running in "Visual Studio Emulator for Android" emulator. It works fine in both Windows Phone and iPhone emulator and real Windows Phone and iPhone devices.

    Currently I do not have an Android device so I can not test on a real Android device.

    Is this a known problem when running in the "Visual Studio Emulator for Android" emulator?

    Thanks
    Jimmi

  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

    @JimmiBendtson
    I have some problems with Hyper-V on my dev VM. So unfortunately I never got the VS Android emulator running. I always test MR.Gestures on real devices. That's also easier for multi finger gestures. These cannot be tested easily with the mouse.
    I have to play more with the VS Android emulator and get it running, but right now I cannot tell you why it doesn't work there.

  • TonyDTonyD USMember ✭✭✭

    Hi @MichaelRumpler

    Any thought on when you can get a fix in for this?

    System.NullReferenceExceptionObject reference not set to an instance of an object
    Xamarin.Forms.BindableObject.GetValue(BindableProperty property)
    MR.Gestures.AbsoluteLayout.get_TappedCommandParameter()

  • DanielKramerDanielKramer USMember

    So far Mr.Gestures is working great for me, thanks for this lib. I'm still wrapping my head around C#, gestures etc.. Right now I have a game board and can move tiles around with panning, that's working well. My game board is a MR.Gestures.AbsoluteLayout and that's where I capture the panning gesture. If I add that game board as a child to another MR.Gestures.AbsoluteLayout then it seems the gestures are blocked by the parent and it no longer works. Is there a way to pass gestures though to children or ignore gestures on a parent in some way?

Sign In or Register to comment.