Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Upgrade MapView to allow multiple onTouchListener #509

Closed
Ph0tonic opened this issue Aug 1, 2020 · 2 comments · Fixed by #511
Closed

Upgrade MapView to allow multiple onTouchListener #509

Ph0tonic opened this issue Aug 1, 2020 · 2 comments · Fixed by #511

Comments

@Ph0tonic
Copy link
Contributor

Ph0tonic commented Aug 1, 2020

Hello,

I used the mapbox annotation plugin in one of my project and hit a limitation regarding the event manager. This plugin uses the following code on mapView to allow annotations to be draggable (as described here https://github.com/mapbox/mapbox-plugins-android/issues/884) :

mapView.setOnTouchListener { view, event -> ... }

But when a user wants to add its own detection system to add a functionality like custom drawing Mapbox example, he is stuck due to a limitation of the view which offer only one OnTouchListener. There exist a workaround consisting of adding another view on top of mapView to intercept the event but I think that there might be a better solution.

This issue could be resolved by adding a new interface to mapView which would allow to have multiple onTouchListener. I thought about something like this :

private List<OnTouchListener> onTouchListeners = new ArrayList<>();

public boolean addOnTouchListener(OnTouchListener listener) {
   return onTouchListeners.add(listener);
}

public boolean removeOnTouchListener(OnTouchListener listener) {
   return onTouchListeners.remove(listener);
}

@Override
public boolean onTouchEvent(MotionEvent event)
   if (isGestureDetectorInitialized() && mapGestureDetector.onTouchEvent(event) || super.onTouchEvent(event)) {
     return true;
   }

   for (OnTouchListener listener : onTouchListeners) {
     if (listener.onTouch(this, event) {
       return true;
     }
   }
   return false;
}

Any thoughts and ideas are most appreciated 👍 @LukasPaczos, @tobrun and @tarigo

@Ph0tonic
Copy link
Contributor Author

Any thoughts about this and it's linked PR ?
/cc @LukasPaczos, @tobrun and @tarigo

@Ph0tonic
Copy link
Contributor Author

Ph0tonic commented Sep 7, 2020

Any updates on this ?
/cc @LukasPaczos, @tobrun and @tarigo

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

Successfully merging a pull request may close this issue.

1 participant