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

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

Open
ulusoyca opened this issue Mar 18, 2019 · 9 comments · May be fixed by #1157
Open

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

ulusoyca opened this issue Mar 18, 2019 · 9 comments · May be fixed by #1157

Comments

@ulusoyca
Copy link

ulusoyca commented Mar 18, 2019

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'

@ulusoyca ulusoyca changed the title mapView.setOnToucListener#onTouch is not invoked with Annotations mapView.setOnTouchListener#onTouch is not invoked with Annotations Mar 18, 2019
@ulusoyca
Copy link
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.

@sebastienrouif
Copy link
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?

@ulusoyca
Copy link
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().

@dongzhixuanyuan
Copy link

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;
    }
}

@stale
Copy link

stale bot commented Oct 5, 2019

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.

@stale stale bot added the archived Archived by Stale bot. label Oct 5, 2019
@stale
Copy link

stale bot commented Oct 5, 2019

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

@stale stale bot closed this as completed Oct 5, 2019
@langsmith langsmith reopened this Oct 5, 2019
@stale stale bot removed the archived Archived by Stale bot. label Oct 5, 2019
@ghost
Copy link

ghost commented Dec 9, 2019

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;
    }
}

Can someone confirm this works ?
Not working for me

@houdayec
Copy link

houdayec commented Jan 9, 2020

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 ?

@Ph0tonic
Copy link
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants