ChartsOrg / Charts

Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart.
Apache License 2.0
27.63k stars 6.01k forks source link

gesture recognizers should be open and exclusive #3876

Open dbquarrel opened 5 years ago

dbquarrel commented 5 years ago

What did you do?

Tried to use double taps on the chart do do some custom work.

What did you expect to happen?

The BarLineChartViewBase is running a private single and double tap gesture recognizer. Double tap is locked exclusively into zoom. Single tap is locked to selecting data points and highlighting them.

I expect:

  1. double tap and single tap should work concurrently
  2. to be able to install my own double tap gesture recognizer or others that run concurrently with what the views are running
  3. that the view does not create gesture recognizers (resources) it is not going to use in a constrained environment

What happened instead?

  1. when double tap to zoom and tap to highlight are both turned on, double tapping is blocked ... this is because the gesture recognizers are not being told how to fail over. Double tap needs to have priority over single tap. See this reference code:

https://developer.apple.com/documentation/uikit/touches_presses_and_gestures/coordinating_multiple_gesture_recognizers/preferring_one_gesture_over_another?language=objc

If you don't give double tap priority, then the result is what it does right now which is to block out all double tap functionality.

  1. the double tap gesture recognizer is being created and hooked up but disabled when it's not in use, this is bad programming, it should not be created unless the user says they want double tap to zoom. In which case it should be created and then given priority over the single tap. If the user turns it off the gesture recognizer should be unhooked and destroyed.

  2. because these gesture recognizers are private, it's not possible for a user of the kit to fix their behavior... furthermore it is entirely conceivable that a user may want to add their own gestures, and because these recognizers are private it means that anything the user installs to the view will compete and conflict with the builtin ones with bad results. These need to be opened up so that a user of the kit can coordinate their behavior with additional installed gesture recognizers.

This can be worked around by forcibly listing the view's gesture recognizers and removing/coordinating them, but that is definitely not a preferred solution vs. being able to access them in subclasses or in user code.

liuxuan30 commented 5 years ago

double tap and single tap should work concurrently

I don't see why they are not working simultaneously right now. they are separate gestures.

to be able to install my own double tap gesture recognizer or others that run concurrently with what the views are running

You can. Just subclass the chart view and provide your own gesture handlers.

that the view does not create gesture recognizers (resources) it is not going to use in a constrained environment

I don't understand.