Skip to content

TapGestureRecognizer not working on a Frame in a grid on iOS or Mac #8330

Closed

Description

@JohnHDev

Description

TapGestureRecognizer not working on a Frame in a grid.

Steps to Reproduce

Try the following code:

var frame = new Frame();
frame.GestureRecognizers.Add(new TapGestureRecognizer() { Command = new Command(() => Debug.WriteLine("dfg")) });

Add the frame to a grid, run iOS or Mac and attempt to tap/click on it.
[EDIT], It might be more complex, it needs to be in a scrollview that spans all columns in the grid and in a custom layout control. Will put together an example when I get time.
[EDIT 2] Ok, nothing to do with my custom control. A grid, containing scrollview that spans columns, containing a frame that has a tap gesture recogniser added will show the problem.

This is using VSforMac, so the .net version is 6.0.301.

Version with bug

Unknown/Other (please specify)

Last version that worked well

Unknown/Other

Affected platforms

iOS, macOS

Affected platform versions

iOS 15

Did you find any workaround?

Nope

Relevant log output

No response

Activity

  1. added
    s/needs-verification
    t/bug
    on Jun 25, 2022
  2. added
    platform/macos
    area-xaml
    legacy-area-controls
    s/needs-repro
    and removed
    s/needs-verification
    on Jun 27, 2022
  3. rachelkang commented on Jun 27, 2022

    @rachelkang
    Member

    Hi, @JohnHDev - thanks for opening this issue! Looking forward to investigating further once you share the example with us

  4. ghost added
    s/needs-attention
    on Jun 27, 2022
  5. ghost removed
    s/needs-repro
    on Jun 27, 2022
  6. JohnHDev commented on Jul 1, 2022

    @JohnHDev
    Author

    @rachelkang apologies for the delay, here you go. In the page constructor add the following code.
    You will see that the tap gesture on the frames don't work at all.
    But also, I found that setting the page content itself to a frame, the tap gesture doesn't work either. So it could be as simple as that to replicate:

                var grid = new Grid();
                grid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Star));
                grid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Star));
                grid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Star));
                grid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Star));
                grid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Star));
    
                grid.RowDefinitions.Add(new RowDefinition(GridLength.Star));
                grid.RowDefinitions.Add(new RowDefinition(GridLength.Star));
                grid.RowDefinitions.Add(new RowDefinition(GridLength.Star));
                grid.RowDefinitions.Add(new RowDefinition(GridLength.Star));
                grid.RowDefinitions.Add(new RowDefinition(GridLength.Star));
    
                var scrollView = new ScrollView()
                {
                    BackgroundColor = Colors.Blue
                };
                Grid.SetRow(scrollView, 0);
                Grid.SetColumn(scrollView, 0);
                Grid.SetColumnSpan(scrollView, 5);
                grid.Children.Add(scrollView);
    
                var frame1 = new Frame
                {
                    BackgroundColor = Colors.Red
                };
    
                frame1.GestureRecognizers.Add(new TapGestureRecognizer() { Command = new Command(() => Debug.WriteLine("frame1")) });
    
                scrollView.Content = frame1;
    
                var frame2 = new Frame
                {
                    BackgroundColor = Colors.Green
                };
                frame2.GestureRecognizers.Add(new TapGestureRecognizer() { Command = new Command(() => Debug.WriteLine("frame2")) });
                Grid.SetRow(frame2, 1);
                Grid.SetColumn(frame2, 0);
                Grid.SetColumnSpan(frame2, 5);
                grid.Children.Add(frame2);
                
                Content = grid;

    Let me know how you get on!

    Thanks
    John

  7. JohnHDev commented on Jul 1, 2022

    @JohnHDev
    Author

    Further info, swapping Frame for Border, the tap gestures work but you can't 'see' the border view.
    [EDIT] Ok to see the background of the border view you must add a StrokeShape, which covers the shape of the border and has nothing to do with the background colour. You might want to take a look at that as well.

  8. 13 remaining items

  9. mattleibow commented on Dec 13, 2022

    @mattleibow
    Member

    @PureWeen is this Frame not having gestures working when there is no child items a "feature" or "compatibility feature" of Frame? As far as I can tell, this is how Xamarin.Forms worked.

    Adding a child or switching to Border makes it work again. How do we make a call on this issue?

  10. awalker-dsg commented on Dec 13, 2022

    @awalker-dsg

    @mattleibow, re your comment, "As far as I can tell, this is how Xamarin.Forms worked." We discovered this while migrating our code from Xamarin to MAUI. The Xamarin version of our app uses Frame in this way, and it does work on iOS as well as on Android.

    Following up on your earlier comment, "Switching to a Border or a CollectionView seems to make it work again", I modified the test code from my original post to use CollectionView instead of ListView. When I ran it on an iPhone 7 with iOS 15.6.1 and an emulated iPhone 14 with iOS 16.0, the app crashed on startup. I then restored it to use ListView and the app ran as before -- i.e. the Frame ignores clicks, but the app didn't crash on startup. These tests were done using VS 17.4.2.

  11. mattleibow commented on Dec 13, 2022

    @mattleibow
    Member

    @awalker-dsg I was testing with the internal bits of 17.4.3 and maui 7.0.52. Both of these just shipped a few hours ago.

    Maybe you have a more complex CollectionView so that may still have a crash. However, you can use a Border.

    I will re-investigate this and see if I can try figure out why Xamarin.Forms worked and this does not as it is the same code...

  12. mattleibow commented on Dec 14, 2022

    @mattleibow
    Member

    Just tested on iOS with Xamarin.Forms and indeed the touches work. Now the trick is to figure out why it is not working in MAUI...

  13. awalker-dsg commented on Dec 14, 2022

    @awalker-dsg

    @mattleibow, I updated to VS 17.4.3 on my PC to see if that addressed the crash described in my previous post. That also forced me to update Xcode from 14.0.1 to 14.2 on our Mac.

    The bad news is that our test app still crashes on iOS if the ListView is replaced with a CollectionView.

    However, there is good news. Per your earlier suggestion, I changed the Frame to a Border, and now our custom button DOES respond to click events when the compound control is in a ListView.

    Also, once I discovered that setting the Border control attribute StrokeShape="RoundRectangle 10" was equivalent to the Frame control's CornerRadius="10", the resulting control looks the same as it did on Xamarin using Frame. So, Border seems to be a viable workaround for Frame for the scenario described in my original post.

    Many thanks for your help.

  14. added
    p/1
    on Dec 17, 2022
  15. moved this from In Progress to Done in MAUI SDK Ongoingon Jan 18, 2023
  16. ghost locked as resolved and limited conversation to collaborators on Feb 17, 2023
  17. added
    fixed-in-8.0.0-preview.1.7762
    on Feb 22, 2023
  18. added this to the 8.0-preview1 milestone on Feb 22, 2023
  19. added
    area-gestures
    and removed
    legacy-area-controls
    area-xaml
    on May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-controls-framearea-gesturesfixed-in-8.0.0-preview.1.7762p/1partner/cat 😻platform/iosplatform/macoss/needs-attentions/triageds/verifiedt/bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions