mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 17:12:45 +02:00
Configured and applied SwiftFormat
This commit is contained in:
committed by
Stefan Ceriu
parent
ff2e6ddfa7
commit
43c28d23b7
@@ -14,15 +14,14 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Combine
|
||||
import Mapbox
|
||||
import SwiftUI
|
||||
|
||||
struct LocationSharingMapView: UIViewRepresentable {
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
private struct Constants {
|
||||
private enum Constants {
|
||||
static let mapZoomLevel = 15.0
|
||||
}
|
||||
|
||||
@@ -41,10 +40,10 @@ struct LocationSharingMapView: UIViewRepresentable {
|
||||
let userAvatarData: AvatarInputProtocol?
|
||||
|
||||
/// True to indicate to show and follow current user location
|
||||
var showsUserLocation: Bool = false
|
||||
var showsUserLocation = false
|
||||
|
||||
/// True to indicate that a touch on user annotation can show a callout
|
||||
var userAnnotationCanShowCallout: Bool = false
|
||||
var userAnnotationCanShowCallout = false
|
||||
|
||||
/// Last user location if `showsUserLocation` has been enabled
|
||||
@Binding var userLocation: CLLocationCoordinate2D?
|
||||
@@ -64,8 +63,7 @@ struct LocationSharingMapView: UIViewRepresentable {
|
||||
// MARK: - UIViewRepresentable
|
||||
|
||||
func makeUIView(context: Context) -> MGLMapView {
|
||||
|
||||
let mapView = self.makeMapView()
|
||||
let mapView = makeMapView()
|
||||
mapView.delegate = context.coordinator
|
||||
let panGesture = UIPanGestureRecognizer(target: context.coordinator, action: #selector(context.coordinator.didPan))
|
||||
panGesture.delegate = context.coordinator
|
||||
@@ -74,15 +72,14 @@ struct LocationSharingMapView: UIViewRepresentable {
|
||||
}
|
||||
|
||||
func updateUIView(_ mapView: MGLMapView, context: Context) {
|
||||
|
||||
mapView.vc_removeAllAnnotations()
|
||||
mapView.addAnnotations(self.annotations)
|
||||
mapView.addAnnotations(annotations)
|
||||
|
||||
if let highlightedAnnotation = self.highlightedAnnotation {
|
||||
if let highlightedAnnotation = highlightedAnnotation {
|
||||
mapView.setCenter(highlightedAnnotation.coordinate, zoomLevel: Constants.mapZoomLevel, animated: false)
|
||||
}
|
||||
|
||||
if self.showsUserLocation {
|
||||
if showsUserLocation {
|
||||
mapView.showsUserLocation = true
|
||||
mapView.userTrackingMode = .follow
|
||||
} else {
|
||||
@@ -108,24 +105,22 @@ struct LocationSharingMapView: UIViewRepresentable {
|
||||
}
|
||||
|
||||
// MARK: - Coordinator
|
||||
|
||||
extension LocationSharingMapView {
|
||||
|
||||
class Coordinator: NSObject, MGLMapViewDelegate, UIGestureRecognizerDelegate {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
var locationSharingMapView: LocationSharingMapView
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(_ locationSharingMapView: LocationSharingMapView) {
|
||||
self.locationSharingMapView = locationSharingMapView
|
||||
}
|
||||
init(_ locationSharingMapView: LocationSharingMapView) {
|
||||
self.locationSharingMapView = locationSharingMapView
|
||||
}
|
||||
|
||||
// MARK: - MGLMapViewDelegate
|
||||
|
||||
func mapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? {
|
||||
|
||||
if let userLocationAnnotation = annotation as? UserLocationAnnotation {
|
||||
return LocationAnnotationView(userLocationAnnotation: userLocationAnnotation)
|
||||
} else if let pinLocationAnnotation = annotation as? PinLocationAnnotation {
|
||||
@@ -168,7 +163,7 @@ extension LocationSharingMapView {
|
||||
// MARK: Callout
|
||||
|
||||
func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
|
||||
return annotation is UserLocationAnnotation && locationSharingMapView.userAnnotationCanShowCallout
|
||||
annotation is UserLocationAnnotation && locationSharingMapView.userAnnotationCanShowCallout
|
||||
}
|
||||
|
||||
func mapView(_ mapView: MGLMapView, calloutViewFor annotation: MGLAnnotation) -> MGLCalloutView? {
|
||||
@@ -188,7 +183,7 @@ extension LocationSharingMapView {
|
||||
// MARK: UIGestureRecognizer
|
||||
|
||||
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
|
||||
return gestureRecognizer is UIPanGestureRecognizer
|
||||
gestureRecognizer is UIPanGestureRecognizer
|
||||
}
|
||||
|
||||
@objc
|
||||
@@ -199,12 +194,12 @@ extension LocationSharingMapView {
|
||||
}
|
||||
|
||||
// MARK: - MGLMapView convenient methods
|
||||
|
||||
extension MGLMapView {
|
||||
|
||||
func vc_removeAllAnnotations() {
|
||||
guard let annotations = self.annotations else {
|
||||
guard let annotations = annotations else {
|
||||
return
|
||||
}
|
||||
self.removeAnnotations(annotations)
|
||||
removeAnnotations(annotations)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -17,7 +17,6 @@
|
||||
import SwiftUI
|
||||
|
||||
struct LocationSharingMarkerView<Content: View>: View {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
+12
-13
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -18,7 +18,6 @@ import Foundation
|
||||
import Reusable
|
||||
|
||||
class UserAnnotationCalloutContentView: UIView, Themable, NibLoadable {
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
private static let sizingView = UserAnnotationCalloutContentView.instantiate()
|
||||
@@ -39,16 +38,16 @@ class UserAnnotationCalloutContentView: UIView, Themable, NibLoadable {
|
||||
// MARK: - Setup
|
||||
|
||||
static func instantiate() -> UserAnnotationCalloutContentView {
|
||||
return UserAnnotationCalloutContentView.loadFromNib()
|
||||
UserAnnotationCalloutContentView.loadFromNib()
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
func update(theme: Theme) {
|
||||
self.backgroundView.backgroundColor = theme.colors.background
|
||||
self.titleLabel.textColor = theme.colors.secondaryContent
|
||||
self.titleLabel.font = theme.fonts.callout
|
||||
self.shareButton.tintColor = theme.colors.secondaryContent
|
||||
backgroundView.backgroundColor = theme.colors.background
|
||||
titleLabel.textColor = theme.colors.secondaryContent
|
||||
titleLabel.font = theme.fonts.callout
|
||||
shareButton.tintColor = theme.colors.secondaryContent
|
||||
}
|
||||
|
||||
// MARK: - Life cycle
|
||||
@@ -56,18 +55,18 @@ class UserAnnotationCalloutContentView: UIView, Themable, NibLoadable {
|
||||
override func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
|
||||
self.titleLabel.text = VectorL10n.locationSharingLiveMapCalloutTitle
|
||||
self.backgroundView.layer.masksToBounds = true
|
||||
titleLabel.text = VectorL10n.locationSharingLiveMapCalloutTitle
|
||||
backgroundView.layer.masksToBounds = true
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
|
||||
self.backgroundView.layer.cornerRadius = Constants.cornerRadius
|
||||
backgroundView.layer.cornerRadius = Constants.cornerRadius
|
||||
}
|
||||
|
||||
static func contentViewSize() -> CGSize {
|
||||
let sizingView = self.sizingView
|
||||
let sizingView = sizingView
|
||||
|
||||
sizingView.frame = CGRect(x: 0, y: 0, width: 1, height: Constants.height)
|
||||
|
||||
@@ -77,8 +76,8 @@ class UserAnnotationCalloutContentView: UIView, Themable, NibLoadable {
|
||||
let fittingSize = CGSize(width: UIView.layoutFittingCompressedSize.width, height: Constants.height)
|
||||
|
||||
let size = sizingView.systemLayoutSizeFitting(fittingSize,
|
||||
withHorizontalFittingPriority: .fittingSizeLevel,
|
||||
verticalFittingPriority: .required)
|
||||
withHorizontalFittingPriority: .fittingSizeLevel,
|
||||
verticalFittingPriority: .required)
|
||||
|
||||
return size
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -17,7 +17,6 @@
|
||||
import Mapbox
|
||||
|
||||
class UserAnnotationCalloutView: UIView, MGLCalloutView, Themable {
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
private enum Constants {
|
||||
@@ -31,16 +30,16 @@ class UserAnnotationCalloutView: UIView, MGLCalloutView, Themable {
|
||||
|
||||
var representedObject: MGLAnnotation
|
||||
|
||||
lazy var leftAccessoryView: UIView = UIView()
|
||||
lazy var leftAccessoryView = UIView()
|
||||
|
||||
lazy var rightAccessoryView: UIView = UIView()
|
||||
lazy var rightAccessoryView = UIView()
|
||||
|
||||
var delegate: MGLCalloutViewDelegate?
|
||||
|
||||
// Allow the callout to remain open during panning.
|
||||
let dismissesAutomatically: Bool = false
|
||||
let dismissesAutomatically = false
|
||||
|
||||
let isAnchoredToAnnotation: Bool = true
|
||||
let isAnchoredToAnnotation = true
|
||||
|
||||
// https://github.com/mapbox/mapbox-gl-native/issues/9228
|
||||
override var center: CGPoint {
|
||||
@@ -50,33 +49,31 @@ class UserAnnotationCalloutView: UIView, MGLCalloutView, Themable {
|
||||
super.center = newCenter
|
||||
}
|
||||
get {
|
||||
return super.center
|
||||
super.center
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Private
|
||||
|
||||
lazy var contentView: UserAnnotationCalloutContentView = {
|
||||
return UserAnnotationCalloutContentView.instantiate()
|
||||
}()
|
||||
lazy var contentView = UserAnnotationCalloutContentView.instantiate()
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
required init(userLocationAnnotation: UserLocationAnnotation) {
|
||||
|
||||
self.representedObject = userLocationAnnotation
|
||||
representedObject = userLocationAnnotation
|
||||
|
||||
super.init(frame: .zero)
|
||||
|
||||
self.vc_addSubViewMatchingParent(self.contentView)
|
||||
vc_addSubViewMatchingParent(contentView)
|
||||
|
||||
self.update(theme: ThemeService.shared().theme)
|
||||
update(theme: ThemeService.shared().theme)
|
||||
|
||||
let size = UserAnnotationCalloutContentView.contentViewSize()
|
||||
|
||||
self.frame = CGRect(origin: .zero, size: size)
|
||||
frame = CGRect(origin: .zero, size: size)
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder decoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
@@ -84,16 +81,15 @@ class UserAnnotationCalloutView: UIView, MGLCalloutView, Themable {
|
||||
// MARK: - Public
|
||||
|
||||
func update(theme: Theme) {
|
||||
self.contentView.update(theme: theme)
|
||||
contentView.update(theme: theme)
|
||||
}
|
||||
|
||||
// MARK: - Overrides
|
||||
|
||||
func presentCallout(from rect: CGRect, in view: UIView, constrainedTo constrainedRect: CGRect, animated: Bool) {
|
||||
|
||||
// Set callout above the marker view
|
||||
|
||||
self.center = view.center.applying(CGAffineTransform(translationX: 0, y: view.bounds.height/2 + self.bounds.height))
|
||||
center = view.center.applying(CGAffineTransform(translationX: 0, y: view.bounds.height / 2 + bounds.height))
|
||||
|
||||
delegate?.calloutViewWillAppear?(self)
|
||||
|
||||
@@ -101,10 +97,10 @@ class UserAnnotationCalloutView: UIView, MGLCalloutView, Themable {
|
||||
|
||||
if isCalloutTappable() {
|
||||
// Handle taps and eventually try to send them to the delegate (usually the map view).
|
||||
self.contentView.shareButton.addTarget(self, action: #selector(UserAnnotationCalloutView.calloutTapped), for: .touchUpInside)
|
||||
contentView.shareButton.addTarget(self, action: #selector(UserAnnotationCalloutView.calloutTapped), for: .touchUpInside)
|
||||
} else {
|
||||
// Disable tapping and highlighting.
|
||||
self.contentView.shareButton.isUserInteractionEnabled = false
|
||||
contentView.shareButton.isUserInteractionEnabled = false
|
||||
}
|
||||
|
||||
if animated {
|
||||
@@ -124,7 +120,7 @@ class UserAnnotationCalloutView: UIView, MGLCalloutView, Themable {
|
||||
}
|
||||
|
||||
func dismissCallout(animated: Bool) {
|
||||
if (superview != nil) {
|
||||
if superview != nil {
|
||||
if animated {
|
||||
UIView.animate(withDuration: Constants.animationDuration, animations: { [weak self] in
|
||||
self?.alpha = 0
|
||||
@@ -149,7 +145,7 @@ class UserAnnotationCalloutView: UIView, MGLCalloutView, Themable {
|
||||
}
|
||||
|
||||
@objc func calloutTapped() {
|
||||
if isCalloutTappable() && delegate!.responds(to: #selector(MGLCalloutViewDelegate.calloutViewTapped)) {
|
||||
if isCalloutTappable(), delegate!.responds(to: #selector(MGLCalloutViewDelegate.calloutViewTapped)) {
|
||||
delegate!.calloutViewTapped!(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -15,11 +15,10 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import Mapbox
|
||||
import SwiftUI
|
||||
|
||||
class LocationAnnotationView: MGLUserLocationAnnotationView {
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
private enum Constants {
|
||||
@@ -34,31 +33,30 @@ class LocationAnnotationView: MGLUserLocationAnnotationView {
|
||||
|
||||
override init(annotation: MGLAnnotation?, reuseIdentifier: String?) {
|
||||
super.init(annotation: annotation, reuseIdentifier:
|
||||
reuseIdentifier)
|
||||
self.frame = Constants.defaultFrame
|
||||
reuseIdentifier)
|
||||
frame = Constants.defaultFrame
|
||||
}
|
||||
|
||||
convenience init(avatarData: AvatarInputProtocol) {
|
||||
self.init(annotation: nil, reuseIdentifier: nil)
|
||||
self.addUserMarkerView(with: avatarData)
|
||||
addUserMarkerView(with: avatarData)
|
||||
}
|
||||
|
||||
convenience init(userLocationAnnotation: UserLocationAnnotation) {
|
||||
|
||||
// TODO: Use a reuseIdentifier
|
||||
self.init(annotation: userLocationAnnotation, reuseIdentifier: nil)
|
||||
|
||||
self.addUserMarkerView(with: userLocationAnnotation.avatarData)
|
||||
addUserMarkerView(with: userLocationAnnotation.avatarData)
|
||||
}
|
||||
|
||||
convenience init(pinLocationAnnotation: PinLocationAnnotation) {
|
||||
|
||||
// TODO: Use a reuseIdentifier
|
||||
self.init(annotation: pinLocationAnnotation, reuseIdentifier: nil)
|
||||
|
||||
self.addPinMarkerView()
|
||||
addPinMarkerView()
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError()
|
||||
}
|
||||
@@ -66,7 +64,6 @@ class LocationAnnotationView: MGLUserLocationAnnotationView {
|
||||
// MARK: - Private
|
||||
|
||||
private func addUserMarkerView(with avatarData: AvatarInputProtocol) {
|
||||
|
||||
guard let avatarMarkerView = UIHostingController(rootView: LocationSharingMarkerView(backgroundColor: theme.userColor(for: avatarData.matrixItemId)) {
|
||||
AvatarImage(avatarData: avatarData, size: .medium)
|
||||
.border()
|
||||
@@ -90,11 +87,10 @@ class LocationAnnotationView: MGLUserLocationAnnotationView {
|
||||
}
|
||||
|
||||
private func addMarkerView(_ markerView: UIView) {
|
||||
|
||||
markerView.backgroundColor = .clear
|
||||
|
||||
addSubview(markerView)
|
||||
|
||||
markerView.frame = self.bounds
|
||||
markerView.frame = bounds
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user