Skip to content

Commit

Permalink
Allow displayPriority and collisionMode to pass-through to `MKAnn…
Browse files Browse the repository at this point in the history
…otationView`.
  • Loading branch information
darronschall committed May 21, 2023
1 parent 108d413 commit ee37e4f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Sources/Annotations/MKMapAnnotationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class MKMapAnnotationView<Content: View>: MKAnnotationView {
func setup(for mapAnnotation: ViewMapAnnotation<Content>) {
annotation = mapAnnotation.annotation
clusteringIdentifier = mapAnnotation.clusteringIdentifier
displayPriority = mapAnnotation.displayPriority
collisionMode = mapAnnotation.collisionMode

let controller = NativeHostingController(rootView: mapAnnotation.content)
addSubview(controller.view)
Expand Down
10 changes: 10 additions & 0 deletions Sources/Annotations/ViewMapAnnotation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public struct ViewMapAnnotation<Content: View>: MapAnnotation {

public let annotation: MKAnnotation
let clusteringIdentifier: String?
let displayPriority: MKFeatureDisplayPriority
let collisionMode: MKAnnotationView.CollisionMode
let content: Content

// MARK: Initialization
Expand All @@ -51,20 +53,28 @@ public struct ViewMapAnnotation<Content: View>: MapAnnotation {
title: String? = nil,
subtitle: String? = nil,
clusteringIdentifier: String? = nil,
displayPriority: MKFeatureDisplayPriority = .required,
collisionMode: MKAnnotationView.CollisionMode = .rectangle,
@ViewBuilder content: () -> Content
) {
self.annotation = Annotation(coordinate: coordinate, title: title, subtitle: subtitle)
self.clusteringIdentifier = clusteringIdentifier
self.displayPriority = displayPriority
self.collisionMode = collisionMode
self.content = content()
}

public init(
annotation: MKAnnotation,
clusteringIdentifier: String? = nil,
displayPriority: MKFeatureDisplayPriority = .required,
collisionMode: MKAnnotationView.CollisionMode = .rectangle,
@ViewBuilder content: () -> Content
) {
self.annotation = annotation
self.clusteringIdentifier = clusteringIdentifier
self.displayPriority = displayPriority
self.collisionMode = collisionMode
self.content = content()
}

Expand Down

0 comments on commit ee37e4f

Please sign in to comment.