Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Tap Gesture not working on iOS [Bug] #10623

Closed
odapplications opened this issue May 8, 2020 · 22 comments · Fixed by #11419
Closed

Tap Gesture not working on iOS [Bug] #10623

odapplications opened this issue May 8, 2020 · 22 comments · Fixed by #11419
Assignees
Labels
a/gestures 🖖 e/3 🕒 3 in-progress This issue has an associated pull request that may resolve it! p/iOS 🍎 t/bug 🐛
Milestone

Comments

@odapplications
Copy link

When having a tap gesture within a frame in xaml it will work on some but not all tap gestures. When adding it to the .cs file it would work but not directly within xaml.

Description

Steps to Reproduce

Expected Behavior

Actual Behavior

Basic Information

  • Version with issue:
  • Last known good version:
  • IDE:
  • Platform Target Frameworks:
    • iOS:
    • Android:
    • UWP:
  • Android Support Library Version:
  • Nuget Packages:
  • Affected Devices:

Screenshots

Reproduction Link

Workaround

@odapplications odapplications added s/unverified New report that has yet to be verified t/bug 🐛 labels May 8, 2020
@pauldipietro pauldipietro added this to New in Triage May 8, 2020
@odapplications
Copy link
Author

Note: some ios versions work and some dont

@AdamMarciniec
Copy link

AdamMarciniec commented May 12, 2020

I'm getting this too, I have TapGestureRecognizers on grids that fail to fire and all of my ListViews won't allow a selected item to happen in iOS. Buttons still seem to work though. All this was working last week. Everything works fine in Android.
Let me know if I can send anything to help this along, our app is basically useless on ios now.

Edit. I saw the note that some versions of ios are ok. I can only confirm that 13.4 has this issue.

Edit 2: I found this issue and it sorted me out after reading the comments nearer the bottom. Thanks.

@PureWeen
Copy link
Contributor

@odapplications @AdamMarciniec

Can you attach a repro? Also make sure you're fully updating on VS

@PureWeen PureWeen moved this from New to Needs Info in Triage May 19, 2020
@PureWeen PureWeen added s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. labels May 19, 2020
@odapplications
Copy link
Author

@PureWeen I ended up fixing the issue. It does not seem to work the same ways as it used to. I think it was just a weird way I was adding the tap gesture. Now I get multiple imports of xamarin forms which I checked there is not.

I would link you to the repo... but it is private so I would have to invite you.

sNEnvY (1)

@samhouts
Copy link
Member

@odapplications Please check your csproj file for duplicates. Sometimes NuGet will install improperly on an update.

@LGFox
Copy link

LGFox commented Jun 23, 2020

I observe this issue on iOS 13.5.1
Updating VS to the latest 8.6.5 (build 23) fixes this issue.

Triage automation moved this from Needs Info to Closed Jun 26, 2020
@samhouts samhouts reopened this Jun 26, 2020
Triage automation moved this from Closed to New Jun 26, 2020
@samhouts
Copy link
Member

Oops, didn't mean to close this one without asking first! Is there still an issue here, or is it okay to close?

@samhouts samhouts moved this from New to Needs Info in Triage Jun 26, 2020
@dhindrik
Copy link
Contributor

dhindrik commented Jul 7, 2020

I still have an issue with the latest stable version of Forms. It works on Android, but not on iOS. Here is a repo that reproduces it, https://github.com/dhindrik/RatingControl

I comment away some other "work in progress code" so it will be easier to see the TapGesture problem.

@PureWeen
Copy link
Contributor

PureWeen commented Jul 8, 2020

@dhindrik do you know a specific version where this broke for you? Or have TapGesture's just never really worked for shapes?

@dhindrik
Copy link
Contributor

dhindrik commented Jul 8, 2020

If you set Rating to example 3.5 you will add the Gesture Recognizer to a Grid and it still not working. But I can investigate more. I tried to downgrade to 3.6, but then I realized that Shapes was introduced in 3.5.

@dhindrik
Copy link
Contributor

dhindrik commented Jul 8, 2020

If I replace the Shapes with a BoxView instead it is working, so it looks like Shapes are the problem, even if it is wrapped in a Grid.

@PureWeen
Copy link
Contributor

PureWeen commented Jul 8, 2020

@jsuarezruiz

@PureWeen PureWeen removed s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. labels Jul 8, 2020
@PureWeen
Copy link
Contributor

PureWeen commented Jul 8, 2020

@dhindrik do you think your issue relates to the original post here?

I'm a little lost on your version lists here

If you set Rating to example 3.5 you will add the Gesture Recognizer to a Grid and it still not working. But I can investigate more. I tried to downgrade to 3.6, but then I realized that Shapes was introduced in 3.5.

Did you mean 4.5/4.6 etc..?

@dhindrik
Copy link
Contributor

dhindrik commented Jul 8, 2020

4.6 and 4.7. 3.5 was if you set the Rating value to 3.5 to get a half star.

@jsuarezruiz jsuarezruiz moved this from New to Ready For Work in Triage Jul 13, 2020
@samhouts samhouts added this to To do in iOS Ready For Work Jul 13, 2020
@samhouts samhouts removed this from Ready For Work in Triage Jul 13, 2020
@samhouts samhouts added the in-progress This issue has an associated pull request that may resolve it! label Jul 13, 2020
@samhouts samhouts added this to In Progress in 4.7.0 Jul 13, 2020
@samhouts samhouts moved this from To do to In progress in iOS Ready For Work Jul 13, 2020
@samhouts samhouts removed this from In Progress in 4.7.0 Jul 28, 2020
@samhouts samhouts added this to In Progress in vCurrent (4.8.0) Jul 30, 2020
@samhouts samhouts removed this from In Progress in vCurrent (4.8.0) Aug 4, 2020
@samhouts samhouts added this to In Progress in vNext+1 (5.0.0) Aug 11, 2020
@samhouts samhouts added this to the 5.0.0 milestone Aug 13, 2020
@ccsousa01
Copy link

TapGestureRecognizer within a frame, which is the parent view inside a <CollectionView> <CollectionView.ItemTemplate> <DataTemplate> still does not trigger from iOS (Xamarin Forms v.4.8). Works fine in Android.

@DellaMoraWalter
Copy link

I confirm that shape objects are involved in this problem.
In my case I have a StackLayout with inside a Label and a Shape created through a Path.
A TapGestureRecognizer is attached to the StackLayout which has the task of executing a command.
Basically it's a button whose image is rendered from a shape and not from a png.
By tapping on the label the command is executed but not by tapping on the Shape.

Tested with iOS 11.1 and ios 13.6.
Xamarin.Forms v 4.8.0.1364
UWP and Android seem to work fine.

@frankzielen
Copy link

frankzielen commented Oct 8, 2020

I face the same issue as @DellaMoraWalter and @dhindrik. TapGestureRecognizer does not work for shapes on iOS. I have added it to Path, Polygone and Polyline objects - none did it, neither in a StackLayout nor in a Grid. Wrapping the shape in a Frame works but only if I tap on the area outside the shape. That's not what I want so it's not an appropriate workaround. Wrapping in a ContentView shows no effect.

I have tested on iOS 13.5 and 14.0, XF is 4.8.0.1451.

I am awaiting a fix or workaround! Thx in advance.

@jgold6
Copy link
Contributor

jgold6 commented Oct 19, 2020

@frankzielen

When the Shape is in another element, the SHape is still on top and still gets the tap from the user, so you have to pass the tap down to the wrapping container, whether a Frame or ContentView

If you set the InputTransparent property on the Shape to true then the Tapped event will fire from the View (whatever subtype) that is wrapping the Shape. E.g.:

        var tgr = new TapGestureRecognizer();
        tgr.Tapped += async (s, e) => {
            await DisplayAlert("Info", "Tapped", "OK");
        };

        Polygon triangle = new Polygon
        {
            Points = new PointCollection(),
            Fill = Brush.Blue,
        };
        triangle.Points.Add(new Point(0, 0));
        triangle.Points.Add(new Point(100, 0));
        triangle.Points.Add(new Point(50, 50));
        triangle.InputTransparent = true;  // <------------------------set InputTransparent to True

        var frame= new Frame(); 
        frame.Content = triangle; // <--------------------- add to Frame
     
        frame.GestureRecognizers.Add(tgr); // <-----------TapGestureRecognizer on Frame

        Content = new StackLayout
        {
            Children = { frame }, // <------------------------ add Frame to view heirarchy
            HorizontalOptions = LayoutOptions.Center,
            VerticalOptions = LayoutOptions.Center
        };

@frankzielen
Copy link

Thx @jgold6! The InputTransparent property was the missing link to make wrapping in a Frame or ContentView work. However, the workaround is still not perfect (for my application) because Frame and ContentView have rectangular shapes. E.g. for the triangle I can now tap on the area outside the triangle but inside the wrapping object to fire the event. Is there a possibility to wrap seamlessly around the shape?

@jgold6
Copy link
Contributor

jgold6 commented Oct 20, 2020

@frankzielen

If you need to only have the tap work when the actual triangle is being tapped, then you will need to do that in platform specific renderers and use the iOS/Android/UWP SDK APIs to do hit tests.

Since a Xamarin.Forms Shape is a View, and a View is rectangular, adding a TapGestureRecognizer to a Shape will trigger the Tap for the View box, not for the shape inside of it. This is what happens on Android when the Shape is not wrapped in a Frame, etc.

There is a discussion of getting the tap coordinates in Xamarin.Forms on the Xamarin Forums: https://forums.xamarin.com/discussion/17767/touch-coordinates-in-tapgesturerecognizer

Docs on handling touch events in Xamarin.iOS: https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/touch/
Docs on handling touch events in Xamarin.Android: https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/touch/touch-in-android
Docs on handling touch events in UWP: https://docs.microsoft.com/en-us/windows/uwp/design/input/touch-interactions

Alternately you could use SkiaSharp for your shapes: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/graphics/skiasharp/transforms/touch

And there is a paid plugin, noted in the Xamarin Forums discussion linked above (I can't vouch for it) that claims to enable determining where the touch occurred: https://www.mrgestures.com/

@samhouts samhouts removed this from the 5.0.0 milestone Nov 2, 2020
@PureWeen PureWeen added this to the 5.0.0 milestone Nov 5, 2020
@mduchev
Copy link

mduchev commented Nov 26, 2020

I'm having the same issue with a shape. The workaround with the InputTransparent seems to do the trick for me until the issue is fixed.

iOS Ready For Work automation moved this from In progress to Done Dec 4, 2020
vNext+1 (5.0.0) automation moved this from In Progress to Done Dec 4, 2020
rmarinho added a commit that referenced this issue Dec 4, 2020
…ixes #13020

* Added repro sample

* Fixed the issue

* Update Issue11050.xaml.cs

* Updated issue 10626. Replaced Color by Brush.

* Fixed build error

* Fixed build error

* Added Issue12685 test

* Changes in text format

* Fix rebase error

Co-authored-by: Samantha Houts <samhouts@users.noreply.github.com>
Co-authored-by: E.Z. Hart <hartez@gmail.com>
Co-authored-by: Rui Marinho <me@ruimarinho.net>
pictos pushed a commit to pictos/Xamarin.Forms that referenced this issue Dec 30, 2020
…ixes xamarin#12685 fixes xamarin#13020

* Added repro sample

* Fixed the issue

* Update Issue11050.xaml.cs

* Updated issue 10626. Replaced Color by Brush.

* Fixed build error

* Fixed build error

* Added Issue12685 test

* Changes in text format

* Fix rebase error

Co-authored-by: Samantha Houts <samhouts@users.noreply.github.com>
Co-authored-by: E.Z. Hart <hartez@gmail.com>
Co-authored-by: Rui Marinho <me@ruimarinho.net>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/gestures 🖖 e/3 🕒 3 in-progress This issue has an associated pull request that may resolve it! p/iOS 🍎 t/bug 🐛
Projects
Development

Successfully merging a pull request may close this issue.