Skip to content

LocationMessageDisplayDelegate to add custom annotations#150

Merged
SD10 merged 4 commits into
MessageKit:v0.9.0from
etoledom:feature/locationMessageAnnotation
Sep 25, 2017
Merged

LocationMessageDisplayDelegate to add custom annotations#150
SD10 merged 4 commits into
MessageKit:v0.9.0from
etoledom:feature/locationMessageAnnotation

Conversation

@etoledom

Copy link
Copy Markdown
Contributor

Added LocationMessageDisplayDelegate to add custom annotations to locationMessages
Modified example proyect implementing LocationMessageDisplayDelegate with a custom annotation

…ationMessages

Modified example proyect implementing LocationMessageDisplayDelegate with a custom annotation
Comment thread Sources/MessagesCollectionView.swift Outdated

open weak var messageCellDelegate: MessageCellDelegate?

open weak var locationMessagesDisplayDelegate: LocationMessageDisplayDelegate?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this property because we can assign it to messagesDisplayDelegate since LocationMessageDisplayDelegate conforms to MessagesDisplayDelegate

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! Thanks!


guard let snapshot = snapshot, error == nil else {
//show an error image?
return

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to call stopAnimating() here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use defer {} to never forget again 😬

…ectionView

Added defer {} to always exit `setMapSnaphotImage` stopping activity indicator
point.x += annotationView.centerOffset.x
point.y += annotationView.centerOffset.y

annotationView.image?.draw(at: point)

@SD10 SD10 Sep 23, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only question is what if the user is not using an image for the MKAnnotationView? It seems like we're not using MKAnnotationView at all really. It's just wrapping up our UIImage. Am I making sense?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MKAnnotationView is not only wrapping the image but also the anchor information necessary for drawing annotationView.centerOffset, so we shouldn't just ask for an image in the delegate.

But is true that this API how it is now, allows the mistake of not adding an image, so maybe we could use a simpler wrapping Struct with image and centerOffset making the image required.

I also thought some users might not want so show an annotation at all, so we could make the delegate return optional adding the possibility of a map without annotation.

@SD10 SD10 Sep 23, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etoledom Isn't there some way to add the MKAnnotationView as a whole?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I'm trying to say is what if I want to style my MKAnnotationView using the properties of UIView and not just a UIImage

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SD10 I see what you mean.

We can actually draw the annotationView's layer with:
annotationView.layer.render(in: context)
I tested it and seems to work fine.

For some reason, every tutorial and example I have found uses the image drawing thing, but the Apple documentation on MKAnnotationView says that is allowed also to draw the pin overriding draw(_:), so in that case probably will be the best, as you said, to draw the whole view instead of just the image for maximum flexibility.

I will test it a bit more, and PR with this little drawing change.

@etoledom etoledom Sep 23, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works with MKAnnotationView, MKMarkerAnnotationView, custom subclasses of MKAnnotationView, but it doesn't want to work with MKPinAnnotationView (our default) 😅

@SD10 SD10 changed the title LocationMessageDisplayDelegate to add custom annotations [WIP] LocationMessageDisplayDelegate to add custom annotations Sep 23, 2017
Documentation on LocationMessageDisplayDelegate
@SD10 SD10 changed the base branch from master to v0.9.0 September 24, 2017 07:48
Comment thread Sources/LocationMessageCell.swift Outdated
self.activityIndicator.stopAnimating()
}
guard let snapshot = snapshot, error == nil else {
print("\(#function) Error creating map snapshot: \(String(describing: error))") //show an error image?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to print anything in production. Let's just return here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!, I'll fix it now

@SD10 SD10 changed the title [WIP] LocationMessageDisplayDelegate to add custom annotations LocationMessageDisplayDelegate to add custom annotations Sep 25, 2017
@SD10

SD10 commented Sep 25, 2017

Copy link
Copy Markdown
Member

@etoledom Thanks for your great work on this 💯 👍 I've invited you to the MessageKit organization, it would be great to have your involvement in our project 😃 No worries if you're not feeling up to it!

@SD10 SD10 merged commit a388785 into MessageKit:v0.9.0 Sep 25, 2017
@SD10 SD10 mentioned this pull request Sep 25, 2017
24 tasks
SD10 added a commit that referenced this pull request Sep 25, 2017
@etoledom etoledom deleted the feature/locationMessageAnnotation branch September 27, 2017 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants