Skip to content

Commit

Permalink
Expose added view annotations (#2141)
Browse files Browse the repository at this point in the history
Co-authored-by: Aleksei Sapitskii <[email protected]>
  • Loading branch information
maios and aleksproger authored May 8, 2024
1 parent 121922b commit a9fd33c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Mapbox welcomes participation and contributions from everyone.
## main

* Added camera(for:) deprecation for several methods. Added an `CameraForExample` camera(for:) usage
* Expose the list of added `ViewAnnotation`

## 11.4.0-beta.3 - 6 May, 2024

Expand Down
9 changes: 7 additions & 2 deletions Sources/MapboxMaps/Annotations/ViewAnnotationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public final class ViewAnnotationManager {
private let mapboxMap: MapboxMapProtocol
private var displayLink: Signal<Void>
// internal for tests
var objectAnnotations = [String: ViewAnnotation]()
private var objectAnnotations = [String: ViewAnnotation]()

// deprecated properties
private var viewsById: [String: UIView] = [:]
Expand All @@ -73,8 +73,13 @@ public final class ViewAnnotationManager {
}
private var _validatesViews = true

/// The list of view annotations added to the manager.
public var allAnnotations: [ViewAnnotation] {
Array(objectAnnotations.values)
}

/// The complete list of annotations associated with the receiver.
@available(*, deprecated, message: "Use ViewAnnotation")
@available(*, deprecated, renamed: "allAnnotations", message: "Please use allAnnotations instead, or directly access ViewAnnotation itself")
public var annotations: [UIView: ViewAnnotationOptions] {
idsByView.compactMapValues { [mapboxMap] id in
try? mapboxMap.options(forViewAnnotationWithId: id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ final class ViewAnnotationManagerTests: XCTestCase {

XCTAssertEqual(Set(mapboxMap.removeViewAnnotationStub.invocations.map(\.parameters)), Set(viewIds))
XCTAssertTrue(container.subviews.isEmpty)
XCTAssertTrue(manager.objectAnnotations.isEmpty)
XCTAssertTrue(manager.allAnnotations.isEmpty)
}

func testRemoveAllObjectAnnotations() {
Expand All @@ -123,16 +123,17 @@ final class ViewAnnotationManagerTests: XCTestCase {
manager.add(va1)
manager.add(va2)

XCTAssertFalse(manager.objectAnnotations.isEmpty)
XCTAssertFalse(manager.allAnnotations.isEmpty)
manager.removeAll()

XCTAssertTrue(manager.objectAnnotations.isEmpty)
XCTAssertTrue(manager.allAnnotations.isEmpty)
}

func testRemoveAllNoAnnotationViews() {
manager.removeAll()

XCTAssertTrue(mapboxMap.removeViewAnnotationStub.invocations.isEmpty)
XCTAssertTrue(manager.allAnnotations.isEmpty)
}

@available(*, deprecated)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ final class MapContentReconcilerTests: XCTestCase {
XCTAssertEqual(sourceManager.addSourceStub.invocations.map(\.parameters.source.id), ["route"])
let addedSource = try XCTUnwrap(sourceManager.addSourceStub.invocations.last?.parameters.source) as? GeoJSONSource
XCTAssertEqual(addedSource?.data, .string("foo"))
XCTAssertEqual(viewAnnotationsManager.objectAnnotations.count, 1)
verifyAnnotationOptions(viewAnnotationsManager.objectAnnotations.values.first, component.mapViewAnnotation)
XCTAssertEqual(viewAnnotationsManager.allAnnotations.count, 1)
verifyAnnotationOptions(viewAnnotationsManager.allAnnotations.first, component.mapViewAnnotation)
XCTAssertEqual(circleAnnotationManager.annotations, [
CircleAnnotation(id: "1", point: Point(LocationCoordinate2D(latitude: 10, longitude: 10))),
CircleAnnotation(id: "2", point: Point(LocationCoordinate2D(latitude: 20, longitude: 20)))
Expand All @@ -598,8 +598,8 @@ final class MapContentReconcilerTests: XCTestCase {
XCTAssertEqual(styleManager.addStyleLayerStub.invocations.last?.parameters.layerId, "condition-false")
XCTAssertEqual(styleManager.removeStyleLayerStub.invocations.count, 1)
XCTAssertEqual(styleManager.removeStyleLayerStub.invocations.last?.parameters, "condition-true")
XCTAssertEqual(viewAnnotationsManager.objectAnnotations.count, 1)
verifyAnnotationOptions(viewAnnotationsManager.objectAnnotations.values.first, component.mapViewAnnotation)
XCTAssertEqual(viewAnnotationsManager.allAnnotations.count, 1)
verifyAnnotationOptions(viewAnnotationsManager.allAnnotations.first, component.mapViewAnnotation)
XCTAssertEqual(circleAnnotationManager.annotations, [
CircleAnnotation(id: "1", point: Point(LocationCoordinate2D(latitude: 10, longitude: 10))),
CircleAnnotation(id: "2", point: Point(LocationCoordinate2D(latitude: 20, longitude: 20)))
Expand All @@ -625,8 +625,8 @@ final class MapContentReconcilerTests: XCTestCase {

XCTAssertEqual(sourceManager.addSourceStub.invocations.count, 1)
XCTAssertEqual(sourceManager.updateGeoJSONSourceStub.invocations.count, 0)
XCTAssertEqual(viewAnnotationsManager.objectAnnotations.count, 1)
verifyAnnotationOptions(viewAnnotationsManager.objectAnnotations.values.first, component.mapViewAnnotation)
XCTAssertEqual(viewAnnotationsManager.allAnnotations.count, 1)
verifyAnnotationOptions(viewAnnotationsManager.allAnnotations.first, component.mapViewAnnotation)
XCTAssertEqual(circleAnnotationManager.annotations, [
CircleAnnotation(id: "1", point: Point(LocationCoordinate2D(latitude: 10, longitude: 10))),
CircleAnnotation(id: "2", point: Point(LocationCoordinate2D(latitude: 20, longitude: 20)))
Expand Down Expand Up @@ -661,8 +661,8 @@ final class MapContentReconcilerTests: XCTestCase {
XCTAssertEqual(styleManager.addStyleLayerStub.invocations.count, 4)
XCTAssertEqual(styleManager.getStyleLayerPropertiesStub.invocations.count, 0)
XCTAssertEqual(styleManager.removeStyleLayerStub.invocations.count, 1)
XCTAssertEqual(viewAnnotationsManager.objectAnnotations.count, 1)
verifyAnnotationOptions(viewAnnotationsManager.objectAnnotations.values.first, component.mapViewAnnotation)
XCTAssertEqual(viewAnnotationsManager.allAnnotations.count, 1)
verifyAnnotationOptions(viewAnnotationsManager.allAnnotations.first, component.mapViewAnnotation)
XCTAssertEqual(circleAnnotationManager.annotations, [
CircleAnnotation(id: "1", point: Point(LocationCoordinate2D(latitude: 10, longitude: 10))),
CircleAnnotation(id: "2", point: Point(LocationCoordinate2D(latitude: 20, longitude: 20)))
Expand Down Expand Up @@ -690,7 +690,7 @@ final class MapContentReconcilerTests: XCTestCase {
XCTAssertEqual(styleManager.removeStyleLayerStub.invocations.count, 4)
XCTAssertEqual(sourceManager.removeSourceUncheckedStub.invocations.count, 1)
XCTAssertEqual(sourceManager.removeSourceUncheckedStub.invocations.last?.parameters, "route")
XCTAssertEqual(viewAnnotationsManager.objectAnnotations.count, 0)
XCTAssertEqual(viewAnnotationsManager.allAnnotations.count, 0)
XCTAssertEqual(orchestratorImpl.removeAnnotationManagerStub.invocations.map(\.parameters), [
"circle-test",
"circle-test",
Expand Down

0 comments on commit a9fd33c

Please sign in to comment.