mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Move the interactive map into a new MapLibreShim framework
Second step towards loading MapLibre on demand: everything that touches it now lives in one framework, so that framework can later be left unlinked. The interactive map view, its annotation view and the coordinate animator move into MapLibreShim, which reaches the app through MapLibreShimProtocol. The app side keeps its MapLibreMapView call site and becomes a thin wrapper that builds a MapViewConfiguration, passing the app-only pieces (map style URLs, marker views, tint colour) across as closures so the shim needs nothing from the app. LocationAnnotation loses its MapLibre conformance and becomes a plain struct, with the shim mapping it onto its own annotation type. MapLibre's log forwarding moves into the shim as well, since TargetConfiguration can no longer reach it.
This commit is contained in:
@@ -8,57 +8,9 @@
|
||||
|
||||
import CoreLocation
|
||||
import Foundation
|
||||
import MapLibre
|
||||
import SwiftUI
|
||||
|
||||
final class LocationAnnotation: NSObject, MLNAnnotation, Identifiable {
|
||||
struct LocationAnnotation: Identifiable {
|
||||
let id: String
|
||||
// @objc dynamic is required to make animations work
|
||||
@objc dynamic var coordinate: CLLocationCoordinate2D
|
||||
var kind: LocationMarkerKind
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(id: String, coordinate: CLLocationCoordinate2D, kind: LocationMarkerKind) {
|
||||
self.id = id
|
||||
self.coordinate = coordinate
|
||||
self.kind = kind
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
|
||||
final class LocationAnnotationView: MLNUserLocationAnnotationView {
|
||||
private var hostingController: UIHostingController<AnyView>?
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
override init(annotation: MLNAnnotation?, reuseIdentifier: String?) {
|
||||
super.init(annotation: annotation, reuseIdentifier:
|
||||
reuseIdentifier)
|
||||
}
|
||||
|
||||
convenience init(annotation: LocationAnnotation, mediaProvider: MediaProviderProtocol?) {
|
||||
self.init(annotation: annotation, reuseIdentifier: "\(Self.self)")
|
||||
let markerView = LocationMarkerView(kind: annotation.kind, mediaProvider: mediaProvider)
|
||||
let hostingController = UIHostingController(rootView: AnyView(markerView))
|
||||
self.hostingController = hostingController
|
||||
let view: UIView = hostingController.view
|
||||
view.backgroundColor = .clear
|
||||
view.anchorPoint = .init(x: 0.5, y: 1.0)
|
||||
addSubview(view)
|
||||
view.bounds.size = view.intrinsicContentSize
|
||||
}
|
||||
|
||||
func updateContent(with kind: LocationMarkerKind, mediaProvider: MediaProviderProtocol?) {
|
||||
let markerView = LocationMarkerView(kind: kind, mediaProvider: mediaProvider)
|
||||
hostingController?.rootView = AnyView(markerView)
|
||||
if let hostedView = hostingController?.view {
|
||||
hostedView.bounds.size = hostedView.intrinsicContentSize
|
||||
}
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError()
|
||||
}
|
||||
let coordinate: CLLocationCoordinate2D
|
||||
let kind: LocationMarkerKind
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user