mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Open map from timeline (#1199)
* Add navigation to expaneded map * Add MapLibreMapView.Options * Add AppActivityView * Add ShareToMapsAppActivity * Add share sheet presentation * Add localisations * Cleanup * Fix UT build errors * Revert breaking change * Fix UIView setup * Add support for location’s description * Show popover on iPad * Restore assets * More cleanup
This commit is contained in:
@@ -18,83 +18,42 @@ import Foundation
|
||||
import Mapbox
|
||||
import SwiftUI
|
||||
|
||||
/// Base class to handle a map annotation
|
||||
class LocationAnnotation: NSObject, MGLAnnotation {
|
||||
// MARK: - Properties
|
||||
|
||||
// Title property is needed to enable annotation selection and callout view showing
|
||||
var title: String?
|
||||
|
||||
final class LocationAnnotation: NSObject, MGLAnnotation {
|
||||
let coordinate: CLLocationCoordinate2D
|
||||
let anchorPoint: CGPoint
|
||||
let view: AnyView
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(coordinate: CLLocationCoordinate2D) {
|
||||
init(coordinate: CLLocationCoordinate2D,
|
||||
anchorPoint: CGPoint = .init(x: 0.5, y: 0.5),
|
||||
@ViewBuilder label: () -> some View) {
|
||||
self.coordinate = coordinate
|
||||
self.anchorPoint = anchorPoint
|
||||
view = AnyView(label())
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
|
||||
/// POI map annotation
|
||||
class PinLocationAnnotation: LocationAnnotation { }
|
||||
|
||||
class LocationAnnotationView: MGLUserLocationAnnotationView {
|
||||
private enum Constants {
|
||||
static let defaultFrame = CGRect(x: 0, y: 0, width: 46, height: 46)
|
||||
}
|
||||
|
||||
final class LocationAnnotationView: MGLUserLocationAnnotationView {
|
||||
// MARK: - Setup
|
||||
|
||||
override init(annotation: MGLAnnotation?, reuseIdentifier: String?) {
|
||||
super.init(annotation: annotation, reuseIdentifier:
|
||||
reuseIdentifier)
|
||||
frame = Constants.defaultFrame
|
||||
}
|
||||
|
||||
convenience init(userPinLocationAnnotation: MGLAnnotation) {
|
||||
self.init(annotation: userPinLocationAnnotation, reuseIdentifier: "userPinLocation")
|
||||
|
||||
addUserView()
|
||||
}
|
||||
|
||||
convenience init(pinLocationAnnotation: PinLocationAnnotation) {
|
||||
self.init(annotation: pinLocationAnnotation, reuseIdentifier: nil)
|
||||
|
||||
addPinView()
|
||||
convenience init(annotation: LocationAnnotation) {
|
||||
self.init(annotation: annotation, reuseIdentifier: "\(Self.self)")
|
||||
let view: UIView = UIHostingController(rootView: annotation.view).view
|
||||
view.backgroundColor = .clear
|
||||
view.anchorPoint = annotation.anchorPoint
|
||||
addSubview(view)
|
||||
view.bounds.size = view.intrinsicContentSize
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func addUserView() {
|
||||
guard let pinView = UIHostingController(rootView: Image(systemName: "circle.fill")
|
||||
.resizable()
|
||||
.foregroundColor(.compound.iconPrimary)).view else {
|
||||
return
|
||||
}
|
||||
|
||||
addMarkerView(pinView)
|
||||
}
|
||||
|
||||
private func addPinView() {
|
||||
guard let pinView = UIHostingController(rootView: Image(systemName: "mappin")
|
||||
.resizable()
|
||||
.foregroundColor(.compound.iconPrimary)).view else {
|
||||
return
|
||||
}
|
||||
|
||||
addMarkerView(pinView)
|
||||
}
|
||||
|
||||
private func addMarkerView(_ markerView: UIView) {
|
||||
markerView.backgroundColor = .clear
|
||||
|
||||
addSubview(markerView)
|
||||
|
||||
markerView.frame = bounds
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user