MichaelRumpler / GestureSample

Sample App for MR.Gestures
MIT License
58 stars 17 forks source link

[2.1.0] iOS button in MR.Gestures.ContentView doesn't raise events #9

Closed SangI762 closed 2 years ago

SangI762 commented 5 years ago

I have my custom button in MR.Gestures.ContentView which has those events in iOS button renderer:

public class GenericButtonRenderer : ButtonRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
        {
            base.OnElementChanged(e);
            GenericButton button = (GenericButton)e.NewElement;

            Control.TouchDown += delegate
            {
                button.TouchDown();
            };

            Control.TouchUpInside += delegate
            {
                button.TouchUp();
            };

            Control.TouchUpOutside += delegate
            {
                button.TouchUpOutside();
            };

            Control.TouchCancel += delegate
            {
                button.IsTouchDown = false;
            };
        }
    }

With 2.1.0 only TouchDown is raised. Reverted to 2.0.0 is raised TouchDown and TouchUpInside as expected. So my button just stop working. MR.Gestures.ContentView subscribes: Panning, Panned, DoubleTapped events. Any thoughts?

MichaelRumpler commented 5 years ago

The UIButton on iOS already consumes some events so that not everything works in MR.Gestures. See https://www.mrgestures.com/#Compatibility

Now iOS handles touch gestures for the UIButton, Xamarin handles it for the Click event, MR.Gestures adds some UIGestureRecognizers and you add some Touch* events. This is too much.

Please use a MR.Gestures.Button with the MR.Gestures events instead. It may also help to replace the XF.Button with a MR.Gestures.Label (or any other control) so that the underlying UIButton is removed.

SangI762 commented 5 years ago

Yes, you're right, but it doesn't explain why 2.0.0 works with that and 2.1.0 don't. I'm interesting what was changed in MR.Gestures.ContentView.

Also, can I disable MR double tap events somehow? Because MR TappedCommand start is slower than XF element with TapGestureRecognizer.

MichaelRumpler commented 5 years ago

In 2.1.0 I fixed the bug that the PanEventArgs are empty when Panning is first raised although the finger has already been moved. For this I needed to add my custom DownUpGestureRecognizer not only for handling Down and Up, but also if Panning or Panned is handled.

All other changes are not related to how gestures are detected on iOS.

You can disable double tap events by unsubscribing from the event.

TheCaveOfWonders commented 5 years ago

Does this mean we cannot use custom buttons for iOS?

SangI762 commented 5 years ago

Looks like. I reverted to 2.0.0. I don’t want rewrite my custom button which is used for entire app. Our app has 100+ k users and everything works as expected. But new version has breaking changes :(

MichaelRumpler commented 5 years ago

Does this mean we cannot use custom buttons for iOS?

Of course you can. Just use the MR.Gestures event handlers and not the iOS ones. MR.Gestures was made to abstract away the gesture handling so that you don't need to know how that is done on each and every platform. The goal is that you don't need a custom renderer at all just for gesture handling.

I don't know why the iOS controls behave differently when you add a UIGestureRecognizer to them. But if what you say is true, then this is the only explanation I have. This seems to be an unexpected side effect in iOS. I cannot change it.

If you know another way to get the starting position of a touch from a UIPanGestureRecognizer, then I could remove the additional UIGestureRecognizer I needed to add for that. But I don't know if that's possible.