Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hightlight, when swipe ends. Or just catch event when swipe ends #3588

Closed
mister-giga opened this issue Jul 28, 2018 · 1 comment
Closed

Comments

@mister-giga
Copy link

What did you do?

I added custom gesture recognizer,. I did override the TouchesEnded method.

What did you expect to happen?

TouchesEnded to be fired after I finished swiping finger on the chart (with highlighting enabled)

What happened instead?

TouchesEnded was never called after swiping end, only if it was a tap. I suppose it shall happen after swiping as well, since there are no other methods to override for swipe ending.

Charts Environment

I am on master, latest.
latest
latest
iOS
latest

@mister-giga
Copy link
Author

After a funny journey on the github and stackoverflow I got answer to my question.
I found that BarLineChartViewBase adds NSUIPanGestureRecognizer, and after adding mine as well, made it not to draw the highlighter so I had to call the func of BarLineChartViewBase named panGestureRecognized but it was not public. And I am on Xamarin.iOS I had to do some reflection for objective C and c# and here is the code

        var list = Control.GestureRecognizers.ToList();
        var old = list.First(x => x is UIPanGestureRecognizer);
        list.Remove(old);
        var our = (new UIPanGestureRecognizer(uIPanGestureRecognizer =>
        {
            ObjCRuntime.Selector selector = new ObjCRuntime.Selector("panGestureRecognized:");
            var theStaticClassType = typeof(UIView).Assembly.GetType("ObjCRuntime.Messaging");
            MethodInfo staticMethodInfo = theStaticClassType.GetMethod("void_objc_msgSend_IntPtr");
            staticMethodInfo.Invoke(this, new object[] { Control.Handle, selector.Handle, uIPanGestureRecognizer.Handle });

            if (uIPanGestureRecognizer.State == UIGestureRecognizerState.Ended)
            {
                 //code that happens when swipe ends
            }
        }));
        list.Add(our);

        Control.GestureRecognizers = list.ToArray();

Where Control is LineChartView. I used this in custom renderer for Xamarin.Forms and it works fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant