Skip to content
This repository has been archived by the owner on Nov 5, 2020. It is now read-only.

How to stop showing CalloutView on annotation selection? #4

Open
hemangshah opened this issue Mar 14, 2018 · 4 comments
Open

How to stop showing CalloutView on annotation selection? #4

hemangshah opened this issue Mar 14, 2018 · 4 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@hemangshah
Copy link

hemangshah commented Mar 14, 2018

I have a scenario for which I don't want to show a CalloutView to be displayed when an annotation will get selected. Instead, I want MapViewPlus to let me know that an annotation has been tapped and I will then show a custom popup on self.view. Is it possible with MapViewPlus?

P.S. I understand that this is not the actual behavior of a MapView itself, however for someways is this will be possible it will be more easy for us to display a map with MapViewPlus while customizing the UI as per our need.

@okhanokbay
Copy link
Owner

You can do this by hacking things. I will add this to 0.2.0 milestone but currently you can achieve it like below:

1) Define an EmptyView:

class EmptyView: UIView, CalloutViewPlus {
  func configureCallout(_ viewModel: CalloutViewModel) { }
}

2) Return this EmptyView from delegate method when you don't want to show callout view:

func mapView(_ mapView: MapViewPlus, calloutViewFor annotationView: AnnotationViewPlus) -> CalloutViewPlus{

  // calloutCanBeShown is any method to decide if you want to show it or not
  guard calloutCanBeShown() else { return EmptyView() }

  return YourCalloutViewInstance

3) Hide the anchor view like in #2 when you won't show the callout view. So, both callout view and anchor view will be hidden.

@hemangshah

@okhanokbay okhanokbay reopened this Mar 14, 2018
@okhanokbay okhanokbay added this to the 0.2.0 milestone Mar 14, 2018
@okhanokbay okhanokbay self-assigned this Mar 14, 2018
@okhanokbay okhanokbay added the enhancement New feature or request label Mar 14, 2018
@hemangshah
Copy link
Author

Wow! Thanks, @okhanokbay, you're amazing. I believe this should work for me. I will wait for 0.2.0 for all the major changes requires for me. 👍

@hemangshah
Copy link
Author

@okhanokbay, here, how I will get to know that which annotation has been tapped and how to update my view with the correct data?

@okhanokbay
Copy link
Owner

okhanokbay commented Mar 16, 2018

Fair point. You will be able to do this in 0.2.0. As in the MKMapView, allowing a user to opt-out of showing a callout view for a specific annotation must be included in MapViewPlus. As of MapViewPlus adding a 'plus' by passing the view model to the callout view that conforms to CalloutViewPlus protocol, it also must provide a way to pass this view model to the user's custom view class that doesn't conform to this protocol.

TL;DR -> Please wait for 0.2.0 :) @hemangshah

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

No branches or pull requests

2 participants