Skip to content

mapView.setOnTouchListener#onTouch is not invoked with Annotations #884

Open

Description

@ulusoyca

I set onTouchListener for MapView and the code inside the block as below was invoked each time.

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

However, after initializing LineManager, View.OnTouchListener has no effect. What is causing it and how can I fix it?

Platform: Android
mapboxAnnotationsVersion = '0.5.0'

Activity

  1. changed the title [-]mapView.setOnToucListener#onTouch is not invoked with Annotations[/-] [+]mapView.setOnTouchListener#onTouch is not invoked with Annotations[/+] on Mar 18, 2019
  2. ulusoyca commented on Mar 19, 2019

    @ulusoyca
    Author

    As a workaround until there is a fix, this ugly trick solves the issue:

    1. Add an empty view on top of MapView
    2. Set the OnTouchListener for that view.
  3. sebastienrouif commented on Mar 21, 2019

    @sebastienrouif
    Contributor

    LineManager is an implementation of AnnotationManager which uses a DraggableAnnotationController which also sets a touchListener on the mapView.

    Unfortunately, you can only set one touchListener on the View (it's a setOnTouchListener, not an addOnTouchListener)

    The current conclusion is that you can't do both at the same time. One other workaround would be to add a callback to be called before androidGesturesManager.onTouchEvent(event); is triggered. Another one if you are using the androidGesturesManager would be to have is injected in like it's done in the second constructor currently.

    Could you explain your use case?

  4. ulusoyca commented on Mar 21, 2019

    @ulusoyca
    Author

    Thanks, in my use case I have a Mapview inside a RecyclerView. Based on the touch coordinate point, I set the flag for parent.requestDisallowInterceptTouchEvent().

  5. dongzhixuanyuan commented on Apr 8, 2019

    @dongzhixuanyuan

    Thanks, in my use case I have a Mapview inside a RecyclerView. Based on the touch coordinate point, I set the flag for parent.requestDisallowInterceptTouchEvent().

    You can use your custom Mapview. This mapview extends mapview and override onTouchEvent()
    Like below in my case:
    public static class CustomMapView extends MapView {

        public CustomMapView(@NonNull Context context) {
            super(context);
        }
    
        public CustomMapView(@NonNull Context context, @Nullable AttributeSet attrs) {
            super(context, attrs);
        }
    
        public CustomMapView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
        }
    
        public CustomMapView(@NonNull Context context, @Nullable MapboxMapOptions options) {
            super(context, options);
        }
    
        List<MapTouchListener> mapDownUpListeners = new ArrayList<>();
    
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            super.onTouchEvent(event);
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                for (MapTouchListener listener : mapDownUpListeners) {
                    listener.onTouchDown();
                }
                return true;
            } else if (event.getAction() == KeyEvent.ACTION_UP) {
                for (MapTouchListener listener : mapDownUpListeners) {
                    listener.onTouchUp();
                }
                return true;
            }
            return true;
        }
    }
    
  6. stale commented on Oct 5, 2019

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  7. added
    archived
    on Oct 5, 2019
  8. stale commented on Oct 5, 2019

    @stale

    This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

  9. removed
    archived
    on Oct 5, 2019
  10. houdayec commented on Jan 9, 2020

    @houdayec

    Getting the same problem. I have my MapView inside a RecyclerView, trying to catch onToucheEvent callback but do not get anything so far. Huge problem as my MapView is not scrollable inside my RecyclerView. Does anyone has a fix for this ?

  11. Ph0tonic commented on Dec 29, 2020

    @Ph0tonic
    Contributor

    I just pushed a PR to fix this issue, see #1157. Hope this will help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions